coop_to_ofx 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/README.rdoc +38 -0
  2. data/Rakefile +141 -0
  3. data/bin/coop_to_ofx +60 -0
  4. data/lib/coop_scraper/base.rb +8 -0
  5. data/lib/coop_scraper/credit_card.rb +94 -0
  6. data/lib/coop_scraper/current_account.rb +92 -0
  7. data/lib/coop_scraper/version.rb +12 -0
  8. data/lib/coop_scraper.rb +2 -0
  9. data/lib/ofx/statement/base.rb +53 -0
  10. data/lib/ofx/statement/credit_card.rb +15 -0
  11. data/lib/ofx/statement/current_account.rb +14 -0
  12. data/lib/ofx/statement/output/base.rb +131 -0
  13. data/lib/ofx/statement/output/builder.rb +76 -0
  14. data/lib/ofx/statement/output/credit_card.rb +31 -0
  15. data/lib/ofx/statement/output/current_account.rb +29 -0
  16. data/lib/ofx/statement/transaction.rb +52 -0
  17. data/lib/ofx/statement.rb +3 -0
  18. data/lib/ofx.rb +1 -0
  19. data/spec/coop_scraper/base_spec.rb +15 -0
  20. data/spec/coop_scraper/credit_card_spec.rb +229 -0
  21. data/spec/coop_scraper/current_account_spec.rb +154 -0
  22. data/spec/fixtures/credit_card/cc_statement_fixture.html +927 -0
  23. data/spec/fixtures/credit_card/foreign_transaction_fixture.html +447 -0
  24. data/spec/fixtures/credit_card/interest_transaction_fixture.html +438 -0
  25. data/spec/fixtures/credit_card/maybe.txt +43 -0
  26. data/spec/fixtures/credit_card/merchandise_interest_fixture.html +0 -0
  27. data/spec/fixtures/credit_card/normal_transaction_fixture.html +439 -0
  28. data/spec/fixtures/credit_card/overlimit_charge_fixture.html +446 -0
  29. data/spec/fixtures/credit_card/payment_in_transaction_fixture.html +439 -0
  30. data/spec/fixtures/credit_card/simple_cc_statement.ofx +43 -0
  31. data/spec/fixtures/credit_card/statement_with_interest_line_fixture.html +452 -0
  32. data/spec/fixtures/current_account/cash_point_transaction_fixture.html +372 -0
  33. data/spec/fixtures/current_account/current_account_fixture.html +420 -0
  34. data/spec/fixtures/current_account/current_account_fixture.ofx +83 -0
  35. data/spec/fixtures/current_account/debit_interest_transaction_fixture.html +372 -0
  36. data/spec/fixtures/current_account/no_transactions_fixture.html +364 -0
  37. data/spec/fixtures/current_account/normal_transaction_fixture.html +372 -0
  38. data/spec/fixtures/current_account/payment_in_transaction_fixture.html +372 -0
  39. data/spec/fixtures/current_account/service_charge_transaction_fixture.html +372 -0
  40. data/spec/fixtures/current_account/transfer_transaction_fixture.html +372 -0
  41. data/spec/ofx/statement/base_spec.rb +116 -0
  42. data/spec/ofx/statement/credit_card_spec.rb +20 -0
  43. data/spec/ofx/statement/current_account_spec.rb +20 -0
  44. data/spec/ofx/statement/output/base_spec.rb +249 -0
  45. data/spec/ofx/statement/output/builder_spec.rb +38 -0
  46. data/spec/ofx/statement/output/credit_card_spec.rb +84 -0
  47. data/spec/ofx/statement/output/current_account_spec.rb +81 -0
  48. data/spec/ofx/statement/transaction_spec.rb +76 -0
  49. data/spec/spec.opts +2 -0
  50. data/spec/spec_helper.rb +36 -0
  51. metadata +172 -0
@@ -0,0 +1,372 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
+
3
+
4
+
5
+ <html>
6
+ <head>
7
+ <TITLE>The Co-operative Bank p.l.c.</TITLE>
8
+ <link rel="stylesheet" href="https://welcome27.co-operativebank.co.uk/CBIBSImages/theme/Master.css" type="text/css">
9
+ <META content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
10
+ <META http-equiv="Content-Type" content="no-cache">
11
+ <META http-equiv="Pragma" content="no-cache">
12
+ <META http-equiv="Expires" content="-1">
13
+ <META http-equiv="Pragma-directive" content="no-cache">
14
+ <META http-equiv="cache-directive" content="no-cache">
15
+ </head>
16
+
17
+
18
+
19
+ <body>
20
+ <table width="100%" cellpadding="0" cellspacing="0">
21
+ <tr>
22
+ <td>
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+ <table width="100%" cellpadding="0" border="0" cellspacing="0">
31
+ <tr>
32
+ <td class="pageheader" height="0" width="50%">&nbsp;</td>
33
+ <td class="pageheader" width="20%">&nbsp;</td>
34
+ <td class="pageheader" height="10" width="30%">&nbsp;</td>
35
+ </tr>
36
+ <tr>
37
+ <td class="pageheader" valign="TOP" width="50%"><img src="https://welcome27.co-operativebank.co.uk/CBIBSImages/images/coop_logo_top.gif" align="left" alt="Top of the co-operative bank logo"></td>
38
+ <TD class="pageheader" valign="baseline" align="left" width="20%">
39
+ <table border="0" cellspacing="0" cellpadding="0" width="100%"><!--Table is used for vertical alignment-->
40
+ <tr><td>&nbsp;</td></tr>
41
+ <tr>
42
+ <TD class="pageheader" valign="BOTTOM" align="right" width="100%" height="100%">
43
+ <a href="/CBIBSWeb/sidebar.do?action=logoff&amp;org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="Log Off" class="whiteLinks"><img src="https://welcome27.co-operativebank.co.uk/CBIBSImages/images/logoffbutton.gif" align="middle" alt="Log Off"></a>
44
+ </TD>
45
+ </tr>
46
+ </table>
47
+ </TD>
48
+
49
+ <TD class="pageheader" valign="baseline" align="left" width="35%">
50
+ <table border="0" cellspacing="0" cellpadding="0" width="100%"><!--Table is used for vertical alignment-->
51
+ <tr><td>&nbsp;</td></tr><!--Used for alignment-->
52
+ <tr>
53
+
54
+
55
+
56
+ <td class="pageheadernew" valign="baseline" width="22.5%"><a href="http://www.smile.co.uk/helppages/cbibs/statements/currentAccountPreviousStatements.htm" target="_blank" class="whiteLinks" title="New Help Window Opened">
57
+ <img src="https://welcome27.co-operativebank.co.uk/CBIBSImages/images/helpbutton.gif" align="left" alt="Help"></a></coop:HelpLinkTag>
58
+ </td>
59
+ <td class="pageheader" align="left" valign="baseline" width="77.5%"><a href="/CBIBSWeb/printstatementDomestic.do?org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="Printer Friendly Page" class="whiteLinks"><img src="https://welcome27.co-operativebank.co.uk/CBIBSImages/images/printbutton.gif" align="left" alt="Print"></a>
60
+ </td>
61
+
62
+
63
+
64
+ </tr>
65
+ </table>
66
+ </td>
67
+ </tr>
68
+ <tr align="left">
69
+ <td>
70
+ <table width="100%" border="0">
71
+ <tr>
72
+ <td align="left">&nbsp;&nbsp;</td>
73
+ <td align="left" valign="baseline" width="40%">Saturday 21 February 2009</td>
74
+ <td align="left" valign="baseline" width="60%"><span class="H4">MR M</span></td>
75
+ </tr>
76
+ <tr><td>&nbsp;</td></tr>
77
+ </table>
78
+ </td>
79
+ </tr>
80
+ </table>
81
+ </td>
82
+ </tr>
83
+ <tr valign="top" align="left">
84
+ <td class="sidebar" >
85
+ <table width="100%">
86
+ <tr valign="top" align="left">
87
+ <td width="20%" class="sidebar">
88
+
89
+
90
+
91
+
92
+
93
+
94
+ <table cellpadding="3" cellspacing="5" width="78%" border="0">
95
+ <tr>
96
+ <td valign="top" height="26"><br></td>
97
+ </tr>
98
+
99
+
100
+
101
+
102
+ <tr valign="top">
103
+ <td valign="top" class="sidebar">
104
+ <a href="/CBIBSWeb/backToAccountBalance.do?org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="Your Accounts" class="sidebar">Your Accounts</a>
105
+ </td>
106
+ </tr>
107
+
108
+
109
+
110
+
111
+ <tr valign="top">
112
+ <td valign="top" class="backgroundSelected">
113
+ <a href="/CBIBSWeb/prepareStatements.do?org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="Statements" class="sidebarSelected">Statements</a>
114
+ </td>
115
+ </tr>
116
+
117
+
118
+
119
+
120
+ <tr valign="top">
121
+ <td valign="top" class="sidebar">
122
+ <a href="/CBIBSWeb/billPaymentSummaryPrepare.do?org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="Pay Bills" class="sidebar">Pay Bills</a>
123
+ </td>
124
+ </tr>
125
+
126
+
127
+
128
+
129
+ <tr valign="top">
130
+ <td valign="top" class="sidebar">
131
+ <a href="/CBIBSWeb/standingOrderSummaryPrepare.do?org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="Standing Orders" class="sidebar">Standing Orders</a>
132
+ </td>
133
+ </tr>
134
+
135
+
136
+
137
+
138
+ <tr valign="top">
139
+ <td valign="top" class="sidebar">
140
+ <a href="/CBIBSWeb/fundsTransferSummaryPrepare.do?org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="Funds Transfers" class="sidebar">Funds Transfers</a>
141
+ </td>
142
+ </tr>
143
+
144
+
145
+
146
+
147
+ <tr valign="top">
148
+ <td valign="top" class="sidebar">
149
+ <a href="/CBIBSWeb/directDebitsSummaryPrepare.do?org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="Direct Debits" class="sidebar">Direct Debits</a>
150
+ </td>
151
+ </tr>
152
+
153
+
154
+
155
+
156
+ <tr valign="top">
157
+ <td valign="top" class="sidebar">
158
+ <a href="/CBIBSWeb/customerServicesSummary.do?org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="Customer Services" class="sidebar">Customer Services</a>
159
+ </td>
160
+ </tr>
161
+
162
+ <tr>
163
+ <td>&nbsp;</td>
164
+ </tr>
165
+ </table>
166
+ </td>
167
+ <td width="80%" class="sidebar" >
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+ <table width="100%" border="0" cellspacing="0" cellpadding="0">
176
+ <tr>
177
+ <td class="field"><span class="H2">Statement<br>
178
+ </span></td>
179
+ </tr>
180
+ </table>
181
+
182
+ <table cellpadding="0" cellspacing="0" border="0" width="100%">
183
+ <tr>
184
+ <td bgcolor="#000000"><img src="https://welcome27.co-operativebank.co.uk/CBIBSImages/images/spacer.gif" height="1" width="1" alt=""></td>
185
+ </tr>
186
+ </table>
187
+
188
+ <table width="95%" border="0" cellspacing="0" cellpadding="0">
189
+ <tbody>
190
+ <tr><td><br/></td></tr>
191
+ <tr>
192
+ <td class="field">
193
+ <h4>CURRENT ACCOUNT
194
+ 08-92-73&nbsp;
195
+ 12341234
196
+ </h4>
197
+ </td>
198
+ </tr>
199
+
200
+
201
+
202
+ <tr>
203
+ <td align="left">
204
+ <table cellpadding="0" cellspacing="0" border="0">
205
+ <tbody>
206
+ <tr>
207
+ <td class="field">Page 132</td>
208
+ <td align="right">Date&nbsp;03/10/2008</td>
209
+ </tr>
210
+ <tr>
211
+ <td colspan="2"><br/>
212
+ </td>
213
+ </tr>
214
+ <tr>
215
+ <td colspan="2" align="left">
216
+ <table align="left" cellpadding="0" cellspacing="0" border="1">
217
+
218
+ <thead>
219
+ <tr>
220
+ <th>Date</th>
221
+ <th>Transaction</th>
222
+ <th>Deposits</th>
223
+ <th>Withdrawals</th>
224
+ <th>Balance</th>
225
+ </tr>
226
+ </thead>
227
+ <tbody>
228
+
229
+ <tr>
230
+ <td class="dataRowL"> 29/09/2008 </td>
231
+ <td class="transData">BROUGHT FORWARD</td>
232
+ <td class="moneyData"> &nbsp;</td>
233
+ <td class="moneyData"> &nbsp;</td>
234
+ <td class="moneyData"> £94.75 CR </td>
235
+ </tr>
236
+
237
+ <tr>
238
+ <td class="dataRowL"> 11/08/2008 </td>
239
+ <td class="transData">TFR 92738812764600</td>
240
+ <td class="moneyData"> &nbsp; </td>
241
+ <td class="moneyData"> £9000.00 </td>
242
+ <td class="moneyData"> £52.88 CR </td>
243
+ </tr>
244
+
245
+ </tbody>
246
+
247
+ </table>
248
+ </td>
249
+ </tr>
250
+ <tr>
251
+ <td>&nbsp;</td>
252
+ </tr>
253
+ <tr>
254
+ <td colspan="2" align="right">
255
+
256
+ <a href="/CBIBSWeb/paginateDomesticStatement.do?paginate=next&amp;org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="next"><span class="bodyhighlight">next</span></a>
257
+
258
+ &nbsp; &nbsp;
259
+ <a href="/CBIBSWeb/paginateDomesticStatement.do?paginate=previous&amp;org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="previous"><span class="bodyhighlight">previous</span></a>
260
+
261
+ </td>
262
+ </tr>
263
+
264
+ </tbody>
265
+ </table>
266
+ </td>
267
+ </tr>
268
+
269
+ </tbody>
270
+ </table>
271
+ <table width="95%" cellspacing="0" cellpadding="0">
272
+
273
+ <tr>
274
+ <td class="field" colspan="2"><br/>
275
+ To view Recent Items click <a href="/CBIBSWeb/domesticRecentItems.do?org.apache.struts.taglib.html.TOKEN=2c0802b4f70aa7e54a0319cac03b7672" title="Recent Items"><span class="bodyhighlight">Recent Items</span></a>.<br>
276
+ </td>
277
+ </tr>
278
+ <tr>
279
+ <td class="field" colspan="2"><BR> To select another service click the menu on the left. <BR><BR>
280
+ </td>
281
+ </tr>
282
+ <tr>
283
+ <td>&nbsp;</td>
284
+ </tr>
285
+ <tr>
286
+ <td colspan="2" align="left"> To view another account, please select from the list below </td>
287
+ </tr>
288
+ </table>
289
+ </td>
290
+ </tr>
291
+ <tr valign="top" align="left">
292
+ <td></td>
293
+ <td align="left">
294
+
295
+
296
+
297
+ <form name="viewAccountForm" method="post" action="/CBIBSWeb/prepareDomesticStatements.do"><input type="hidden" name="org.apache.struts.taglib.html.TOKEN" value="2c0802b4f70aa7e54a0319cac03b7672">
298
+ <table cellpadding="0" cellspacing="0" border="0">
299
+ <tr>
300
+ <td><label for="accounts" class="nodisplay">accounts</label></td>
301
+ </tr>
302
+ <tr valign="bottom">
303
+ <td class="field" width="56%">
304
+ <select name="selectedAccount" id="accounts">
305
+ <option value ="Select Account">Select Account</option>
306
+ <option value ="%0892738810381900">CURRENT ACCOUNT 089273 12341234</option>
307
+
308
+ </select>
309
+ </td>
310
+ <td class="field">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
311
+ <input type="image" name="VIEW" src="https://welcome27.co-operativebank.co.uk/CBIBSImages/images/viewbutton.gif" title="view account" alt="view">
312
+ </td>
313
+ </tr>
314
+ <tr>
315
+ <td class="error" colspan="2"></td>
316
+ </tr>
317
+ <tr>
318
+ <td colspan="2">&nbsp;</td>
319
+ </tr>
320
+
321
+
322
+
323
+
324
+ <tr>
325
+ <td colspan="2" align="left"><strong><font color="#216173">IBAN :</font></strong> GB65 CPBK 0892 7312 3412 34
326
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
327
+ <strong><font color="#216173">BIC :</font></strong> CPBK GB 22
328
+ </td>
329
+ </tr>
330
+
331
+
332
+
333
+ <tr>
334
+ <td colspan="2">&nbsp;</td>
335
+ </tr>
336
+
337
+
338
+
339
+
340
+
341
+ <tr>
342
+ <td colspan="2" align="left">For details of charges for card transactions in any currency other than sterling click<a href="http://www.smile.co.uk/helppages/cbibs/foreigncardtransactions.html" target="_blank" class="whiteLinks" title="new help window opened">
343
+ <span class="bodyhighlight"> here</span></a>.</td>
344
+ </tr>
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+ </table>
358
+ </form>
359
+ </td>
360
+ </tr>
361
+ </table>
362
+ </td>
363
+ </tr>
364
+ <tr>
365
+ <td align="left"><table width="100%">
366
+ <tr><td/>
367
+ </tr>
368
+ </table></td>
369
+ </tr>
370
+ </table>
371
+ </body>
372
+ </html>
@@ -0,0 +1,116 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe OFX::Statement::Base do
4
+ describe "instances" do
5
+ before(:each) do
6
+ @statement = OFX::Statement::Base.new
7
+ end
8
+
9
+ describe "setting the data" do
10
+ describe "server response time" do
11
+ it "should allow the server response time to be set" do
12
+ t = Time.now
13
+
14
+ @statement.server_response_time = t
15
+ @statement.server_response_time.should == t
16
+ end
17
+
18
+ it "should default to Time.now if it's not set" do
19
+ t = Time.now
20
+ Time.expects(:now).returns(t)
21
+
22
+ @statement.server_response_time.should == t
23
+ end
24
+ end
25
+
26
+ describe "language" do
27
+ it "should allow the language to be set" do
28
+ @statement.language = "FR"
29
+ @statement.language.should == "FR"
30
+ end
31
+
32
+ it "should default to 'ENG' if not set" do
33
+ @statement.language.should == "ENG"
34
+ end
35
+ end
36
+
37
+ describe "currency" do
38
+ it "should allow the currency to be set" do
39
+ @statement.currency = 'USD'
40
+ @statement.currency.should == 'USD'
41
+ end
42
+
43
+ it "should default to 'GBP' if not set" do
44
+ @statement.currency.should == 'GBP'
45
+ end
46
+ end
47
+
48
+ it "should allow the account number to be set" do
49
+ @statement.account_number = '1234123412341234'
50
+ @statement.account_number.should == '1234123412341234'
51
+ end
52
+
53
+ it "should allow the statement's start date to be set" do
54
+ t = Time.now
55
+
56
+ @statement.start_date = t
57
+ @statement.start_date.should == t
58
+ end
59
+
60
+ it "should allow the statement's end date to be set" do
61
+ t = Time.now
62
+
63
+ @statement.end_date = t
64
+ @statement.end_date.should == t
65
+ end
66
+
67
+ it "should statement's date to be set" do
68
+ t = Time.now
69
+
70
+ @statement.date = t
71
+ @statement.date.should == t
72
+ end
73
+
74
+ it "should allow the statement's ledger balance to be set" do
75
+ @statement.ledger_balance = "150.56"
76
+ @statement.ledger_balance.should == "150.56"
77
+ end
78
+
79
+ describe "transactions" do
80
+ it "should allow transactions to be appended" do
81
+ mock_transaction = mock('Transaction')
82
+ mock_transaction.expects(:statement=).with(@statement)
83
+
84
+ @statement << mock_transaction
85
+ @statement.transactions.should == [mock_transaction]
86
+ end
87
+
88
+ it "should default to []" do
89
+ @statement.transactions.should == []
90
+ end
91
+
92
+ describe "generating FITIDs for transactions" do
93
+ it "should generate a FITID which is unique, even for identical transactions" do
94
+ @statement.date = Time.utc('2009', '3', '11')
95
+ transaction = OFX::Statement::Transaction.new("-350.00", Time.utc('2009','3','8'), 'TEST TRANSACTION')
96
+ transaction2 = OFX::Statement::Transaction.new("-350.00", Time.utc('2009','3','8'), 'TEST TRANSACTION')
97
+ @statement << transaction
98
+ @statement << transaction2
99
+
100
+ @statement.fitid_for(transaction).should_not == @statement.fitid_for(transaction2)
101
+ end
102
+
103
+ it "should generate FITIDs which meet the field requirements for OFX" do
104
+ @statement.date = Time.utc('2009', '3', '11')
105
+ transaction = OFX::Statement::Transaction.new("-350.00", Time.utc('2009','3','8'), 'TEST TRANSACTION')
106
+ @statement << transaction
107
+
108
+ fitid = @statement.fitid_for(transaction)
109
+ fitid.should match(/^[a-z0-9]+$/)
110
+ (fitid.length < 254).should be_true
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe OFX::Statement::CreditCard do
4
+ before(:each) do
5
+ @statement = OFX::Statement::CreditCard.new
6
+ end
7
+
8
+ describe "setting the data" do
9
+ it "should allow the statement's available credit amount to be set" do
10
+ @statement.available_credit = "150.56"
11
+ @statement.available_credit.should == "150.56"
12
+ end
13
+ end
14
+
15
+ describe "output" do
16
+ it "should use the right output generator" do
17
+ @statement.output.should == OFX::Statement::Output::CreditCard
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe OFX::Statement::CurrentAccount do
4
+ before(:each) do
5
+ @statement = OFX::Statement::CurrentAccount.new
6
+ end
7
+
8
+ describe "setting the data" do
9
+ it "should allow the statement's sort code to be set" do
10
+ @statement.sort_code = "089273"
11
+ @statement.sort_code.should == "089273"
12
+ end
13
+ end
14
+
15
+ describe "output" do
16
+ it "should use the right output generator" do
17
+ @statement.output.should == OFX::Statement::Output::CurrentAccount
18
+ end
19
+ end
20
+ end