Sha256: c756488649282b2d3cd87fa7eb6e45e1046c8f84df61654e5d906568ad2e228f

Contents?: true

Size: 551 Bytes

Versions: 5

Compression:

Stored size: 551 Bytes

Contents

require "ecommerce/exception"

module Ecommerce
  RequestTimeout = Class.new(Exception)
  RequestError   = Class.new(Exception)

  class Response < SimpleDelegator

    def resolve!(&block)
      if success?
        block_given? ? yield(self) : self
      elsif timed_out?
        timeout!
      else
        error!
      end
    end

    private

    def timeout!
      raise RequestTimeout
    end

    def error!
      raise RequestError.new(
        code:    code,
        message: status_message,
        body:    body
      )
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ecommerce-client-0.0.5 lib/ecommerce/response.rb
ecommerce-client-0.0.4 lib/ecommerce/response.rb
ecommerce-client-0.0.3 lib/ecommerce/response.rb
ecommerce-client-0.0.2 lib/ecommerce/response.rb
ecommerce-client-0.0.1 lib/ecommerce/response.rb