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-0.11.0 lib/billimatic/response.rb
billimatic-client-0.10.2 lib/billimatic/response.rb
billimatic-client-0.10.1 lib/billimatic/response.rb
billimatic-client-0.10.0 lib/billimatic/response.rb
billimatic-client-0.9.0 lib/billimatic/response.rb
billimatic-client-0.8.0 lib/billimatic/response.rb
billimatic-client-0.7.0 lib/billimatic/response.rb
billimatic-client-0.6.0 lib/billimatic/response.rb
billimatic-client-0.5.1 lib/billimatic/response.rb
billimatic-client-0.5.0 lib/billimatic/response.rb
billimatic-client-0.4.0 lib/billimatic/response.rb
billimatic-client-0.3.0 lib/billimatic/response.rb
billimatic-client-0.2.1 lib/billimatic/response.rb
billimatic-client-0.1.2 lib/billimatic/response.rb
billimatic-client-0.1.1 lib/billimatic/response.rb
billimatic-client-0.1.0 lib/billimatic/response.rb