ofx-parser 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,87 @@
1
+ OFXHEADER:100
2
+ DATA:OFXSGML
3
+ VERSION:102
4
+ SECURITY:NONE
5
+ ENCODING:USASCII
6
+ CHARSET:1252
7
+ COMPRESSION:NONE
8
+ OLDFILEUID:NONE
9
+ NEWFILEUID:NONE
10
+
11
+ <OFX>
12
+ <SIGNONMSGSRSV1>
13
+ <SONRS>
14
+ <STATUS>
15
+ <CODE>0</CODE>
16
+ <SEVERITY>INFO</SEVERITY>
17
+ <MESSAGE>The user is authentic; operation succeeded.</MESSAGE>
18
+ </STATUS>
19
+ <DTSERVER>20070623142635.169[-5:CDT]</DTSERVER>
20
+ <LANGUAGE>ENG</LANGUAGE>
21
+ <FI>
22
+ <ORG>U.S. Bank</ORG>
23
+ <FID>1402</FID>
24
+ </FI>
25
+ <INTU.BID>1402</INTU.BID>
26
+ </SONRS>
27
+ </SIGNONMSGSRSV1>
28
+ <BANKMSGSRSV1>
29
+ <STMTTRNRS>
30
+ <TRNUID>9C24229A0077EAA50000011353C9E00743FC</TRNUID>
31
+ <STATUS>
32
+ <CODE>0</CODE>
33
+ <SEVERITY>INFO</SEVERITY>
34
+ </STATUS>
35
+ <STMTRS>
36
+ <CURDEF>USD</CURDEF>
37
+ <BANKACCTFROM>
38
+ <BANKID>033000033</BANKID>
39
+ <ACCTID>103333333333</ACCTID>
40
+ <ACCTTYPE>CHECKING</ACCTTYPE>
41
+ </BANKACCTFROM>
42
+ <BANKTRANLIST>
43
+ <DTSTART>20070604190000.000[-5:CDT]</DTSTART>
44
+ <DTEND>20070622190000.000[-5:CDT]</DTEND>
45
+ <STMTTRN>
46
+ <TRNTYPE>PAYMENT</TRNTYPE>
47
+ <DTPOSTED>20070606120000.000</DTPOSTED>
48
+ <TRNAMT>-11.11</TRNAMT>
49
+ <FITID>11111111 22</FITID>
50
+ <NAME>WEB AUTHORIZED PMT FOO INC</NAME>
51
+ <MEMO>Download from usbank.com. FOO INC</MEMO>
52
+ </STMTTRN>
53
+ <STMTTRN>
54
+ <TRNTYPE>CHECK</TRNTYPE>
55
+ <DTPOSTED>20070607120000.000</DTPOSTED>
56
+ <TRNAMT>-111.11</TRNAMT>
57
+ <FITID>22222A</FITID>
58
+ <CHECKNUM>0000009611</CHECKNUM>
59
+ <NAME>CHECK</NAME>
60
+ <MEMO>Download from usbank.com.</MEMO>
61
+ </STMTTRN>
62
+ <STMTTRN>
63
+ <TRNTYPE>DIRECTDEP</TRNTYPE>
64
+ <DTPOSTED>20070614120000.000</DTPOSTED>
65
+ <TRNAMT>1111.11</TRNAMT>
66
+ <FITID>X34AE33</FITID>
67
+ <NAME>ELECTRONIC DEPOSIT BAR INC</NAME>
68
+ <MEMO>Download from usbank.com. BAR INC</MEMO>
69
+ </STMTTRN>
70
+ <STMTTRN>
71
+ <TRNTYPE>CREDIT</TRNTYPE>
72
+ <DTPOSTED>20070619120000.000</DTPOSTED>
73
+ <TRNAMT>11.11</TRNAMT>
74
+ <FITID>8 8 9089743</FITID>
75
+ <NAME>ATM DEPOSIT US BANK ANYTOWNAS</NAME>
76
+ <MEMO>Download from usbank.com. US BANK ANYTOWN ASUS1</MEMO>
77
+ </STMTTRN>
78
+ </BANKTRANLIST>
79
+ <LEDGERBAL>
80
+ <BALAMT>1234.09</BALAMT>
81
+ <DTASOF>20070623142635.369[-5:CDT]</DTASOF>
82
+ </LEDGERBAL>
83
+ </STMTRS>
84
+ </STMTTRNRS>
85
+ </BANKMSGSRSV1>
86
+ </OFX>
87
+
@@ -0,0 +1,79 @@
1
+ OFXHEADER:100
2
+ DATA:OFXSGML
3
+ VERSION:102
4
+ SECURITY:NONE
5
+ ENCODING:USASCII
6
+ CHARSET:1252
7
+ COMPRESSION:NONE
8
+ OLDFILEUID:NONE
9
+ NEWFILEUID:NONE
10
+
11
+ <OFX>
12
+ <SIGNONMSGSRSV1>
13
+ <SONRS>
14
+ <STATUS>
15
+ <CODE>0</CODE>
16
+ <SEVERITY>INFO</SEVERITY>
17
+ </STATUS>
18
+ <DTSERVER>20070623192010</DTSERVER>
19
+ <LANGUAGE>ENG</LANGUAGE>
20
+ <FI>
21
+ <ORG>Citigroup</ORG>
22
+ <FID>24909</FID>
23
+ </FI>
24
+ <INTU.BID>24909</INTU.BID>
25
+ </SONRS>
26
+ </SIGNONMSGSRSV1>
27
+ <CREDITCARDMSGSRSV1>
28
+ <CCSTMTTRNRS>
29
+ <TRNUID>0</TRNUID>
30
+ <STATUS>
31
+ <CODE>0</CODE>
32
+ <SEVERITY>INFO</SEVERITY>
33
+ </STATUS>
34
+ <CCSTMTRS>
35
+ <CURDEF>USD</CURDEF>
36
+ <CCACCTFROM>
37
+ <ACCTID>XXXXXXXXXXXX1111</ACCTID>
38
+ </CCACCTFROM>
39
+ <BANKTRANLIST>
40
+ <DTSTART>20070509120000</DTSTART>
41
+ <DTEND>20070608120000</DTEND>
42
+ <STMTTRN>
43
+ <TRNTYPE>DEBIT</TRNTYPE>
44
+ <DTPOSTED>20070510170000</DTPOSTED>
45
+ <TRNAMT>-19.17</TRNAMT>
46
+ <FITID>xx</FITID>
47
+ <SIC>5912</SIC>
48
+ <NAME>WALGREEN 34638675 ANYTOWN</NAME>
49
+ </STMTTRN>
50
+ <STMTTRN>
51
+ <TRNTYPE>DEBIT</TRNTYPE>
52
+ <DTPOSTED>20070512170000</DTPOSTED>
53
+ <TRNAMT>-12.0</TRNAMT>
54
+ <FITID>yy-56</FITID>
55
+ <SIC>7933</SIC>
56
+ <NAME>SUNSET BOWL ANYTOWN</NAME>
57
+ </STMTTRN>
58
+ <STMTTRN>
59
+ <TRNTYPE>CREDIT</TRNTYPE>
60
+ <DTPOSTED>20070526170000</DTPOSTED>
61
+ <TRNAMT>11.01</TRNAMT>
62
+ <FITID>78-9</FITID>
63
+ <SIC>0000</SIC>
64
+ <NAME>ELECTRONIC PAYMENT-THANK YOU</NAME>
65
+ </STMTTRN>
66
+ </BANKTRANLIST>
67
+ <LEDGERBAL>
68
+ <BALAMT>-1111.01</BALAMT>
69
+ <DTASOF>20070623192013</DTASOF>
70
+ </LEDGERBAL>
71
+ <AVAILBAL>
72
+ <BALAMT>19000.99</BALAMT>
73
+ <DTASOF>20070623192013</DTASOF>
74
+ </AVAILBAL>
75
+ </CCSTMTRS>
76
+ </CCSTMTTRNRS>
77
+ </CREDITCARDMSGSRSV1>
78
+ </OFX>
79
+
@@ -0,0 +1,28 @@
1
+ OFXHEADER:100
2
+ DATA:OFXSGML
3
+ VERSION:102
4
+ SECURITY:NONE
5
+ ENCODING:USASCII
6
+ CHARSET:1252
7
+ COMPRESSION:NONE
8
+ OLDFILEUID:NONE
9
+ NEWFILEUID:NONE
10
+
11
+ <OFX>
12
+ <SIGNONMSGSRSV1>
13
+ <SONRS>
14
+ <STATUS>
15
+ <CODE> 0
16
+ <SEVERITY> INFO
17
+ <MESSAGE> The user is authentic; operation succeeded.
18
+ </STATUS>
19
+ <DTSERVER> 20070623142635.169[-5:CDT]
20
+ <LANGUAGE>ENG
21
+ <FI>
22
+ <ORG> U.S. Bank
23
+ <FID> 1402
24
+ </FI>
25
+ <INTU.BID>1402
26
+ </SONRS>
27
+ </SIGNONMSGSRSV1>
28
+ </OFX>
@@ -0,0 +1,244 @@
1
+ require 'test/unit'
2
+ require 'ofx-parser'
3
+
4
+ class OfxParserTest < Test::Unit::TestCase
5
+
6
+ OFX_FILES = {}
7
+
8
+ fixtures_dir = File.dirname(__FILE__) + '/fixtures'
9
+
10
+ # Load up the xml files
11
+ Dir.open(fixtures_dir).each do |fn|
12
+ next unless fn =~ /\.ofx\.sgml$/
13
+ OFX_FILES[fn.scan(/^[^.]*/).to_s.to_sym] = File.read(fixtures_dir + "/#{fn}")
14
+ end
15
+
16
+ def setup
17
+ # empty ofx parser - useful for testing other methods independently
18
+ @parser = OfxParser::OfxParser
19
+ end
20
+
21
+ def test_pre_process_strips_spaces
22
+ header, body = @parser.pre_process(OFX_FILES[:with_spaces])
23
+
24
+ assert_no_match(/>\s+.*?</, body, "should be no spaces after a tag close")
25
+ assert_no_match(/>.*?\s+</, body, "should be no spaces before a tag close")
26
+ assert_no_match(/>\s+</, body, "should be no spaces between two tags")
27
+ assert_match("The user is authentic; operation succeeded.", body, "content in tags should not be altered")
28
+ end
29
+
30
+ def test_pre_process_header
31
+ header, body = @parser.pre_process(OFX_FILES[:with_spaces])
32
+
33
+ assert_equal 9, header.keys.size
34
+ end
35
+
36
+ def test_parse_datetime
37
+ assert_equal DateTime.civil(2007, 6, 22, 19, 0, 0, Rational(-5,24)), @parser.parse_datetime('20070622190000.200[-5:CDT]')
38
+ assert_equal DateTime.civil(2007, 6, 22), @parser.parse_datetime('20070622')
39
+ assert_equal DateTime.civil(2007, 6, 22, 19, 0, 0), @parser.parse_datetime('20070622190000')
40
+ assert_equal DateTime.civil(2007, 6, 22, 19, 0, 0), @parser.parse_datetime('20070622190000.200')
41
+ end
42
+
43
+ def test_sign_on
44
+ ofx = OfxParser::OfxParser.parse(OFX_FILES[:with_spaces])
45
+
46
+ assert_equal '0', ofx.sign_on.status.code
47
+ assert_equal 'INFO', ofx.sign_on.status.severity
48
+ assert_equal 'The user is authentic; operation succeeded.', ofx.sign_on.status.message
49
+ assert_equal 'Success', ofx.sign_on.status.code_desc
50
+
51
+ assert_equal DateTime.civil(2007,6,23,14,26,35,Rational(-5, 24)), ofx.sign_on.date
52
+ assert_equal 'ENG', ofx.sign_on.language
53
+ assert_equal 'U.S. Bank', ofx.sign_on.institute.name
54
+ assert_equal '1402', ofx.sign_on.institute.id
55
+ end
56
+
57
+ def test_no_accounts
58
+ ofx = OfxParser::OfxParser.parse(OFX_FILES[:with_spaces])
59
+
60
+ assert_equal 0, ofx.accounts.size
61
+ end
62
+
63
+ def test_banking
64
+ ofx = OfxParser::OfxParser.parse(OFX_FILES[:banking])
65
+
66
+ acct = ofx.bank_account
67
+
68
+ assert_equal '103333333333', acct.number
69
+ assert_equal '033000033', acct.routing_number
70
+ assert_equal :CHECKING, acct.type
71
+ assert_equal '1234.09', acct.balance
72
+ assert_equal 123409, acct.balance_in_pennies
73
+ assert_equal DateTime.civil(2007,6,23,14,26,35,Rational(-5, 24)), acct.balance_date
74
+ assert_equal '9C24229A0077EAA50000011353C9E00743FC', acct.transaction_uid
75
+
76
+ statement = acct.statement
77
+
78
+ assert_equal 'USD', statement.currency
79
+ assert_equal DateTime.civil(2007,6,4,19,0,0,Rational(-5, 24)), statement.start_date
80
+ assert_equal DateTime.civil(2007,6,22,19,0,0,Rational(-5, 24)), statement.end_date
81
+
82
+ transactions = statement.transactions
83
+ assert_equal 4, transactions.size
84
+
85
+ assert_equal :PAYMENT, transactions[0].type
86
+ assert_equal OfxParser::Transaction::TYPE[:PAYMENT], transactions[0].type_desc
87
+ assert_equal DateTime.civil(2007,6,6,12,0,0), transactions[0].date
88
+ assert_equal '-11.11', transactions[0].amount
89
+ assert_equal -1111, transactions[0].amount_in_pennies
90
+ assert_equal '11111111 22', transactions[0].fit_id
91
+ assert_equal nil, transactions[0].check_number
92
+ assert_equal nil, transactions[0].sic
93
+ assert_equal nil, transactions[0].sic_desc
94
+ assert_equal 'WEB AUTHORIZED PMT FOO INC', transactions[0].payee
95
+ assert_equal 'Download from usbank.com. FOO INC', transactions[0].memo
96
+
97
+ assert_equal :CHECK, transactions[1].type
98
+ assert_equal OfxParser::Transaction::TYPE[:CHECK], transactions[1].type_desc
99
+ assert_equal DateTime.civil(2007,6,7,12,0,0), transactions[1].date
100
+ assert_equal '-111.11', transactions[1].amount
101
+ assert_equal -11111, transactions[1].amount_in_pennies
102
+ assert_equal '22222A', transactions[1].fit_id
103
+ assert_equal '0000009611', transactions[1].check_number
104
+ assert_equal nil, transactions[1].sic
105
+ assert_equal nil, transactions[1].sic_desc
106
+ assert_equal 'CHECK', transactions[1].payee
107
+ assert_equal 'Download from usbank.com.', transactions[1].memo
108
+
109
+ assert_equal :DIRECTDEP, transactions[2].type
110
+ assert_equal OfxParser::Transaction::TYPE[:DIRECTDEP], transactions[2].type_desc
111
+ assert_equal DateTime.civil(2007,6,14,12,0,0), transactions[2].date
112
+ assert_equal '1111.11', transactions[2].amount
113
+ assert_equal 111111, transactions[2].amount_in_pennies
114
+ assert_equal 'X34AE33', transactions[2].fit_id
115
+ assert_equal nil, transactions[2].check_number
116
+ assert_equal nil, transactions[2].sic
117
+ assert_equal nil, transactions[2].sic_desc
118
+ assert_equal 'ELECTRONIC DEPOSIT BAR INC', transactions[2].payee
119
+ assert_equal 'Download from usbank.com. BAR INC', transactions[2].memo
120
+
121
+ assert_equal :CREDIT, transactions[3].type
122
+ assert_equal OfxParser::Transaction::TYPE[:CREDIT], transactions[3].type_desc
123
+ assert_equal DateTime.civil(2007,6,19,12,0,0), transactions[3].date
124
+ assert_equal '11.11', transactions[3].amount
125
+ assert_equal 1111, transactions[3].amount_in_pennies
126
+ assert_equal '8 8 9089743', transactions[3].fit_id
127
+ assert_equal nil, transactions[3].check_number
128
+ assert_equal nil, transactions[3].sic
129
+ assert_equal nil, transactions[3].sic_desc
130
+ assert_equal 'ATM DEPOSIT US BANK ANYTOWNAS', transactions[3].payee
131
+ assert_equal 'Download from usbank.com. US BANK ANYTOWN ASUS1', transactions[3].memo
132
+
133
+ assert_equal 1, ofx.accounts.size
134
+ end
135
+
136
+ def test_creditcard
137
+ ofx = OfxParser::OfxParser.parse(OFX_FILES[:creditcard])
138
+
139
+ acct = ofx.credit_card
140
+
141
+ assert_equal 'XXXXXXXXXXXX1111', acct.number
142
+ assert_equal '19000.99', acct.remaining_credit
143
+ assert_equal 1900099, acct.remaining_credit_in_pennies
144
+ assert_equal DateTime.civil(2007,6,23,19,20,13), acct.remaining_credit_date
145
+ assert_equal '-1111.01', acct.balance
146
+ assert_equal -111101, acct.balance_in_pennies
147
+ assert_equal DateTime.civil(2007,6,23,19,20,13), acct.balance_date
148
+ assert_equal '0', acct.transaction_uid
149
+
150
+ statement = acct.statement
151
+
152
+ assert_equal 'USD', statement.currency
153
+ assert_equal DateTime.civil(2007,5,9,12,0,0), statement.start_date
154
+ assert_equal DateTime.civil(2007,6,8,12,0,0), statement.end_date
155
+
156
+ transactions = statement.transactions
157
+ assert_equal 3, transactions.size
158
+
159
+ assert_equal :DEBIT, transactions[0].type
160
+ assert_equal OfxParser::Transaction::TYPE[:DEBIT], transactions[0].type_desc
161
+ assert_equal DateTime.civil(2007,5,10,17,0,0), transactions[0].date
162
+ assert_equal '-19.17', transactions[0].amount
163
+ assert_equal -1917, transactions[0].amount_in_pennies
164
+ assert_equal 'xx', transactions[0].fit_id
165
+ assert_equal nil, transactions[0].check_number
166
+ assert_equal '5912', transactions[0].sic
167
+ assert_equal OfxParser::Sic::CODES['5912'], transactions[0].sic_desc
168
+ assert_equal 'WALGREEN 34638675 ANYTOWN', transactions[0].payee
169
+ assert_equal '', transactions[0].memo
170
+
171
+ assert_equal :DEBIT, transactions[1].type
172
+ assert_equal OfxParser::Transaction::TYPE[:DEBIT], transactions[1].type_desc
173
+ assert_equal DateTime.civil(2007,5,12,17,0,0), transactions[1].date
174
+ assert_equal '-12.0', transactions[1].amount
175
+ assert_equal -1200, transactions[1].amount_in_pennies
176
+ assert_equal 'yy-56', transactions[1].fit_id
177
+ assert_equal nil, transactions[1].check_number
178
+ assert_equal '7933', transactions[1].sic
179
+ assert_equal OfxParser::Sic::CODES['7933'], transactions[1].sic_desc
180
+ assert_equal 'SUNSET BOWL ANYTOWN', transactions[1].payee
181
+ assert_equal '', transactions[1].memo
182
+
183
+ assert_equal :CREDIT, transactions[2].type
184
+ assert_equal OfxParser::Transaction::TYPE[:CREDIT], transactions[2].type_desc
185
+ assert_equal DateTime.civil(2007,5,26,17,0,0), transactions[2].date
186
+ assert_equal '11.01', transactions[2].amount
187
+ assert_equal 1101, transactions[2].amount_in_pennies
188
+ assert_equal '78-9', transactions[2].fit_id
189
+ assert_equal nil, transactions[2].check_number
190
+ assert_equal '0000', transactions[2].sic
191
+ assert_equal nil, transactions[2].sic_desc
192
+ assert_equal 'ELECTRONIC PAYMENT-THANK YOU', transactions[2].payee
193
+ assert_equal '', transactions[2].memo
194
+
195
+ assert_equal 1, ofx.accounts.size
196
+ end
197
+
198
+ def test_monetary_support_call
199
+ t = OfxParser::Transaction.new
200
+ t.amount = '-11.1'
201
+
202
+ assert_nothing_raised { t.amount_in_pennies }
203
+ assert_raise(NoMethodError) { t.amount_in_whatever }
204
+
205
+ assert t.respond_to?(:amount_in_pennies)
206
+ assert !t.respond_to?(:amount_in_whatever)
207
+
208
+
209
+ end
210
+
211
+ class X
212
+ include OfxParser::MonetarySupport
213
+ attr_accessor :amount
214
+ monetary_vars :amount
215
+ end
216
+
217
+ def test_original_method
218
+ x = X.new
219
+ assert_equal :a_b, x.original_method('a_b_in_pennies')
220
+ assert_equal :a, x.original_method('a_in_pennies')
221
+ end
222
+
223
+ def test_for_pennies
224
+ amounts = {
225
+ '-11.1' => -111,
226
+ '-11.110' => -1111,
227
+ '-11.11101' => -1111,
228
+ '11.11' => 1111,
229
+ '11,11' => 1111,
230
+ '1' => 100,
231
+ '1.0' => 100,
232
+ '-1.0' => -100,
233
+ '' => nil
234
+ }
235
+
236
+ x = X.new
237
+
238
+ amounts.each do |actual, expected|
239
+ x.amount = actual
240
+ assert_equal expected, x.amount_in_pennies, "#{actual.inspect} should give #{expected.inspect}"
241
+ end
242
+ end
243
+
244
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: ofx-parser
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2007-06-26 00:00:00 -07:00
8
+ summary: ofx-parser is a ruby library for parsing OFX 1.x data.
9
+ require_paths:
10
+ - lib
11
+ email: andy@tinnedfruit.org
12
+ homepage: http://ofx-parser.rubyforge.org/
13
+ rubyforge_project: ofx-parser
14
+ description: "== DESCRIPTION: ofx-parser is a ruby library to parse a realistic subset of the lengthy OFX 1.x specification. == FEATURES/PROBLEMS: * Reads OFX responses - i.e. those downloaded from financial institutions and puts it into a usable object graph. * Supports the 3 main message sets: banking, credit card and investment accounts, as well as the required 'sign on' set. * Knows about SIC codes - if your institution provides them. See http://www.eeoc.gov/stats/jobpat/siccodes.html * Monetary amounts can be retrieved either as a raw string, or in pennies. * Supports OFX timestamps."
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Andrew A. Smith
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - lib/class-extension.rb
37
+ - lib/ofx-parser.rb
38
+ - lib/ofx.rb
39
+ - lib/sic.rb
40
+ - test/fixtures/banking.ofx.sgml
41
+ - test/fixtures/creditcard.ofx.sgml
42
+ - test/fixtures/with_spaces.ofx.sgml
43
+ - test/test_ofx_parser.rb
44
+ test_files:
45
+ - test/test_ofx_parser.rb
46
+ rdoc_options:
47
+ - --main
48
+ - README.txt
49
+ extra_rdoc_files:
50
+ - History.txt
51
+ - Manifest.txt
52
+ - README.txt
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ requirements: []
58
+
59
+ dependencies:
60
+ - !ruby/object:Gem::Dependency
61
+ name: hpricot
62
+ version_requirement:
63
+ version_requirements: !ruby/object:Gem::Version::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0.6"
68
+ version:
69
+ - !ruby/object:Gem::Dependency
70
+ name: hoe
71
+ version_requirement:
72
+ version_requirements: !ruby/object:Gem::Version::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.2.1
77
+ version: