Class: JeraPayment::Api::Iugu::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/jera_payment/api/iugu/base.rb

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, )
  response = HTTParty.delete("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: set_headers())
  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.()
  if .nil?
     = JeraPayment.is_test ? JeraPayment.api_key_test : JeraPayment.api_key
  else
    
  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, )
  response = HTTParty.get("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: set_headers(), 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, )
  response = HTTParty.post("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: set_headers(), 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, )
  response = HTTParty.put("#{JeraPayment.iugu_base_url}/#{endpoint}", headers: set_headers(), body: body.to_json)
  parse_response(response)
end

.set_headers(account_access_token) ⇒ Object



30
31
32
# File 'lib/jera_payment/api/iugu/base.rb', line 30

def self.set_headers()
  return { 'Content-Type': 'application/json', 'Authorization': "Basic #{Base64.encode64(())}" }
end