Class: Fulfil::ResponseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/fulfil/response_handler.rb

Overview

The ‘Fulfil::ResponseHandler` parses the HTTP response from Fulfil. If it encounters an HTTP status code that indicates an error, it raises an internal exception that the consumer can catch.

Constant Summary collapse

HTTP_ERROR_CODES =
{
  400 => Fulfil::HttpError::BadRequest,
  401 => Fulfil::HttpError::AuthorizationRequired,
  402 => Fulfil::HttpError::PaymentRequired,
  403 => Fulfil::HttpError::Forbidden,
  404 => Fulfil::HttpError::NotFound,
  405 => Fulfil::HttpError::MethodNotAllowed,
  406 => Fulfil::HttpError::NotAccepted,
  422 => Fulfil::HttpError::UnprocessableEntity,
  429 => Fulfil::HttpError::TooManyRequests,
  500 => Fulfil::HttpError::InternalServerError
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ResponseHandler

Returns a new instance of ResponseHandler.



21
22
23
24
# File 'lib/fulfil/response_handler.rb', line 21

def initialize(response)
  @response = response
  @status_code = response.code
end

Instance Method Details

#verify!Object



26
27
28
29
# File 'lib/fulfil/response_handler.rb', line 26

def verify!
  verify_rate_limits!
  verify_http_status_code!
end