Class: Monzo::Transaction
- Inherits:
-
Object
- Object
- Monzo::Transaction
- Defined in:
- lib/monzo/transaction.rb
Overview
Public: Transactions are movements of funds into or out of an account.
Negative transactions represent debits (ie. spending money) and
positive transactions represent credits (ie. receiving money).
Instance Attribute Summary collapse
-
#account_balance ⇒ Object
readonly
Returns the value of attribute account_balance.
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#counterparty ⇒ Object
readonly
Returns the value of attribute counterparty.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#dedupe_id ⇒ Object
readonly
Returns the value of attribute dedupe_id.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#include_in_spending ⇒ Object
readonly
Returns the value of attribute include_in_spending.
-
#is_load ⇒ Object
readonly
Returns the value of attribute is_load.
-
#local_amount ⇒ Object
readonly
Returns the value of attribute local_amount.
-
#local_currency ⇒ Object
readonly
Returns the value of attribute local_currency.
-
#merchant ⇒ Object
readonly
Returns the value of attribute merchant.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#originator ⇒ Object
readonly
Returns the value of attribute originator.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#settled ⇒ Object
readonly
Returns the value of attribute settled.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Class Method Summary collapse
-
.all(account_id) ⇒ Object
Public: Find all the transactions for a given account id.
-
.create_annotation(transaction_id, metadata) ⇒ Object
Public: Create an annotation for a given transaction id.
-
.find(transaction_id, options = {}) ⇒ Object
Public: Find a transaction with the given transaction id.
Instance Method Summary collapse
-
#initialize(params) ⇒ Transaction
constructor
Public: Initialize a Transaction.
Constructor Details
#initialize(params) ⇒ Transaction
Public: Initialize a Transaction.
params - A Hash of transaction parameters.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/monzo/transaction.rb', line 17 def initialize(params) @id = params[:id] @created = params[:created] @description = params[:description] @amount = params[:amount] @currency = params[:currency] @merchant = params[:merchant] @notes = params[:notes] @metadata = params[:metadata] @account_balance = params[:account_balance] @attachments = params[:attachments] @category = params[:category] @is_load = params[:is_load] @settled = params[:settled] @local_amount = params[:local_amount] @local_currency = params[:local_currency] @updated = params[:updated] @account_id = params[:account_id] @counterparty = params[:counterparty] @scheme = params[:scheme] @dedupe_id = params[:dedupe_id] @originator = params[:originator] @include_in_spending = params[:include_in_spending] end |
Instance Attribute Details
#account_balance ⇒ Object (readonly)
Returns the value of attribute account_balance.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def account_balance @account_balance end |
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def account_id @account_id end |
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def amount @amount end |
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def @attachments end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def category @category end |
#counterparty ⇒ Object (readonly)
Returns the value of attribute counterparty.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def counterparty @counterparty end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def created @created end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def currency @currency end |
#dedupe_id ⇒ Object (readonly)
Returns the value of attribute dedupe_id.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def dedupe_id @dedupe_id end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def id @id end |
#include_in_spending ⇒ Object (readonly)
Returns the value of attribute include_in_spending.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def include_in_spending @include_in_spending end |
#is_load ⇒ Object (readonly)
Returns the value of attribute is_load.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def is_load @is_load end |
#local_amount ⇒ Object (readonly)
Returns the value of attribute local_amount.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def local_amount @local_amount end |
#local_currency ⇒ Object (readonly)
Returns the value of attribute local_currency.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def local_currency @local_currency end |
#merchant ⇒ Object (readonly)
Returns the value of attribute merchant.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def merchant @merchant end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def @metadata end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def notes @notes end |
#originator ⇒ Object (readonly)
Returns the value of attribute originator.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def originator @originator end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def scheme @scheme end |
#settled ⇒ Object (readonly)
Returns the value of attribute settled.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def settled @settled end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
8 9 10 |
# File 'lib/monzo/transaction.rb', line 8 def updated @updated end |
Class Method Details
.all(account_id) ⇒ Object
Public: Find all the transactions for a given account id.
account_id - The account id to retrieve transactions from.
Returns an Array of Monzo::Transaction.
61 62 63 64 65 66 67 68 |
# File 'lib/monzo/transaction.rb', line 61 def self.all(account_id) response = Monzo.client.get("/transactions", :account_id => account_id) parsed_response = JSON.parse(response.body, :symbolize_names => true) parsed_response[:transactions].map do |item| Monzo::Transaction.new(item) end end |
.create_annotation(transaction_id, metadata) ⇒ Object
Public: Create an annotation for a given transaction id. You may store your own key-value annotations against a transaction in its metadata.
transaction_id - The transaction id to annotate. metadata - a hash of annotations to add.
Returns an instance of Monzo::Transaction with the annotations.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/monzo/transaction.rb', line 77 def self.create_annotation(transaction_id, ) data = {} .each do |k, v| data["metadata[#{k.to_s}]"] = v end response = Monzo.client.patch("/transactions/#{transaction_id}", data, {}) parsed_response = JSON.parse(response.body, :symbolize_names => true) Monzo::Transaction.new(parsed_response[:transaction]) end |
.find(transaction_id, options = {}) ⇒ Object
Public: Find a transaction with the given transaction id.
transaction_id - The id to find. options - a Hash of options to request further information such as the
merchant information (optional)
Returns an instance of Monzo::Transaction.
49 50 51 52 53 54 |
# File 'lib/monzo/transaction.rb', line 49 def self.find(transaction_id, = {}) response = Monzo.client.get("/transactions/#{transaction_id}", ) parsed_response = JSON.parse(response.body, :symbolize_names => true) Monzo::Transaction.new(parsed_response[:transaction]) end |