Sha256: aae4574d02bfff986c00b56fe615228c6dfef3398f70ccf8f8bab11f094585ae

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

module Affirm
  class Client
    attr_reader :connection

    attr_reader :url_prefix
    private :url_prefix

    class << self
      def request(method, path, **data)
        new.public_send(method, path, data)
      end
    end

    def initialize
      @url_prefix = "/api/v2"
      @connection = Faraday.new(Affirm.configuration.endpoint) do |conn|
        conn.basic_auth(basic_auth_user, basic_auth_password)
        conn.request  :json
        conn.response :json, content_type: /\bjson$/
        conn.adapter  Faraday.default_adapter
      end
    end

    def get(path, **data)
      connection.get(normalized_path(path), data)
    end

    def post(path, **data)
      connection.post(normalized_path(path), data)
    end

    private

    def basic_auth_user
      Affirm.configuration.public_api_key
    end

    def basic_auth_password
      Affirm.configuration.private_api_key
    end

    def normalized_path(path)
      url_prefix + normalize_path(path)
    end

    def normalize_path(path)
      Faraday::Utils.normalize_path(path)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
affirm-ruby-1.1.2 lib/affirm/client.rb
affirm-ruby-1.1.1 lib/affirm/client.rb
affirm-ruby-1.1.0 lib/affirm/client.rb
affirm-ruby-1.0.2 lib/affirm/client.rb
affirm-ruby-1.0.1 lib/affirm/client.rb
affirm-ruby-1.0.0 lib/affirm/client.rb
affirm-ruby-0.0.1 lib/affirm/client.rb