class Tangocard::Raas

Public Class Methods

cc_fund_account(params) click to toggle source

Funds an account. Returns Tangocard::Response object.

Example:

>> Tangocard::Raas.cc_fund_account(params)
 => #<Tangocard::Response:0x007f9a6c4bca68 ...>

Arguments:

params: (Hash - see https://www.tangocard.com/docs/raas-api/#create-cc-fund for details)
# File lib/tangocard/raas.rb, line 36
def self.cc_fund_account(params)
  Tangocard::Response.new(post_request('/cc_fund', { body: params.to_json }))
end
create_account(params) click to toggle source

Create a new account. Returns Tangocard::Response object.

Example:

>> Tangocard::Raas.create_account(params)
 => #<Tangocard::Response:0x007f9a6c4bca68 ...>

Arguments:

params: (Hash - see https://www.tangocard.com/docs/raas-api/#create-account for details)
# File lib/tangocard/raas.rb, line 12
def self.create_account(params)
  Tangocard::Response.new(post_request('/accounts', { body: params.to_json }))
end
create_order(params) click to toggle source

Create an order. Returns Tangocard::Response object.

Example:

>> Tangocard::Raas.create_order(params)
 => #<Tangocard::Response:0x007f9a6c4bca68 ...>

Arguments:

params: (Hash - see https://www.tangocard.com/docs/raas-api/#create-order for details)
# File lib/tangocard/raas.rb, line 90
def self.create_order(params)
  Tangocard::Response.new(post_request('/orders', { body: params.to_json }))
end
delete_credit_card(params) click to toggle source

Deletes a credit card from an account. Returns Tangocard::Response object.

Example:

>> Tangocard::Raas.delete_credit_card(params)
 => #<Tangocard::Response:0x007f9a6c4bca68 ...>

Arguments:

params: (Hash - see https://www.tangocard.com/docs/raas-api/#create-cc-un-registration for details)
# File lib/tangocard/raas.rb, line 60
def self.delete_credit_card(params)
  Tangocard::Response.new(post_request('/cc_unregister', { body: params.to_json }))
end
orders_index(params = {}) click to toggle source

Retrieve a list of historical orders. Returns Tangocard::Response object.

Example:

>> Tangocard::Raas.orders_index
 => #<Tangocard::Response:0x007f9a6c4bca68 ...>

Arguments:

params: (Hash - see https://www.tangocard.com/docs/raas-api/#list-orders for details)
# File lib/tangocard/raas.rb, line 114
def self.orders_index(params = {})
  query_string = ""
  if params.any?
    query_string = "?"
    params.keys.each_with_index do |k, i|
      query_string += "&" unless i == 0
      query_string += "#{k}=#{params[k]}"
    end
  end
  Tangocard::Response.new(get_request("/orders#{query_string}"))
end
register_credit_card(params) click to toggle source

Registers a credit card to an account. Returns Tangocard::Response object.

Example:

>> Tangocard::Raas.register_credit_card(params)
 => #<Tangocard::Response:0x007f9a6c4bca68 ...>

Arguments:

params: (Hash - see https://www.tangocard.com/docs/raas-api/#create-cc-registration for details)
# File lib/tangocard/raas.rb, line 48
def self.register_credit_card(params)
  Tangocard::Response.new(post_request('/cc_register', { body: params.to_json }))
end
rewards_index(use_cache: true) click to toggle source

Retrieve all rewards. Returns Tangocard::Response object.

Example:

>> Tangocard::Raas.rewards_index
 => #<Tangocard::Response:0x007f9a6c4bca68 ...>

Arguments:

none
# File lib/tangocard/raas.rb, line 72
def self.rewards_index(use_cache: true)
  if Tangocard.configuration.use_cache && use_cache
    cached_response = Tangocard.configuration.cache.read("#{Tangocard::CACHE_PREFIX}rewards_index")
    raise Tangocard::RaasException.new('Tangocard cache is not primed. Either configure the gem to run without caching or warm the cache before calling cached endpoints') if cached_response.nil?
    cached_response
  else
    Tangocard::Response.new(get_request('/rewards'))
  end
end
show_account(params) click to toggle source

Gets account details. Returns Tangocard::Response object.

Example:

>> Tangocard::Raas.show_account(params)
 => #<Tangocard::Response:0x007f9a6c4bca68 ...>

Arguments:

params: (Hash - see https://www.tangocard.com/docs/raas-api/#get-account for details)
# File lib/tangocard/raas.rb, line 24
def self.show_account(params)
  Tangocard::Response.new(get_request("/accounts/#{params['customer']}/#{params['identifier']}"))
end
show_order(params) click to toggle source

Get order details. Returns Tangocard::Response object.

Example:

>> Tangocard::Raas.show_order(params)
 => #<Tangocard::Response:0x007f9a6c4bca68 ...>

Arguments:

params: (Hash - see https://www.tangocard.com/docs/raas-api/#get-order for details)
# File lib/tangocard/raas.rb, line 102
def self.show_order(params)
  Tangocard::Response.new(get_request("/orders/#{params['order_id']}"))
end

Private Class Methods

basic_auth_param() click to toggle source
# File lib/tangocard/raas.rb, line 128
def self.basic_auth_param
  { basic_auth: { username: Tangocard.configuration.name, password: Tangocard.configuration.key } }
end
endpoint() click to toggle source
# File lib/tangocard/raas.rb, line 132
def self.endpoint
  "#{Tangocard.configuration.base_uri}/raas/v1.1"
end
get_request(path) click to toggle source
# File lib/tangocard/raas.rb, line 136
def self.get_request(path)
  get("#{endpoint}#{path}", basic_auth_param)
end
post_request(path, params) click to toggle source
# File lib/tangocard/raas.rb, line 140
def self.post_request(path, params)
  post("#{endpoint}#{path}", basic_auth_param.merge(params))
end