Class: Wesabe
- Inherits:
-
Object
- Object
- Wesabe
- Defined in:
- lib/wesabe.rb
Overview
Provides an object-oriented interface to the Wesabe API.
Defined Under Namespace
Modules: Util Classes: Account, BaseModel, Credential, Currency, FinancialInstitution, Job, Request, Target, Upload
Constant Summary collapse
- VERSION =
'0.0.3'
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#account(id) ⇒ Wesabe::Account?
Returns an account with the given id or
nil
if the account is not found. -
#accounts ⇒ Array<Wesabe::Account>
Fetches the user’s accounts list from Wesabe or, if the list was already fetched, returns the cached result.
-
#credentials ⇒ Array<Wesabe::Account>
Fetches the user’s accounts list from Wesabe or, if the list was already fetched, returns the cached result.
-
#get(options) ⇒ Object
Executes a request via GET with the initial username and password.
-
#initialize(username, password) ⇒ Wesabe
constructor
Initializes access to the Wesabe API with a certain user.
- #inspect ⇒ Object
-
#post(options) ⇒ Object
Executes a request via POST with the initial username and password.
-
#targets ⇒ Object
Fetches the user’s targets list from Wesabe or, if the list was already fetched, returns the cached result.
Constructor Details
#initialize(username, password) ⇒ Wesabe
Initializes access to the Wesabe API with a certain user. All requests will be made in the context of this user.
28 29 30 31 |
# File 'lib/wesabe.rb', line 28 def initialize(username, password) self.username = username self.password = password end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
16 17 18 |
# File 'lib/wesabe.rb', line 16 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
16 17 18 |
# File 'lib/wesabe.rb', line 16 def username @username end |
Instance Method Details
#account(id) ⇒ Wesabe::Account?
Returns an account with the given id or nil
if the account is not found.
wesabe.account(4).name # => "Amex Blue"
70 71 72 |
# File 'lib/wesabe.rb', line 70 def account(id) accounts.find {|a| a.id.to_s == id.to_s} end |
#accounts ⇒ Array<Wesabe::Account>
Fetches the user’s accounts list from Wesabe or, if the list was already fetched, returns the cached result.
pp wesabe.accounts
[#<Wesabe::Account:0x106105c
@balance=-393.42,
@currency=
#<Wesabe::Currency:0x104fdc0
@decimal_places=2,
@delimiter=",",
@separator=".",
@symbol="$">,
@financial_institution=
#<Wesabe::FinancialInstitution:0x104b054
@homepage_url=nil,
@id="us-003383",
@login_url=nil,
@name="American Express Card">,
@id=4,
@name="Amex Blue">]
56 57 58 |
# File 'lib/wesabe.rb', line 56 def accounts @accounts ||= load_accounts end |
#credentials ⇒ Array<Wesabe::Account>
Fetches the user’s accounts list from Wesabe or, if the list was already fetched, returns the cached result.
pp wesabe.credentials
[#<Wesabe::Credential:0x10ae870
@accounts=[],
@financial_institution=
#<Wesabe::FinancialInstitution:0x1091928
@homepage_url=nil,
@id="us-003383",
@login_url=nil,
@name="American Express Card">,
@id=3>]
90 91 92 |
# File 'lib/wesabe.rb', line 90 def credentials @credentials ||= load_credentials end |
#get(options) ⇒ Object
Executes a request via GET with the initial username and password.
110 111 112 |
# File 'lib/wesabe.rb', line 110 def get() Request.execute({:method => :get, :username => username, :password => password}.merge()) end |
#inspect ⇒ Object
114 115 116 |
# File 'lib/wesabe.rb', line 114 def inspect "#<#{self.class.name} username=#{username.inspect} password=#{password.gsub(/./, '*').inspect} url=#{Wesabe::Request.base_url.inspect}>" end |
#post(options) ⇒ Object
Executes a request via POST with the initial username and password.
103 104 105 |
# File 'lib/wesabe.rb', line 103 def post() Request.execute({:method => :post, :username => username, :password => password}.merge()) end |
#targets ⇒ Object
Fetches the user’s targets list from Wesabe or, if the list was already fetched, returns the cached result.
96 97 98 |
# File 'lib/wesabe.rb', line 96 def targets @targets ||= load_targets end |