Class: ProcessOut::Balances

Inherits:
Object
  • Object
show all
Defined in:
lib/processout/balances.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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



73
74
75
76
77
78
79
80
# File 'lib/processout/balances.rb', line 73

def initialize(client, data = {})
  @client = client

  self.vouchers = data.fetch(:vouchers, nil)
  self.available_balance = data.fetch(:available_balance, nil)
  self.customer_action = data.fetch(:customer_action, nil)
  
end

Instance Attribute Details

#available_balanceObject

Returns the value of attribute available_balance.



12
13
14
# File 'lib/processout/balances.rb', line 12

def available_balance
  @available_balance
end

#customer_actionObject

Returns the value of attribute customer_action.



13
14
15
# File 'lib/processout/balances.rb', line 13

def customer_action
  @customer_action
end

#vouchersObject

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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/processout/balances.rb', line 99

def fill_with_data(data)
  if data.nil?
    return self
  end
  if data.include? "vouchers"
    self.vouchers = data["vouchers"]
  end
  if data.include? "available_balance"
    self.available_balance = data["available_balance"]
  end
  if data.include? "customer_action"
    self.customer_action = data["customer_action"]
  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



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/processout/balances.rb', line 134

def find(token_id, options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/balances/tokens/" + CGI.escape(token_id) + ""
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  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



83
84
85
# File 'lib/processout/balances.rb', line 83

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



119
120
121
122
123
124
125
126
127
128
# File 'lib/processout/balances.rb', line 119

def prefill(data)
  if data.nil?
    return self
  end
  self.vouchers = data.fetch(:vouchers, self.vouchers)
  self.available_balance = data.fetch(:available_balance, self.available_balance)
  self.customer_action = data.fetch(:customer_action, self.customer_action)
  
  self
end

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



88
89
90
91
92
93
94
# File 'lib/processout/balances.rb', line 88

def to_json(options)
  {
      "vouchers": self.vouchers,
      "available_balance": self.available_balance,
      "customer_action": self.customer_action,
  }.to_json
end