Class: Datadog::OpenFeature::Transport::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/open_feature/transport.rb

Defined Under Namespace

Classes: Spec

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apis, default_api, logger:) ⇒ HTTP

Returns a new instance of HTTP.



41
42
43
44
# File 'lib/datadog/open_feature/transport.rb', line 41

def initialize(apis, default_api, logger:)
  @api = apis[default_api]
  @logger = logger
end

Class Method Details

.build(agent_settings:, logger:) ⇒ Object



34
35
36
37
38
39
# File 'lib/datadog/open_feature/transport.rb', line 34

def self.build(agent_settings:, logger:)
  Core::Transport::HTTP.build(
    agent_settings: agent_settings,
    logger: logger
  ) { |t| t.api('exposures', HTTP::Spec.new) }.to_transport(self)
end

Instance Method Details

#send_exposures(payload) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/datadog/open_feature/transport.rb', line 46

def send_exposures(payload)
  encoder = Core::Encoding::JSONEncoder
  parcel = Core::Transport::Parcel.new(
    encoder.encode(payload),
    content_type: encoder.content_type
  )
  request = Core::Transport::Request.new(parcel)

  @api.endpoint.call(Core::Transport::HTTP::Env.new(request)) do |env|
    @api.call(env)
  end
rescue => e
  message = "Internal error during request. Cause: #{e.class.name} #{e.message} " \
            "Location: #{Array(e.backtrace).first}"
  @logger.debug(message)

  Core::Transport::InternalErrorResponse.new(e)
end