Class: ProcessOut::Balances
- Inherits:
-
Object
- Object
- ProcessOut::Balances
- Defined in:
- lib/processout/balances.rb
Instance Attribute Summary collapse
-
#vouchers ⇒ Object
Returns the value of attribute vouchers.
Instance Method Summary collapse
-
#fill_with_data(data) ⇒ Object
- Fills the object with data coming from the API Params:
data
-
Hash
of data coming from the API.
- Fills the object with data coming from the API Params:
-
#find(token_id, options = {}) ⇒ Object
- Fetch a customer token’s balance Params:
token_id
- ID of the customer’s token
options
-
Hash
of options.
- ID of the customer’s token
- Fetch a customer token’s balance Params:
-
#initialize(client, data = {}) ⇒ Balances
constructor
- Initializes the Balances object Params:
client
ProcessOut
client instancedata
-
data that can be used to fill the object.
- Initializes the Balances object Params:
-
#new(data = {}) ⇒ Object
Create a new Balances using the current client.
-
#prefill(data) ⇒ Object
- Prefills the object with the data passed as parameters Params:
data
-
Hash
of data.
- Prefills the object with the data passed as parameters Params:
-
#to_json(options) ⇒ Object
Overrides the JSON marshaller to only send the fields we want.
Constructor Details
#initialize(client, data = {}) ⇒ Balances
Initializes the Balances object Params:
client
-
ProcessOut
client instance data
-
data that can be used to fill the object
39 40 41 42 43 44 |
# File 'lib/processout/balances.rb', line 39 def initialize(client, data = {}) @client = client self.vouchers = data.fetch(:vouchers, nil) end |
Instance Attribute Details
#vouchers ⇒ Object
Returns the value of attribute vouchers.
11 12 13 |
# File 'lib/processout/balances.rb', line 11 def vouchers @vouchers end |
Instance Method Details
#fill_with_data(data) ⇒ Object
Fills the object with data coming from the API Params:
data
-
Hash
of data coming from the API
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/processout/balances.rb', line 61 def fill_with_data(data) if data.nil? return self end if data.include? "vouchers" self.vouchers = data["vouchers"] end self end |
#find(token_id, options = {}) ⇒ Object
Fetch a customer token’s balance Params:
token_id
-
ID of the customer’s token
options
-
Hash
of options
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/processout/balances.rb', line 88 def find(token_id, = {}) self.prefill() request = Request.new(@client) path = "/balances/tokens/" + CGI.escape(token_id) + "" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new body = response.body body = body["balances"] balances = Balances.new(@client) return_values.push(balances.fill_with_data(body)) return_values[0] end |
#new(data = {}) ⇒ Object
Create a new Balances using the current client
47 48 49 |
# File 'lib/processout/balances.rb', line 47 def new(data = {}) Balances.new(@client, data) end |
#prefill(data) ⇒ Object
Prefills the object with the data passed as parameters Params:
data
-
Hash
of data
75 76 77 78 79 80 81 82 |
# File 'lib/processout/balances.rb', line 75 def prefill(data) if data.nil? return self end self.vouchers = data.fetch(:vouchers, self.vouchers) self end |
#to_json(options) ⇒ Object
Overrides the JSON marshaller to only send the fields we want
52 53 54 55 56 |
# File 'lib/processout/balances.rb', line 52 def to_json() { "vouchers": self.vouchers, }.to_json end |