Class: X::ResponseParser
- Inherits:
-
Object
- Object
- X::ResponseParser
- 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
Instance Method Summary collapse
Instance Method Details
#parse(response:, array_class: nil, object_class: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/x/response_parser.rb', line 38 def parse(response:, array_class: nil, object_class: nil) raise error(response) unless response.is_a?(Net::HTTPSuccess) return if response.instance_of?(Net::HTTPNoContent) begin JSON.parse(response.body, array_class:, object_class:) rescue JSON::ParserError nil end end |