Sha256: b6412a57f097e559a395565dce06dbb18f331cc77188f5b57e37423ac63d103b

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

require 'dry/configurable'

module Payable
  extend Dry::Configurable

  setting :api_url, 'https://api.payable.com/v1/'
  setting :logger
  setting :page_size, 50

  setting :company_id
  setting :api_key

  def self.api_url
    Addressable::URI.parse config.api_url
  end

  def self.client
    @client ||= Client.new
  end

  def self.client=(instance)
    @client = instance
  end

  Error                  = Class.new(StandardError)
  MissingRequiredSetting = Class.new(Error)

  class InvalidRequest < Error
    attr_reader :response

    def initialize(response = {})
      @response = response
      super
    end

    def response?
      return false if response.nil?
      return false if response.respond_to?(:empty?) && response.empty?
      !!response
    end

    def status
      return nil unless response
      response[:status]
    end

    def headers
      return nil unless response
      response[:headers]
    end

    def body
      return nil unless response
      respose[:body]
    end
  end
end

require 'payable/types'
require 'payable/client'
require 'payable/resource'
require 'payable/resource_list'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
payable-api-0.1.2 lib/payable.rb
payable-api-0.1.1 lib/payable.rb
payable-api-0.1.0 lib/payable.rb