Sha256: eaf0bc17b68db2c3ed129a93d400cc82c3238546e0e23d64dc29f0daab019c23

Contents?: true

Size: 635 Bytes

Versions: 5

Compression:

Stored size: 635 Bytes

Contents

# frozen_string_literal: true

require 'forwardable'

module CapitalOnTap
  class Response
    extend Forwardable

    def_delegators :@http_response, :body, :status, :success?, :headers

    def initialize(http_response)
      @http_response = http_response
    end

    def error
      @http_response.body&.dig(:errorMessage) || @http_response.body&.dig(:error)
    end

    def metadata
      @http_response.body&.dig(:metaData)
    end

    def invalid_token?
      auth_failure = @http_response.headers&.dig('www-authenticate')

      return false unless auth_failure

      auth_failure.match?('invalid_token')
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
capital_on_tap-1.0.1 lib/capital_on_tap/response.rb
capital_on_tap-1.0.0 lib/capital_on_tap/response.rb
capital_on_tap-0.2.1 lib/capital_on_tap/response.rb
capital_on_tap-0.2.0 lib/capital_on_tap/response.rb
capital_on_tap-0.1.8 lib/capital_on_tap/response.rb