Class: Datadog::CI::Transport::RemoteSettingsApi::Response

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

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



16
17
18
19
# File 'lib/datadog/ci/transport/remote_settings_api.rb', line 16

def initialize(http_response)
  @http_response = http_response
  @json = nil
end

Instance Method Details

#ok?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/datadog/ci/transport/remote_settings_api.rb', line 21

def ok?
  resp = @http_response
  !resp.nil? && resp.ok?
end

#payloadObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/datadog/ci/transport/remote_settings_api.rb', line 26

def payload
  cached = @json
  return cached unless cached.nil?

  resp = @http_response
  return @json = default_payload if resp.nil? || !resp.ok?

  begin
    @json = JSON.parse(resp.payload).dig(*Ext::Transport::DD_API_SETTINGS_RESPONSE_DIG_KEYS) ||
      default_payload
  rescue JSON::ParserError => e
    Datadog.logger.error("Failed to parse settings response payload: #{e}. Payload was: #{resp.payload}")
    @json = default_payload
  end
end