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.



5
6
7
8
9
# File 'lib/affirm/client.rb', line 5

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



15
16
17
# File 'lib/affirm/client.rb', line 15

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

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



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

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



11
12
13
# File 'lib/affirm/client.rb', line 11

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