Sha256: 9931055bfa983dd4e0fe111bf6d964374c28427d368bdac55ce9d2e0ab0e8671

Contents?: true

Size: 602 Bytes

Versions: 47

Compression:

Stored size: 602 Bytes

Contents

require "cobrato/exception"

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

  class Response < SimpleDelegator
    def resolve!(&block)
      if success? #TODO: test redirect if need
        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:    (MultiJson.load(body) rescue {})
      )
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
cobrato-client-1.1.7 lib/cobrato/response.rb
cobrato-client-1.1.6 lib/cobrato/response.rb
cobrato-client-1.1.5 lib/cobrato/response.rb
cobrato-client-1.1.4 lib/cobrato/response.rb
cobrato-client-1.1.3 lib/cobrato/response.rb
cobrato-client-1.1.2 lib/cobrato/response.rb
cobrato-client-1.1.1 lib/cobrato/response.rb
cobrato-client-1.1.0 lib/cobrato/response.rb
cobrato-client-1.0.1 lib/cobrato/response.rb
cobrato-client-1.0.0 lib/cobrato/response.rb
cobrato-client-0.27.0 lib/cobrato/response.rb
cobrato-client-0.26.0 lib/cobrato/response.rb
cobrato-client-0.25.0 lib/cobrato/response.rb
cobrato-client-0.24.1 lib/cobrato/response.rb
cobrato-client-0.24.0 lib/cobrato/response.rb
cobrato-client-0.23.0 lib/cobrato/response.rb
cobrato-client-0.23.0.beta12 lib/cobrato/response.rb
cobrato-client-0.23.0.beta11 lib/cobrato/response.rb
cobrato-client-0.23.0.beta10 lib/cobrato/response.rb
cobrato-client-0.23.0.beta9 lib/cobrato/response.rb