Class: Wesabe

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • username (String)

    The username of an active Wesabe user.

  • password (String)

    The password of an active Wesabe 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

#passwordObject

Returns the value of attribute password.



16
17
18
# File 'lib/wesabe.rb', line 16

def password
  @password
end

#usernameObject

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.(4).name # => "Amex Blue"

Parameters:

  • id (#to_s)

    Something whose to_s result matches the to_s result of the account id.

Returns:

  • (Wesabe::Account, nil)

    The account whose user-scoped id is id or nil if there is no account with that id.



70
71
72
# File 'lib/wesabe.rb', line 70

def (id)
  accounts.find {|a| a.id.to_s == id.to_s}
end

#accountsArray<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">]

Returns:



56
57
58
# File 'lib/wesabe.rb', line 56

def accounts
  @accounts ||= load_accounts
end

#credentialsArray<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>]

Returns:



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.

See Also:

  • Wesabe::Request::execute


110
111
112
# File 'lib/wesabe.rb', line 110

def get(options)
  Request.execute({:method => :get, :username => username, :password => password}.merge(options))
end

#inspectObject



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.

See Also:

  • Wesabe::Request::execute


103
104
105
# File 'lib/wesabe.rb', line 103

def post(options)
  Request.execute({:method => :post, :username => username, :password => password}.merge(options))
end

#targetsObject

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