Class: X::ResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/x/response_parser.rb

Constant Summary collapse

ERROR_MAP =
{
  400 => BadRequest,
  401 => Unauthorized,
  403 => Forbidden,
  404 => NotFound,
  406 => NotAcceptable,
  409 => ConnectionException,
  410 => Gone,
  413 => PayloadTooLarge,
  422 => UnprocessableEntity,
  429 => TooManyRequests,
  500 => InternalServerError,
  502 => BadGateway,
  503 => ServiceUnavailable,
  504 => GatewayTimeout
}.freeze
JSON_CONTENT_TYPE_REGEXP =
%r{application/json}

Instance Method Summary collapse

Instance Method Details

#parse(response:, array_class: nil, object_class: nil) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/x/response_parser.rb', line 39

def parse(response:, array_class: nil, object_class: nil)
  raise error(response) unless response.is_a?(Net::HTTPSuccess)

  return unless json?(response)

  JSON.parse(response.body, array_class: array_class, object_class: object_class)
end