Class: Instana::Backend::RequestClient
- Inherits:
-
Object
- Object
- Instana::Backend::RequestClient
- Defined in:
- lib/instana/backend/request_client.rb
Overview
Convince wrapper around Net::HTTP.
Defined Under Namespace
Classes: Response
Instance Attribute Summary collapse
- #host ⇒ Object readonly
- #port ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(host, port, use_ssl: false) ⇒ RequestClient
constructor
A new instance of RequestClient.
-
#send_request(method, path, data = nil, headers = {}) ⇒ Object
Send a request to the backend.
Constructor Details
#initialize(host, port, use_ssl: false) ⇒ RequestClient
Returns a new instance of RequestClient.
37 38 39 40 41 42 |
# File 'lib/instana/backend/request_client.rb', line 37 def initialize(host, port, use_ssl: false) timeout = Integer(ENV.fetch('INSTANA_TIMEOUT', 500)) @host = host @port = port @client = Net::HTTP.start(host, port, use_ssl: use_ssl, read_timeout: timeout) end |
Instance Attribute Details
#host ⇒ Object (readonly)
23 24 25 |
# File 'lib/instana/backend/request_client.rb', line 23 def host @host end |
#port ⇒ Object (readonly)
23 24 25 |
# File 'lib/instana/backend/request_client.rb', line 23 def port @port end |
Instance Method Details
#send_request(method, path, data = nil, headers = {}) ⇒ Object
Send a request to the backend. If data is a Hash, encode the object as JSON and set the proper headers.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/instana/backend/request_client.rb', line 51 def send_request(method, path, data = nil, headers = {}) body = if data.is_a?(Hash) || data.is_a?(Array) headers['Content-Type'] = 'application/json' headers['Accept'] = 'application/json' encode_body(data) else headers['Content-Type'] = 'application/octet-stream' data end response = @client.send_request(method, path, body, headers) Response.new(response) end |