Class: Roistat::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/roistat/response.rb

Constant Summary collapse

ERROR_MAP =
{
  "authentication_failed" => Roistat::AuthenticationError,
  "authorization_failed" => Roistat::AuthorizationError,
  "access_denied" => Roistat::AccessDeniedError,
  "request_limit_error" => Roistat::RateLimitError
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response, parse:, binary_tempfile_threshold:) ⇒ Response

Returns a new instance of Response.



18
19
20
21
22
# File 'lib/roistat/response.rb', line 18

def initialize(http_response, parse:, binary_tempfile_threshold:)
  @http_response = http_response
  @parse = parse
  @binary_tempfile_threshold = binary_tempfile_threshold
end

Class Method Details

.parse(http_response, parse:, binary_tempfile_threshold:) ⇒ Object



14
15
16
# File 'lib/roistat/response.rb', line 14

def self.parse(http_response, parse:, binary_tempfile_threshold:)
  new(http_response, parse: parse, binary_tempfile_threshold: binary_tempfile_threshold).parse
end

Instance Method Details

#parseObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/roistat/response.rb', line 24

def parse
  raise_transport_error! if transport_failure?

  body = @http_response.body.to_s
  return parse_binary(body) if @parse == :binary

  parsed = parse_json(body)
  raise_api_error!(parsed) if api_error?(parsed)
  parsed
end