Class: Monzo::Pot
- Inherits:
-
Object
- Object
- Monzo::Pot
- Defined in:
- lib/monzo/pot.rb
Overview
Public: Retrieve information about a pot. A Pot is a place to keep some money separate from your main spending account.
Instance Attribute Summary collapse
-
#balance ⇒ Object
readonly
Returns the value of attribute balance.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#deleted ⇒ Object
readonly
Returns the value of attribute deleted.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Class Method Summary collapse
-
.all ⇒ Object
Public: Find all Monzo Pots.
-
.find(pot_id) ⇒ Object
Public: Find a pot with the given pot id.
Instance Method Summary collapse
-
#deposit!(amount, source_account_id, dedupe_id = SecureRandom.uuid) ⇒ Object
Public: Deposit Money in a pot.
-
#initialize(params) ⇒ Pot
constructor
Public: Initialize an Pot.
-
#withdraw!(amount, destination_account_id, dedupe_id = SecureRandom.uuid) ⇒ Object
Public: Withdraw Money from a pot.
Constructor Details
#initialize(params) ⇒ Pot
Public: Initialize an Pot.
params - A Hash of pot parameters.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/monzo/pot.rb', line 15 def initialize(params) @id = params[:id] @name = params[:name] @style = params[:style] @balance = params[:balance] @currency = params[:currency] @created = params[:created] @updated = params[:updated] @deleted = params[:deleted] end |
Instance Attribute Details
#balance ⇒ Object (readonly)
Returns the value of attribute balance.
9 10 11 |
# File 'lib/monzo/pot.rb', line 9 def balance @balance end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
9 10 11 |
# File 'lib/monzo/pot.rb', line 9 def created @created end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
9 10 11 |
# File 'lib/monzo/pot.rb', line 9 def currency @currency end |
#deleted ⇒ Object (readonly)
Returns the value of attribute deleted.
9 10 11 |
# File 'lib/monzo/pot.rb', line 9 def deleted @deleted end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/monzo/pot.rb', line 9 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/monzo/pot.rb', line 9 def name @name end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
9 10 11 |
# File 'lib/monzo/pot.rb', line 9 def style @style end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
9 10 11 |
# File 'lib/monzo/pot.rb', line 9 def updated @updated end |
Class Method Details
.all ⇒ Object
Public: Find all Monzo Pots
Returns An Array of Monzo::Pot
29 30 31 32 33 34 35 36 |
# File 'lib/monzo/pot.rb', line 29 def self.all response = Monzo.client.get("/pots") parsed_response = JSON.parse(response.body, :symbolize_names => true) parsed_response[:pots].map do |item| Monzo::Pot.new(item) end end |
.find(pot_id) ⇒ Object
Public: Find a pot with the given pot id.
pot_id - The id to find.
Returns an instance of Monzo::Pot.
43 44 45 46 47 |
# File 'lib/monzo/pot.rb', line 43 def self.find(pot_id) response = Monzo.client.get("/pots/#{pot_id}") parsed_response = JSON.parse(response.body, :symbolize_names => true) Monzo::Pot.new(parsed_response) end |
Instance Method Details
#deposit!(amount, source_account_id, dedupe_id = SecureRandom.uuid) ⇒ Object
Public: Deposit Money in a pot
amount - The amount to deposit, in pennies. source_account_id - The account_id of the account to withdraw from. dedupe_id (optional) - A random string, to prevent duplicate deposits.
Returns self: a single Monzo::Pot
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/monzo/pot.rb', line 56 def deposit!(amount, source_account_id, dedupe_id = SecureRandom.uuid) data = { amount: amount, source_account_id: source_account_id, dedupe_id: dedupe_id, } response = Monzo.client.put("/pots/#{@id}/deposit", data) parsed_response = parse_response(response) update_self(parsed_response) end |
#withdraw!(amount, destination_account_id, dedupe_id = SecureRandom.uuid) ⇒ Object
Public: Withdraw Money from a pot
amount - The amount to withdraw, in pennies. destination_account_id - The account_id of the account to deposit into. dedupe_id (optional) - A random string, to prevent duplicate deposits.
Returns self: a single Monzo::Pot
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/monzo/pot.rb', line 75 def withdraw!(amount, destination_account_id, dedupe_id = SecureRandom.uuid) data = { amount: amount, destination_account_id: destination_account_id, dedupe_id: dedupe_id, } response = Monzo.client.put("/pots/#{@id}/withdraw", data) parsed_response = parse_response(response) update_self(parsed_response) end |