Class: Datadog::CI::Transport::RemoteSettingsApi::Response
- Inherits:
-
Object
- Object
- Datadog::CI::Transport::RemoteSettingsApi::Response
- Defined in:
- lib/datadog/ci/transport/remote_settings_api.rb
Instance Method Summary collapse
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
- #payload ⇒ Object
- #require_git? ⇒ Boolean
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
20 21 22 23 |
# File 'lib/datadog/ci/transport/remote_settings_api.rb', line 20 def initialize(http_response) @http_response = http_response @json = nil end |
Instance Method Details
#ok? ⇒ Boolean
25 26 27 28 |
# File 'lib/datadog/ci/transport/remote_settings_api.rb', line 25 def ok? resp = @http_response !resp.nil? && resp.ok? end |
#payload ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/datadog/ci/transport/remote_settings_api.rb', line 30 def payload cached = @json return cached unless cached.nil? resp = @http_response return @json = default_payload if resp.nil? || !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}") Transport::Telemetry.api_requests_errors( Ext::Telemetry::METRIC_GIT_REQUESTS_SETTINGS_ERRORS, 1, error_type: "invalid_json", status_code: nil ) @json = default_payload end end |
#require_git? ⇒ Boolean
54 55 56 |
# File 'lib/datadog/ci/transport/remote_settings_api.rb', line 54 def require_git? Utils::Parsing.convert_to_bool(payload[Ext::Transport::DD_API_SETTINGS_RESPONSE_REQUIRE_GIT_KEY]) end |