Class: OFXClient
- Inherits:
-
Object
- Object
- OFXClient
- Defined in:
- lib/OFXClient.rb
Class Method Summary collapse
-
.all_institutions ⇒ Object
returns hash of ALL FI names : fids.
- .get_institution(fid) ⇒ Object
- .investment_accounts(fi, username, password) ⇒ Object
- .investment_holdings(fi, username, password, accountNumber) ⇒ Object
-
.search_institutions(term) ⇒ Object
returns hash of FI names : fids names include or match the passed search term.
Class Method Details
.all_institutions ⇒ Object
returns hash of ALL FI names : fids
66 67 68 69 70 71 |
# File 'lib/OFXClient.rb', line 66 def self.all_institutions httpClient = HTTPClient.new res = httpClient.get_content("http://www.ofxhome.com/api.php?all=yes") doc = Nokogiri::XML(res) return OFXClient::doc_to_hash(doc) end |
.get_institution(fid) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/OFXClient.rb', line 73 def self.get_institution(fid) httpClient = HTTPClient.new res = httpClient.get_content("http://www.ofxhome.com/api.php?lookup=" + fid.to_s) doc = Nokogiri::XML(res) institutionElements = doc.xpath("//institution") if(institutionElements.length == 1) if(institutionElements.first["id"].eql? fid.to_s) name = doc.xpath("//institution//name").first.content org = doc.xpath("//institution//org").first.content url = doc.xpath("//institution//url").first.content return FinancialInstitution.new(fid, name, org, url) else # error in ofxhome api return nil end else # the institution with specified fid doesn't exist # in the ofxhome.com database return nil end end |
.investment_accounts(fi, username, password) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/OFXClient.rb', line 8 def self.investment_accounts(fi, username, password) # construct our OFX XML builder = Nokogiri::XML::Builder.new do |xml| xml.OFX { xml.SIGNONMSGSRQV1 { xml.SONRQ { xml.DTCLIENT Time.new.strftime("%Y%m%d%H%M%S") xml.USERID username xml.USERPASS password xml.LANGUAGE "ENG" xml.FI { xml.FID fi.fid.to_s xml.ORG fi.org } xml.APPID "funds" xml.APPVER "0.0.1" } } xml.SIGNUPMSGSRQV1 { xml.xxxxTRNRQ { } } } end # insert the required OFX declaration after XML declaration # nokogiri's builder cannot do this ofxDeclaration = "\n<?OFX OFXHEADER=\"200\" VERSION=\"211\" SECURITY=\"NONE\" OLDFILEUID=\"NONE\" NEWFILEUID=\"NONE\"?>" xml = builder.to_xml.insert(21, ofxDeclaration) #puts xml httpClient = HTTPClient.new #required headers extheader = [['Content-Type', 'application/x-ofx']] extheader.push(['Content-Length', xml.bytesize.to_s]) end |
.investment_holdings(fi, username, password, accountNumber) ⇒ Object
52 53 54 |
# File 'lib/OFXClient.rb', line 52 def self.investment_holdings(fi, username, password, accountNumber) end |
.search_institutions(term) ⇒ Object
returns hash of FI names : fids names include or match the passed search term
58 59 60 61 62 63 |
# File 'lib/OFXClient.rb', line 58 def self.search_institutions(term) httpClient = HTTPClient.new res = httpClient.get_content("http://www.ofxhome.com/api.php?search=" + term) doc = Nokogiri::XML(res) return OFXClient::doc_to_hash(doc) end |