Class: Wesabe::Account

Inherits:
BaseModel show all
Defined in:
lib/wesabe/account.rb

Overview

Encapsulates an account from Wesabe’s API.

Instance Attribute Summary collapse

Attributes inherited from BaseModel

#wesabe

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#get, #post

Methods included from Util

#all_or_one

Constructor Details

#initialize {|account| ... } ⇒ Account

Initializes a Wesabe::Account and yields itself.

Yield Parameters:



22
23
24
# File 'lib/wesabe/account.rb', line 22

def initialize
  yield self if block_given?
end

Instance Attribute Details

#balanceObject

This account’s balance or nil if the account is a cash account.



12
13
14
# File 'lib/wesabe/account.rb', line 12

def balance
  @balance
end

#currencyObject

This account’s currency.



14
15
16
# File 'lib/wesabe/account.rb', line 14

def currency
  @currency
end

#financial_institutionObject

The financial institution this account is held at.



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

def financial_institution
  @financial_institution
end

#idObject

The user-scoped account id, used to identify the account in URLs.



4
5
6
# File 'lib/wesabe/account.rb', line 4

def id
  @id
end

#nameObject

The user-provided account name (“Bank of America - Checking”)



8
9
10
# File 'lib/wesabe/account.rb', line 8

def name
  @name
end

#numberObject

The application-scoped account id, used in upload



6
7
8
# File 'lib/wesabe/account.rb', line 6

def number
  @number
end

#typeObject

The account type (“Credit Card”, “Savings” …)



10
11
12
# File 'lib/wesabe/account.rb', line 10

def type
  @type
end

Class Method Details

.from_xml(xml) ⇒ Wesabe::Account

Returns a Wesabe::Account generated from Wesabe’s API XML.

Parameters:

  • xml (Hpricot::Element)

    The <account> element from the API.

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/wesabe/account.rb', line 45

def self.from_xml(xml)
  new do ||
    .id = xml.at("id").inner_text.to_i
    .name = xml.at("name").inner_text
    .type = xml.at("account-type").inner_text
    .number = xml.at("account-number").inner_text if xml.at("account-number")
    balance = xml.at("current-balance")
    .balance = balance.inner_text.to_f if balance
    .currency = Wesabe::Currency.from_xml(xml.at("currency"))
    fi = xml.at("financial-institution")
    .financial_institution = Wesabe::FinancialInstitution.from_xml(fi) if fi
  end
end

Instance Method Details

#inspectObject



59
60
61
# File 'lib/wesabe/account.rb', line 59

def inspect
  inspect_these :id, :number, :type, :name, :balance, :financial_institution, :currency
end

#new_uploadWesabe::Upload

Creates a Wesabe::Upload that can be used to upload to this account.

Returns:

  • (Wesabe::Upload)

    The newly-created upload, ready to be used to upload a statement.



30
31
32
33
34
35
36
# File 'lib/wesabe/account.rb', line 30

def new_upload
  Wesabe::Upload.new do |upload|
    upload.accounts = [self]
    upload.financial_institution = financial_institution
    associate upload
  end
end