Class: Wesabe::Credential

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

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 {|credential| ... } ⇒ Credential

Initializes a Wesabe::Credential and yields itself.

Yield Parameters:



13
14
15
# File 'lib/wesabe/credential.rb', line 13

def initialize
  yield self if block_given?
end

Instance Attribute Details

#accountsObject

The accounts linked to this credential.



7
8
9
# File 'lib/wesabe/credential.rb', line 7

def accounts
  @accounts
end

#financial_institutionObject

The financial institution this credential is for.



5
6
7
# File 'lib/wesabe/credential.rb', line 5

def financial_institution
  @financial_institution
end

#idObject

The id of the credential, used to identify the account in URLs.



3
4
5
# File 'lib/wesabe/credential.rb', line 3

def id
  @id
end

Class Method Details

.from_xml(xml) ⇒ Wesabe::Credential

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

Parameters:

  • xml (Hpricot::Element)

    The <credential> element from the API.

Returns:



32
33
34
35
36
37
38
39
40
41
# File 'lib/wesabe/credential.rb', line 32

def self.from_xml(xml)
  new do |cred|
    cred.id = xml.at('id').inner_text.to_i
    cred.financial_institution = Wesabe::FinancialInstitution.from_xml(
                                  xml.children_of_type('financial-institution')[0])
    cred.accounts = xml.search('accounts account').map do ||
      Wesabe::Account.from_xml()
    end
  end
end

Instance Method Details

#inspectObject



43
44
45
# File 'lib/wesabe/credential.rb', line 43

def inspect
  inspect_these :id, :financial_institution, :accounts
end

#start_jobWesabe::Job

Starts a new sync job for this Wesabe::Credential.

Returns:



21
22
23
# File 'lib/wesabe/credential.rb', line 21

def start_job
  associate(Wesabe::Job.from_xml(Hpricot::XML(post(:url => "/credentials/#{id}/jobs.xml")) / :job))
end