Class: Tango::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/tango/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Initialize an instance with specified options. Unless an option is specified, the corresponding value from Default.options is used.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • (Object)
  • username (String)

    Tango account username

  • password (String)

    Tango account password

  • endpoint (String)

    API endpoint, the whole API URL prefix is “endpoint/version”.

  • version (String)

    version part of API URL

  • middleware (Faraday::Builder)

    Faraday’s middleware stack

  • connection_options (Hash)

    Further options for Faraday connection



24
25
26
# File 'lib/tango/client.rb', line 24

def initialize(options = {})
  @options = ::Tango::Default.template.merge(options)
end

Instance Attribute Details

#optionsHash

Returns:

  • (Hash)


10
11
12
# File 'lib/tango/client.rb', line 10

def options
  @options
end

Instance Method Details

#connectionFaraday::Connection

Returns a Faraday::Connection object

Returns:

  • (Faraday::Connection)


54
55
56
# File 'lib/tango/client.rb', line 54

def connection
  @connection ||= Faraday.new(endpoint, connection_options)
end

#endpointString

Constructs endpoint from options

Returns:

  • (String)


61
62
63
# File 'lib/tango/client.rb', line 61

def endpoint
  options.values_at(:endpoint, :version).join('/')
end

#get_available_balanceInteger

Get user available balance

Returns:

  • (Integer)

    balance in cents (100 = $1.00)

See Also:



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

Returns:

  • (Hash)

    “response” part of the returned JSON. All keys are symbols.

See Also:



46
47
48
49
# File 'lib/tango/client.rb', line 46

def purchase_card(params = {})
  response = post 'PurchaseCard', params
  response[:body]
end