Class: Buxfer::Base
Overview
Instance Method Summary collapse
-
#accounts ⇒ Object
Returns an array of Buxfer::Account objects.
-
#add_transaction(amount, description, account = nil, status = nil, tags = []) ⇒ Object
Add a transaction to Buxfer.
- #budgets ⇒ Object
- #contacts ⇒ Object
- #groups ⇒ Object
-
#initialize(username, password) ⇒ Base
constructor
Create a new Buxfer::Base object with a username and password.
- #loans ⇒ Object
- #reminders ⇒ Object
-
#reports(options = {}) ⇒ Object
Return a Buxfer::Report object.
-
#tags ⇒ Object
Returns an array of Buxfer::Tag objects.
-
#transactions(options = {}) ⇒ Object
Return an array of the last 25 transactions.
-
#upload_statement(account, statement, date_format = 'DD/MM/YYYY') ⇒ Object
Upload a file containing a transaction statement to Buxfer account.
Constructor Details
#initialize(username, password) ⇒ Base
Create a new Buxfer::Base object with a username and password.
56 57 58 59 |
# File 'lib/buxfer/base.rb', line 56 def initialize(username, password) @username = username @password = password end |
Instance Method Details
#accounts ⇒ Object
Returns an array of Buxfer::Account objects
154 155 156 |
# File 'lib/buxfer/base.rb', line 154 def accounts get_collection 'accounts', :class => Buxfer::Account end |
#add_transaction(amount, description, account = nil, status = nil, tags = []) ⇒ Object
Add a transaction to Buxfer. The amount and description must be specified.
An account name or Buxfer::Account object can be specified if the transaction is to be associated with a particular account.
An array of tag names can be specified.
Examples:
Buxfer.add_transaction(-10.0, 'Internet bill', 'Current account', nil, %w(bill payment))
Buxfer.add_transaction(1000, 'Salary', 'Current account', 'pending', %w(salary))
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/buxfer/base.rb', line 75 def add_transaction(amount, description, account = nil, status = nil, = []) amount = (amount < 0 ? amount.to_s : '+' + amount.to_s) = .join(',') attrs = {} text = [description, amount] account.respond_to?(:name) ? account.name : account.to_s {:acct => account, :status => status, :tags => }.each do |k, v| text << '%s:%s' % [k, v] unless v.blank? end self.class.post('/add_transaction.xml', auth_query({:text => text, :format => 'sms'}, :body)) end |
#budgets ⇒ Object
168 |
# File 'lib/buxfer/base.rb', line 168 def budgets; get_collection('budgets'); end |
#contacts ⇒ Object
174 |
# File 'lib/buxfer/base.rb', line 174 def contacts; get_collection('contacts'); end |
#groups ⇒ Object
172 |
# File 'lib/buxfer/base.rb', line 172 def groups; get_collection('groups'); end |
#loans ⇒ Object
166 |
# File 'lib/buxfer/base.rb', line 166 def loans; get_collection('loans'); end |
#reminders ⇒ Object
170 |
# File 'lib/buxfer/base.rb', line 170 def reminders; get_collection('reminders'); end |
#reports(options = {}) ⇒ Object
Return a Buxfer::Report object.
147 148 149 |
# File 'lib/buxfer/base.rb', line 147 def reports( = {}) Buxfer::Report.new(get('/reports.xml', auth_query())['response']) end |
#tags ⇒ Object
Returns an array of Buxfer::Tag objects
161 162 163 |
# File 'lib/buxfer/base.rb', line 161 def get_collection 'tags', :class => Buxfer::Tag end |
#transactions(options = {}) ⇒ Object
Return an array of the last 25 transactions.
Valid options:
-
:account
- A Buxfer::Account or account name -
:tag
- A Buxfer::Tag object or tag name -
:startDate
- Date in format ‘10 feb 2008’ or ‘2008-02-10’ -
:endDate
- Date in format ‘10 feb 2008’ or ‘2008-02-10’ -
:month
- Month name and year in short format ‘feb 08’
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/buxfer/base.rb', line 130 def transactions( = {}) .symbolize_keys! if account = .delete(:account) [:accountName] = account.is_a?(Buxfer::Account) ? account.name : account end if tag = .delete(:tag) [:tagName] = tag.is_a?(Buxfer::Tag) ? tag.name : tag end get_collection('transactions', ) end |
#upload_statement(account, statement, date_format = 'DD/MM/YYYY') ⇒ Object
Upload a file containing a transaction statement to Buxfer account. The account specified can be a Buxfer::Account (see #accounts) or an account id string.
The statement can be a String or an IO object.
An optional date format can be passed indicating if the dates used in the statement are in the format ‘DD/MM/YYYY’ (default) or ‘MM/DD/YYYY’
Example:
account = Buxfer.accounts.first
Buxfer.upload_statement(account, open('/path/to/file')) => true
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/buxfer/base.rb', line 103 def upload_statement(account, statement, date_format = 'DD/MM/YYYY') account_id = account.is_a?(Buxfer::Account) ? account.id : account unless statement.is_a?(String) if statement.respond_to?(:read) statement = statement.read else statement = statement.to_s end end = {:accountId => account_id, :statement => statement, :dateFormat => date_format} self.class.post('/upload_statement.xml', auth_query(, :body)) end |