class ShippingEasy::Http::ResponseHandler

Attributes

response[R]

Public Class Methods

new(response) click to toggle source
# File lib/shipping_easy/http/response_handler.rb, line 9
def initialize(response)
  @response = response
end
run(response) click to toggle source
# File lib/shipping_easy/http/response_handler.rb, line 13
def self.run(response)
  new(response).run
end

Public Instance Methods

run() click to toggle source
# File lib/shipping_easy/http/response_handler.rb, line 17
def run
  case status
  when 200, 201 then JSON.parse(response.body)
  when 400 then raise ShippingEasy::InvalidRequestError, response.body
  when 401 then raise ShippingEasy::AccessDeniedError, response.body
  when 404 then raise ShippingEasy::ResourceNotFoundError, response.body
  else
    raise ShippingEasy::Error, response.body
  end
end