Class: EurekaRuby::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/eureka_ruby/http_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, timeout, skip_verify_ssl) ⇒ HttpClient

Returns a new instance of HttpClient.



9
10
11
12
13
14
15
# 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

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



7
8
9
# File 'lib/eureka_ruby/http_client.rb', line 7

def base
  @base
end

#httprbObject (readonly)

Returns the value of attribute httprb.



7
8
9
# File 'lib/eureka_ruby/http_client.rb', line 7

def httprb
  @httprb
end

#ssl_contextObject (readonly)

Returns the value of attribute ssl_context.



7
8
9
# File 'lib/eureka_ruby/http_client.rb', line 7

def ssl_context
  @ssl_context
end

Instance Method Details

#delete(path) ⇒ Object



29
30
31
# 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) ⇒ Object



17
18
19
# 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 = {}) ⇒ Object



21
22
23
# 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 = {}) ⇒ Object



25
26
27
# 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