Class: JeraPayment::Api::Iugu::Base
- Inherits:
-
Object
- Object
- JeraPayment::Api::Iugu::Base
show all
- Defined in:
- lib/jera_payment/api/iugu/base.rb
Direct Known Subclasses
Charge, Customer, Household, Invoice, PaymentMethod, PaymentToken, Plan, SubAccount, Subscription, Transfer, Withdrawal
Class Method Summary
collapse
Class Method Details
.delete(endpoint, account_access_token) ⇒ Object
25
26
27
28
|
# File 'lib/jera_payment/api/iugu/base.rb', line 25
def self.delete(endpoint, account_access_token)
response = HTTParty.delete("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: (account_access_token))
parse_response(response)
end
|
.ensure_account_access_token(account_access_token) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/jera_payment/api/iugu/base.rb', line 34
def self.ensure_account_access_token(account_access_token)
if account_access_token.nil?
account_access_token = JeraPayment.is_test ? JeraPayment.api_key_test : JeraPayment.api_key
else
account_access_token
end
end
|
.get(endpoint, query, account_access_token) ⇒ Object
10
11
12
13
|
# File 'lib/jera_payment/api/iugu/base.rb', line 10
def self.get(endpoint, query, account_access_token)
response = HTTParty.get("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: (account_access_token), query: query)
parse_response(response)
end
|
.parse_response(response) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/jera_payment/api/iugu/base.rb', line 42
def self.parse_response(response)
if response.parsed_response.is_a?(Array) && response.parsed_response.first.is_a?(Hash)
response.parsed_response.map(&:deep_symbolize_keys)
elsif response.parsed_response.is_a?(Hash)
response.parsed_response.deep_symbolize_keys
else
response.parsed_response
end
end
|
.post(endpoint, body, account_access_token) ⇒ Object
15
16
17
18
|
# File 'lib/jera_payment/api/iugu/base.rb', line 15
def self.post(endpoint, body, account_access_token)
response = HTTParty.post("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: (account_access_token), body: body.to_json)
parse_response(response)
end
|
.put(endpoint, body, account_access_token) ⇒ Object
20
21
22
23
|
# File 'lib/jera_payment/api/iugu/base.rb', line 20
def self.put(endpoint, body, account_access_token)
response = HTTParty.put("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: (account_access_token), body: body.to_json)
parse_response(response)
end
|
30
31
32
|
# File 'lib/jera_payment/api/iugu/base.rb', line 30
def self.(account_access_token)
return { 'Content-Type': 'application/json', 'Authorization': "Basic #{Base64.encode64(ensure_account_access_token(account_access_token))}" }
end
|