class EurekaRuby::HttpClient
Attributes
base[R]
httprb[R]
ssl_context[R]
Public Class Methods
new(base, timeout, skip_verify_ssl)
click to toggle source
# File lib/eureka_ruby/http_client.rb, line 9 def initialize(base, timeout, skip_verify_ssl) @base = base @httprb = HTTP.timeout(write: timeout, connect: timeout, read: timeout) @ssl_context = OpenSSL::SSL::SSLContext.new @ssl_context.ssl_version = :TLSv1 @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE if skip_verify_ssl end
Public Instance Methods
delete(path)
click to toggle source
# File lib/eureka_ruby/http_client.rb, line 29 def delete(path) request(path) { |url| httprb.delete(url, ssl_context: ssl_context) } end
get(path)
click to toggle source
# File lib/eureka_ruby/http_client.rb, line 17 def get(path) request(path) { |url| httprb.get(url, ssl_context: ssl_context) } end
post(path, payload = {})
click to toggle source
# File lib/eureka_ruby/http_client.rb, line 21 def post(path, payload = {}) request(path) { |url| httprb.post(url, json: payload, ssl_context: ssl_context) } end
put(path, payload = {})
click to toggle source
# File lib/eureka_ruby/http_client.rb, line 25 def put(path, payload = {}) request(path) { |url| httprb.put(url, json: payload, ssl_context: ssl_context) } end
Private Instance Methods
request(path) { |"#{base}#{path}"| ... }
click to toggle source
# File lib/eureka_ruby/http_client.rb, line 35 def request(path) response = yield("#{base}#{path}") unless [200, 204].include? response.status puts <<-ERROR EurekaRequestError: request: #{path} response: status: #{response.status} body: #{response.body} ERROR end response end