Class: Tango::Client
- Inherits:
-
Object
- Object
- Tango::Client
- Defined in:
- lib/tango/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#connection ⇒ Faraday::Connection
Returns a Faraday::Connection object.
-
#endpoint ⇒ String
Constructs endpoint from options.
-
#get_available_balance ⇒ Integer
Get user available balance.
-
#initialize(options = {}) ⇒ Client
constructor
Initialize an instance with specified options.
-
#post(path, params = {}) ⇒ Object
Perform an HTTP POST request.
-
#purchase_card(params = {}) ⇒ Hash
Purchase a card.
Constructor Details
#initialize(options = {}) ⇒ Client
Initialize an instance with specified options. Unless an option is specified, the corresponding value from Default.options is used.
24 25 26 |
# File 'lib/tango/client.rb', line 24 def initialize( = {}) @options = ::Tango::Default.template.merge() end |
Instance Attribute Details
#options ⇒ Hash
10 11 12 |
# File 'lib/tango/client.rb', line 10 def @options end |
Instance Method Details
#connection ⇒ Faraday::Connection
Returns a Faraday::Connection object
54 55 56 |
# File 'lib/tango/client.rb', line 54 def connection @connection ||= Faraday.new(endpoint, ) end |
#endpoint ⇒ String
Constructs endpoint from options
61 62 63 |
# File 'lib/tango/client.rb', line 61 def endpoint .values_at(:endpoint, :version).join('/') end |
#get_available_balance ⇒ Integer
Get user available balance
36 37 38 39 |
# File 'lib/tango/client.rb', line 36 def get_available_balance response = post 'GetAvailableBalance' balance = response[:body][:availableBalance] end |
#post(path, params = {}) ⇒ Object
Perform an HTTP POST request
29 30 31 |
# File 'lib/tango/client.rb', line 29 def post(path, params = {}) request(:post, path, params) end |
#purchase_card(params = {}) ⇒ Hash
Purchase a card
46 47 48 49 |
# File 'lib/tango/client.rb', line 46 def purchase_card(params = {}) response = post 'PurchaseCard', params response[:body] end |