class JeraPayment::Api::Iugu::Base

Public Class Methods

delete(endpoint, account_access_token) click to toggle source
# 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: set_headers(account_access_token))
  parse_response(response)
end
ensure_account_access_token(account_access_token) click to toggle source
# 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) click to toggle source
# 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: set_headers(account_access_token), query: query)
  parse_response(response)
end
parse_response(response) click to toggle source
# 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) click to toggle source
# 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: set_headers(account_access_token), body: body.to_json)
  parse_response(response)
end
put(endpoint, body, account_access_token) click to toggle source
# 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: set_headers(account_access_token), body: body.to_json)
  parse_response(response)
end
set_headers(account_access_token) click to toggle source
# File lib/jera_payment/api/iugu/base.rb, line 30
def self.set_headers(account_access_token)
  return { 'Content-Type': 'application/json', 'Authorization': "Basic #{Base64.encode64(ensure_account_access_token(account_access_token))}" }
end