Class: Fulfil::ResponseHandler

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

Overview

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

Examples:

Fulfil::ResponseHandler.new(@response).verify!
=> true

Fulfil::ResponseHandler.new(@response).verify!
=> Fulfil::Error::BadRequest

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.



28
29
30
31
# File 'lib/fulfil/response_handler.rb', line 28

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

Instance Method Details

#verify!Object



33
34
35
36
# File 'lib/fulfil/response_handler.rb', line 33

def verify!
  verify_rate_limits!
  verify_http_status_code!
end