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(iid) ⇒ Object
- .get_statement(fi, account, username, password, startDate, endDate) ⇒ Object
- .post_ofx(url, ofxBody) ⇒ 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
76 77 78 79 80 81 |
# File 'lib/OFXClient.rb', line 76 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(iid) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/OFXClient.rb', line 83 def self.get_institution(iid) httpClient = HTTPClient.new res = httpClient.get_content("http://www.ofxhome.com/api.php?lookup=" + iid.to_s) doc = Nokogiri::XML(res) institutionElements = doc.xpath("//institution") if(institutionElements.length == 1) if(institutionElements.first["id"].eql? iid.to_s) fid = doc.xpath("//institution//fid").first.content.to_i 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 |
.get_statement(fi, account, username, password, startDate, endDate) ⇒ Object
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/OFXClient.rb', line 11 def self.get_statement(fi, account, username, password, startDate, endDate) if(account.type.eql?(AccountType::CHECKING) || account.type.eql?(AccountType::SAVINGS)) ofx = OFXClient::create_headers() + '<OFX>' + create_signon(fi, username, password) + '<BANKMSGSRQV1>' + '<STMTTRNRQ>' + '<TRNUID>' + OFXClient::generate_uuid(32) + '<CLTCOOKIE>' + OFXClient::generate_uuid(5) + '<STMTRQ>' + '<BANKACCTFROM>' + '<BANKID>' + account.routingNumber + '<ACCTID>' + account.accountNumber + '<ACCTTYPE>' + account.type + '</BANKACCTFROM>' + '<INCTRAN>' + '<DTSTART>' + startDate + '<DTEND>' + endDate + '<INCLUDE>Y</INCTRAN>' + '</STMTRQ>' + '</STMTTRNRQ>' + '</BANKMSGSRQV1>' + '</OFX>'; OFXClient::post_ofx(fi.url, ofx); end if(account.type.eql?(AccountType::CREDITCARD)) ofx = OFXClient::create_headers() + '<OFX>' + create_signon(fi, username, password) + '<CREDITCARDMSGSRQV1>' + '<CCSTMTTRNRQ>' + '<TRNUID>' + OFXClient::generate_uuid(32) + '<CLTCOOKIE>' + OFXClient::generate_uuid(5) + '<CCSTMTRQ>' + '<CCACCTFROM>' + '<ACCTID>' + account.accountNumber + '</CCACCTFROM>' + '<INCTRAN>' + '<DTSTART>' + startDate + '<INCLUDE>Y</INCTRAN>' + '</CCSTMTRQ>' + '</CCSTMTTRNRQ>' + '</CREDITCARDMSGSRQV1>' + '</OFX>'; OFXClient::post_ofx(fi.url, ofx); end end |
.post_ofx(url, ofxBody) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/OFXClient.rb', line 110 def self.post_ofx(url, ofxBody) httpClient = HTTPClient.new #required headers extheader = [['Content-Type', 'application/x-ofx']] extheader = [['User-Agent', 'funds']] #extheader.push(['Content-Length', ofxBody.bytesize.to_s]) extheader.push(['Accept', 'application/ofx']) res = httpClient.post(url, ofxBody, extheader, nil) return res.body end |
.search_institutions(term) ⇒ Object
returns hash of FI names : fids names include or match the passed search term
68 69 70 71 72 73 |
# File 'lib/OFXClient.rb', line 68 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 |