Class: Affirm::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/affirm/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(public_key:, secret_key:, api_url: Affirm::API.api_url) ⇒ Client

Returns a new instance of Client.



3
4
5
6
7
# File 'lib/affirm/client.rb', line 3

def initialize(public_key:, secret_key:, api_url: Affirm::API.api_url)
  @public_key = public_key
  @secret_key = secret_key
  @api_url = api_url
end

Instance Method Details

#get(path, data = {}) ⇒ Object



13
14
15
# File 'lib/affirm/client.rb', line 13

def get(path, data={})
  make_request(path, :get, data)
end

#make_request(path, method, data = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/affirm/client.rb', line 17

def make_request(path, method, data={})
  response = Typhoeus::Request.new(
    url(path),
    method: method,
    body: data.to_json,
    headers: affirm_headers(data),
    userpwd: user_password
  ).run

  affirm_response = parse_response(response)

  handle_errors(affirm_response)
end

#post(path, data = {}) ⇒ Object



9
10
11
# File 'lib/affirm/client.rb', line 9

def post(path, data={})
  make_request(path, :post, data)
end