Sha256: 4aaf6188fc7960ab3a0b3e01f1d193ef9e67d05321c6f66190fc2d103b613f55

Contents?: true

Size: 616 Bytes

Versions: 11

Compression:

Stored size: 616 Bytes

Contents

class ShippingEasy::Http::ResponseHandler

  extend Forwardable

  def_delegators :response, :status, :body

  attr_reader :response

  def initialize(response)
    @response = response
  end

  def self.run(response)
    new(response).run
  end

  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

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
shipping_easy-0.7.1 lib/shipping_easy/http/response_handler.rb
shipping_easy-0.7.0 lib/shipping_easy/http/response_handler.rb
shipping_easy-0.6.1 lib/shipping_easy/http/response_handler.rb
shipping_easy-0.6.0 lib/shipping_easy/http/response_handler.rb
shipping_easy-0.5.1 lib/shipping_easy/http/response_handler.rb
shipping_easy-0.5.0 lib/shipping_easy/http/response_handler.rb
shipping_easy-0.3.2 lib/shipping_easy/http/response_handler.rb
shipping_easy-0.3.1 lib/shipping_easy/http/response_handler.rb
shipping_easy-0.3.0 lib/shipping_easy/http/response_handler.rb
shipping_easy-0.2.2 lib/shipping_easy/http/response_handler.rb
shipping_easy-0.2.1 lib/shipping_easy/http/response_handler.rb