Class: Datadog::Core::Remote::Transport::HTTP::API::Instance

Inherits:
Object
  • Object
show all
Includes:
Config::API::Instance, Negotiation::API::Instance
Defined in:
lib/datadog/core/remote/transport/http/api/instance.rb

Overview

An API configured with adapter and routes

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config::API::Instance

#send_config

Methods included from Negotiation::API::Instance

#send_info

Constructor Details

#initialize(spec, adapter, options = {}) ⇒ Instance

Returns a new instance of Instance.



16
17
18
19
20
# File 'lib/datadog/core/remote/transport/http/api/instance.rb', line 16

def initialize(spec, adapter, options = {})
  @spec = spec
  @adapter = adapter
  @headers = options.fetch(:headers, {})
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



11
12
13
# File 'lib/datadog/core/remote/transport/http/api/instance.rb', line 11

def adapter
  @adapter
end

#headersObject (readonly)

Returns the value of attribute headers.



11
12
13
# File 'lib/datadog/core/remote/transport/http/api/instance.rb', line 11

def headers
  @headers
end

#specObject (readonly)

Returns the value of attribute spec.



11
12
13
# File 'lib/datadog/core/remote/transport/http/api/instance.rb', line 11

def spec
  @spec
end

Instance Method Details

#call(env) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/datadog/core/remote/transport/http/api/instance.rb', line 26

def call(env)
  # Add headers to request env, unless empty.
  env.headers.merge!(headers) unless headers.empty?

  # Send request env to the adapter.
  adapter.call(env)
end

#encoderObject



22
23
24
# File 'lib/datadog/core/remote/transport/http/api/instance.rb', line 22

def encoder
  spec.encoder
end