class Instana::Backend::RequestClient
Convince wrapper around {Net::HTTP}. @since 1.197.0
Attributes
host[R]
port[R]
Public Class Methods
new(host, port, use_ssl: false)
click to toggle source
# File lib/instana/backend/request_client.rb, line 35 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
Public Instance Methods
send_request(method, path, data = nil, headers = {})
click to toggle source
Send a request to the backend. If data is a {Hash}, encode the object as JSON and set the proper headers.
@param [String] method request method @param [String] path request path @param [Hash, String] data request body @param [Hash] headers extra request headers to send
# File lib/instana/backend/request_client.rb, line 49 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
Private Instance Methods
encode_body(data)
click to toggle source
# File lib/instana/backend/request_client.rb, line 67 def encode_body(data) # :nocov: defined?(Oj) ? Oj.dump(data, mode: :strict) : JSON.dump(data) # :nocov: end