Class: OFX::FinancialInstitution
- Inherits:
-
Object
- Object
- OFX::FinancialInstitution
- Defined in:
- lib/ofx/financial_institution.rb
Instance Attribute Summary collapse
-
#bank_identifier ⇒ Object
readonly
Returns the value of attribute bank_identifier.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ofx_uri ⇒ Object
readonly
Returns the value of attribute ofx_uri.
-
#ofx_version ⇒ Object
readonly
Returns the value of attribute ofx_version.
-
#organization_id ⇒ Object
readonly
Returns the value of attribute organization_id.
-
#organization_name ⇒ Object
readonly
Returns the value of attribute organization_name.
Class Method Summary collapse
Instance Method Summary collapse
- #create_request_document ⇒ Object
- #create_request_document_for_bank_statement(account_id, date_range = nil, account_type = :checking) ⇒ Object
- #create_request_document_for_cc_closing_statement(account_id) ⇒ Object
- #create_request_document_for_cc_statement(account_id, date_range = nil, include_trans = true) ⇒ Object
- #create_request_document_for_inv_statement(account_id, date_range = nil) ⇒ Object
- #create_request_document_profile_update(request_date = nil) ⇒ Object
- #create_request_document_signon ⇒ Object
- #create_request_document_signup(request_date = nil) ⇒ Object
- #document_to_post_data(document, no_whitespace = false) ⇒ Object
- #get_account_id(account_id = nil) ⇒ Object
-
#get_anon_profile ⇒ Object
Debugging routines.
-
#initialize(name, ofx_uri, ofx_version, org_name, org_id, bank_id = nil, client_id = nil, ssl_version = nil) ⇒ FinancialInstitution
constructor
A new instance of FinancialInstitution.
- #send(document) ⇒ Object
- #set_client(user_name, password, client_uid = nil) ⇒ Object
-
#set_client_anon ⇒ Object
anonymous can be used for ProfileRequest.
- #test_send(data, post_data = nil, serial_resp = true, debug_req = false, debug_resp = false) ⇒ Object
Constructor Details
#initialize(name, ofx_uri, ofx_version, org_name, org_id, bank_id = nil, client_id = nil, ssl_version = nil) ⇒ FinancialInstitution
Returns a new instance of FinancialInstitution.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ofx/financial_institution.rb', line 74 def initialize(name, ofx_uri, ofx_version, org_name, org_id, bank_id=nil, client_id=nil, ssl_version=nil) @name = name @ofx_uri = ofx_uri @ofx_version = ofx_version @organization_name = org_name @organization_id = org_id @bank_identifier = bank_id @client = nil @ofx_client_id = client_id @ofx_ssl_version = ssl_version end |
Instance Attribute Details
#bank_identifier ⇒ Object (readonly)
Returns the value of attribute bank_identifier.
71 72 73 |
# File 'lib/ofx/financial_institution.rb', line 71 def bank_identifier @bank_identifier end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
72 73 74 |
# File 'lib/ofx/financial_institution.rb', line 72 def client @client end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
66 67 68 |
# File 'lib/ofx/financial_institution.rb', line 66 def name @name end |
#ofx_uri ⇒ Object (readonly)
Returns the value of attribute ofx_uri.
67 68 69 |
# File 'lib/ofx/financial_institution.rb', line 67 def ofx_uri @ofx_uri end |
#ofx_version ⇒ Object (readonly)
Returns the value of attribute ofx_version.
68 69 70 |
# File 'lib/ofx/financial_institution.rb', line 68 def ofx_version @ofx_version end |
#organization_id ⇒ Object (readonly)
Returns the value of attribute organization_id.
70 71 72 |
# File 'lib/ofx/financial_institution.rb', line 70 def organization_id @organization_id end |
#organization_name ⇒ Object (readonly)
Returns the value of attribute organization_name.
69 70 71 |
# File 'lib/ofx/financial_institution.rb', line 69 def organization_name @organization_name end |
Class Method Details
.get_institution(financial_institution_name, ofx_client_id = nil, ssl_version = nil) ⇒ Object
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/ofx/financial_institution.rb', line 23 def self.get_institution(financial_institution_name, ofx_client_id=nil, ssl_version=nil) case financial_institution_name when 'Capital One' FinancialInstitution.new('Capital One', URI.parse('https://onlinebanking.capitalone.com/ofx/process.ofx'), OFX::Version.new("1.0.2"), 'Hibernia', '1001', '065002030', ofx_client_id, ssl_version) when 'Citi' FinancialInstitution.new('Citi', URI.parse('https://www.accountonline.com/cards/svc/CitiOfxManager.do'), OFX::Version.new("1.0.2"), 'Citigroup', '24909', nil, 'Quicken', ssl_version) when 'Chase' FinancialInstitution.new('Chase', URI.parse('https://ofx.chase.com'), OFX::Version.new("1.0.3"), 'B1', '10898', nil, 'Quicken', :TLSv1) when 'AMEX' FinancialInstitution.new('AMEX', URI.parse('https://online.americanexpress.com/myca/ofxdl/desktop/desktopDownload.do?request_type=nl_ofxdownload'), OFX::Version.new("1.0.2"), 'AMEX', '3101', nil, 'Quicken', ssl_version) when 'Schwab' FinancialInstitution.new('Schwab', URI.parse('https://ofx.schwab.com/bankcgi_dev/ofx_server'), OFX::Version.new("1.0.2"), 'ISC', '101', '121202211', 'Quicken', ssl_version) when 'Fidelity' FinancialInstitution.new('Fidelity', URI.parse('https://ofx.fidelity.com/ftgw/OFX/clients/download'), OFX::Version.new("1.0.2"), 'fidelity.com', '7776', nil, 'Quicken', ssl_version) else raise NotImplementedError end end |
Instance Method Details
#create_request_document ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ofx/financial_institution.rb', line 104 def create_request_document() document = OFX::Document.new case ofx_version when OFX::Version.new("1.0.2") document.header.header_version = OFX::Version.new("1.0.0") document.header.content_type = "OFXSGML" document.header.document_version = OFX::Version.new("1.0.2") when OFX::Version.new("1.0.3") document.header.header_version = OFX::Version.new("1.0.0") document.header.content_type = "OFXSGML" document.header.document_version = OFX::Version.new("1.0.3") else raise NotImplementedError end document.header.security = "NONE" document.header.content_encoding = "USASCII" document.header.content_character_set = "1252" document.header.compression = "NONE" document.header.previous_unique_identifier = "NONE" document.header.unique_identifier = OFX::FileUniqueIdentifier.new document end |
#create_request_document_for_bank_statement(account_id, date_range = nil, account_type = :checking) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/ofx/financial_institution.rb', line 195 def create_request_document_for_bank_statement(account_id, date_range=nil, account_type = :checking) return nil if @client.nil? = OFX::BankingMessageSet.new statement_request = OFX::BankingStatementRequest.new statement_request.transaction_identifier = OFX::TransactionUniqueIdentifier.new statement_request.account = OFX::BankingAccount.new statement_request.account.bank_identifier = @bank_identifier statement_request.account.branch_identifier = nil statement_request.account.account_identifier = account_id statement_request.account.account_type = account_type statement_request.account.account_key = nil statement_request.include_transactions = true if date_range statement_request.included_range = date_range # example DateRange (start.to_date)..(end.to_date) .requests << statement_request requestDocument = self.create_request_document requestDocument. << @client.(@organization_id, @ofx_client_id) requestDocument. << return requestDocument end |
#create_request_document_for_cc_closing_statement(account_id) ⇒ Object
191 192 193 |
# File 'lib/ofx/financial_institution.rb', line 191 def create_request_document_for_cc_closing_statement(account_id) create_request_document_for_cc_statement(account_id, nil, false) end |
#create_request_document_for_cc_statement(account_id, date_range = nil, include_trans = true) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/ofx/financial_institution.rb', line 172 def create_request_document_for_cc_statement(account_id, date_range=nil, include_trans=true) return nil if @client.nil? = OFX::CreditCardStatementMessageSet.new statement_request = OFX::CreditCardStatementRequest.new statement_request.transaction_identifier = OFX::TransactionUniqueIdentifier.new statement_request.account = OFX::CreditCardAccount.new statement_request.account.account_identifier = account_id if include_trans statement_request.included_range = date_range statement_request.include_transactions = include_trans end .requests << statement_request requestDocument = self.create_request_document requestDocument. << @client.(@organization_id, @ofx_client_id) requestDocument. << return requestDocument end |
#create_request_document_for_inv_statement(account_id, date_range = nil) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/ofx/financial_institution.rb', line 216 def create_request_document_for_inv_statement(account_id, date_range=nil) return nil if @client.nil? = OFX::InvestmentStatementMessageSet.new statement_request = OFX::BankingStatementRequest.new statement_request.transaction_identifier = OFX::TransactionUniqueIdentifier.new statement_request.account = OFX::BankingAccount.new statement_request.account.bank_identifier = @bank_identifier statement_request.account.branch_identifier = nil statement_request.account.account_identifier = account_id statement_request.account.account_type = :money_market statement_request.account.account_key = nil statement_request.include_transactions = true if date_range statement_request.included_range = date_range .requests << statement_request requestDocument = self.create_request_document requestDocument. << @client.(@organization_id, @ofx_client_id) requestDocument. << return requestDocument end |
#create_request_document_profile_update(request_date = nil) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/ofx/financial_institution.rb', line 137 def create_request_document_profile_update(request_date=nil) return nil if @client.nil? if request_date.nil? request_date = DateTime.new(2001, 1, 1) end profileMessageSet = OFX::FinancialInstitutionProfileMessageSet.new profileRequest = OFX::FinancialInstitutionProfileRequest.new profileRequest.transaction_identifier = OFX::TransactionUniqueIdentifier.new profileRequest.client_routing = 'MSGSET' profileRequest.date_of_last_profile_update = request_date profileMessageSet.requests << profileRequest requestDocument = self.create_request_document requestDocument. << @client.(@organization_id, @ofx_client_id) requestDocument. << profileMessageSet return requestDocument end |
#create_request_document_signon ⇒ Object
130 131 132 133 134 135 |
# File 'lib/ofx/financial_institution.rb', line 130 def create_request_document_signon return nil if @client.nil? requestDocument = self.create_request_document requestDocument. << @client.(@organization_id, @ofx_client_id) return requestDocument end |
#create_request_document_signup(request_date = nil) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/ofx/financial_institution.rb', line 155 def create_request_document_signup(request_date=nil) return nil if @client.nil? if request_date.nil? request_date = DateTime.new(2001, 1, 1) end = OFX::SignupMessageSet.new account_info_request = OFX::AccountInformationRequest.new account_info_request.transaction_identifier = OFX::TransactionUniqueIdentifier.new account_info_request.date_of_last_account_update = request_date .requests << account_info_request requestDocument = self.create_request_document requestDocument. << @client.(@organization_id, @ofx_client_id) requestDocument. << return requestDocument end |
#document_to_post_data(document, no_whitespace = false) ⇒ Object
263 264 265 266 267 268 269 270 |
# File 'lib/ofx/financial_institution.rb', line 263 def document_to_post_data(document, no_whitespace=false) serializer = OFX::Serializer.get(@ofx_version) request_body = serializer.to_http_post_body(document) if no_whitespace request_body.delete! " " end return request_body end |
#get_account_id(account_id = nil) ⇒ Object
237 238 239 240 241 242 243 |
# File 'lib/ofx/financial_institution.rb', line 237 def get_account_id(account_id=nil) req = create_request_document_signup return nil if req.nil? resp = send(req) id = resp.[1].responses[0].account_identifier(account_id) if resp return id end |
#get_anon_profile ⇒ Object
Debugging routines
258 259 260 261 |
# File 'lib/ofx/financial_institution.rb', line 258 def get_anon_profile set_client_anon return send(create_request_document_profile_update) end |
#send(document) ⇒ Object
245 246 247 248 249 250 251 252 253 |
# File 'lib/ofx/financial_institution.rb', line 245 def send(document) serializer = OFX::Serializer.get(@ofx_version) request_body = serializer.to_http_post_body(document) client = OFX::HTTPClient.new(@ofx_uri) response_body = client.send(request_body, @ofx_ssl_version) return serializer.from_http_response_body(response_body) end |
#set_client(user_name, password, client_uid = nil) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ofx/financial_institution.rb', line 86 def set_client(user_name, password, client_uid=nil) inst_id = OFX::FinancialInstitutionIdentification.new( @organization_name, @organization_id) user_cred = OFX::UserCredentials.new(user_name, password) @client = OFX::FinancialClient.new([[inst_id, user_cred]]) # caller can generate one-time with: SecureRandom.hex(16) # see: http://wiki.gnucash.org/wiki/Setting_up_OFXDirectConnect_in_GnuCash_2#Chase_.22username_or_password_are_incorrect.22 @client.client_unique_identifier = client_uid @client end |
#set_client_anon ⇒ Object
anonymous can be used for ProfileRequest
98 99 100 101 102 |
# File 'lib/ofx/financial_institution.rb', line 98 def set_client_anon user_name = "anonymous00000000000000000000000" password = "anonymous00000000000000000000000" set_client(user_name, password) end |
#test_send(data, post_data = nil, serial_resp = true, debug_req = false, debug_resp = false) ⇒ Object
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/ofx/financial_institution.rb', line 272 def test_send(data, post_data=nil, serial_resp=true, debug_req=false, debug_resp=false) serializer = OFX::Serializer.get(@ofx_version) if post_data request_body = data else request_body = serializer.to_http_post_body(data) end client = OFX::HTTPClient.new(@ofx_uri) response_body = client.send(request_body, @ofx_ssl_version, debug_req, debug_resp) if serial_resp return serializer.from_http_response_body(response_body) else return response_body end end |