Sha256: 407ef7053cea757b899fc2f2043f5b1403dd4a5a067b02bc02750312bb00b1c1

Contents?: true

Size: 553 Bytes

Versions: 1

Compression:

Stored size: 553 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 401 then raise ShippingEasy::AccessDeniedError, response.body
      when 404 then raise ShippingEasy::ResourceNotFoundError, response.body
      when 200, 201 then JSON.parse(response.body)
      else
        raise ShippingEasy::Error, response.body
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shipping_easy-0.2.0 lib/shipping_easy/http/response_handler.rb