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

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/transport/http/api/instance.rb

Overview

An API configured with adapter and routes

Defined Under Namespace

Classes: EndpointNotSupportedError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Instance.

[View source]

32
33
34
35
36
# File 'lib/datadog/core/transport/http/api/instance.rb', line 32

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.


27
28
29
# File 'lib/datadog/core/transport/http/api/instance.rb', line 27

def adapter
  @adapter
end

#headersObject (readonly)

Returns the value of attribute headers.


27
28
29
# File 'lib/datadog/core/transport/http/api/instance.rb', line 27

def headers
  @headers
end

#specObject (readonly)

Returns the value of attribute spec.


27
28
29
# File 'lib/datadog/core/transport/http/api/instance.rb', line 27

def spec
  @spec
end

Instance Method Details

#call(env) ⇒ Object

[View source]

42
43
44
45
46
47
48
# File 'lib/datadog/core/transport/http/api/instance.rb', line 42

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

[View source]

38
39
40
# File 'lib/datadog/core/transport/http/api/instance.rb', line 38

def encoder
  spec.encoder
end