Sha256: 65b51ebb9010c8595de6816386367bda4374c2887250bbda855623eb0902c4bd

Contents?: true

Size: 620 Bytes

Versions: 36

Compression:

Stored size: 620 Bytes

Contents

require "billimatic/exception"

module Billimatic
  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

36 entries across 36 versions & 1 rubygems

Version Path
billimatic-client-1.0.1 lib/billimatic/response.rb
billimatic-client-1.0.0 lib/billimatic/response.rb
billimatic-client-0.22.1 lib/billimatic/response.rb
billimatic-client-0.22.0 lib/billimatic/response.rb
billimatic-client-0.21.0 lib/billimatic/response.rb
billimatic-client-0.20.0 lib/billimatic/response.rb
billimatic-client-0.19.1 lib/billimatic/response.rb
billimatic-client-0.19.0 lib/billimatic/response.rb
billimatic-client-0.18.1 lib/billimatic/response.rb
billimatic-client-0.18.0 lib/billimatic/response.rb
billimatic-client-0.17.0 lib/billimatic/response.rb
billimatic-client-0.16.0 lib/billimatic/response.rb
billimatic-client-0.15.0 lib/billimatic/response.rb
billimatic-client-0.14.1 lib/billimatic/response.rb
billimatic-client-0.14.0 lib/billimatic/response.rb
billimatic-client-0.13.0 lib/billimatic/response.rb
billimatic-client-0.12.0 lib/billimatic/response.rb
billimatic-client-0.11.3 lib/billimatic/response.rb
billimatic-client-0.11.2 lib/billimatic/response.rb
billimatic-client-0.11.1 lib/billimatic/response.rb