firstdirect 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +7 -13
- data/Rakefile +2 -0
- data/lib/firstdirect.rb +65 -6
- metadata +2 -2
data/README.txt
CHANGED
@@ -5,21 +5,15 @@ Internet banking with First Direct using Ruby.
|
|
5
5
|
A FirstDirect object will log into First Direct's website and create some
|
6
6
|
Account objects for each account listed on the first page after login.
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
* Downloading of credit card account statements "doesn't work".
|
13
|
-
|
14
|
-
firstdirect.rb:51:in `strip_js': undefined method `[]' for nil:NilClass (NoMethodError)
|
15
|
-
|
16
|
-
* Downloading statements for 'Everyday e-Saver' fails with "no date_form found".
|
17
|
-
|
18
|
-
* Downloading "Regular Saver" account information often returns 'rubbish':
|
19
|
-
|
20
|
-
data downloaded looks like rubbish: <!--Build:19.01.0004-
|
8
|
+
You can install +firstdirect+ using +gem+ (the gem is called 'firstdirect') or
|
9
|
+
{download it}[http://rubyforge.org/frs/?group_id=6595]
|
10
|
+
from from the
|
11
|
+
{Rubyforge project}[http://rubyforge.org/projects/firstdirec/].
|
21
12
|
|
13
|
+
See the FirstDirect module for further information.
|
22
14
|
|
23
15
|
== LICENSE
|
24
16
|
|
17
|
+
Copyright (c) Edward Speyer, 2008
|
18
|
+
|
25
19
|
This code is licensed under the terms of the GPL version 2.
|
data/Rakefile
CHANGED
data/lib/firstdirect.rb
CHANGED
@@ -26,6 +26,17 @@ Each Account has a name, number, and balance.
|
|
26
26
|
#=> 1st Account (10-20-30 10000000): £100.00
|
27
27
|
|
28
28
|
|
29
|
+
You can fetch an Account's recent activity (as parsed from the HTML of the
|
30
|
+
account page on the First Direct website) as a CSV string or an Array:
|
31
|
+
|
32
|
+
puts account.recent_statement_csv
|
33
|
+
#=> date,details,paid out,paid in,balance,?
|
34
|
+
# 08/07/2008,TROTTER R *FRS REGULAR SAVER,100.00,"",100.00,""
|
35
|
+
|
36
|
+
# Get an array instead:
|
37
|
+
account.recent_statement_array
|
38
|
+
|
39
|
+
|
29
40
|
An Account can also download statements in CSV format:
|
30
41
|
|
31
42
|
account.download
|
@@ -48,9 +59,11 @@ An Account can also download statements in CSV format:
|
|
48
59
|
# T100.00
|
49
60
|
|
50
61
|
|
62
|
+
Copyright (c) Edward Speyer, 2008
|
63
|
+
|
51
64
|
=end
|
52
65
|
class FirstDirect
|
53
|
-
VERSION = '0.
|
66
|
+
VERSION = '0.2'
|
54
67
|
|
55
68
|
require 'rubygems'
|
56
69
|
require 'mechanize'
|
@@ -220,13 +233,60 @@ class FirstDirect
|
|
220
233
|
def to_s
|
221
234
|
"#{name} (#{number}): #{balance}"
|
222
235
|
end
|
223
|
-
|
236
|
+
|
224
237
|
#
|
225
|
-
# Go to the
|
238
|
+
# Go to the recent-statement page for this account, which we'll need to do
|
226
239
|
# statement downloading.
|
227
240
|
#
|
228
|
-
|
229
|
-
|
241
|
+
# The page is cached -- if you want to force an update:
|
242
|
+
#
|
243
|
+
# account.page(:update => true)
|
244
|
+
#
|
245
|
+
#--
|
246
|
+
#
|
247
|
+
# This is a lazy accessor for @__page. Please don't use @__page directly!
|
248
|
+
# In fact, I think I'll rename it to @__page (from @page) to discourage
|
249
|
+
# such access!
|
250
|
+
#
|
251
|
+
def page(options={})
|
252
|
+
if @__page.nil? or options[:update]
|
253
|
+
trace('getting account page'){ @__page = parent.agent.get(link) }
|
254
|
+
end
|
255
|
+
@__page
|
256
|
+
end
|
257
|
+
|
258
|
+
#
|
259
|
+
# Parse a recent-statement from this Account's page.
|
260
|
+
#
|
261
|
+
def recent_statement_array
|
262
|
+
data = []
|
263
|
+
|
264
|
+
table = page.at('table.fdStatTable')
|
265
|
+
headings = (table / 'thead/tr/th').map{ |el| el.inner_text.strip }
|
266
|
+
data << headings
|
267
|
+
|
268
|
+
last_row_data = nil
|
269
|
+
(table / 'tbody/tr').each do |row|
|
270
|
+
row_data = (row / 'td').map{ |el| el.inner_text.strip }
|
271
|
+
row_data[0] = last_row_data[0] if row_data[0].empty? and last_row_data
|
272
|
+
last_row_data = row_data
|
273
|
+
data << row_data
|
274
|
+
end
|
275
|
+
|
276
|
+
return data
|
277
|
+
end
|
278
|
+
|
279
|
+
#
|
280
|
+
# Return the recent-statement in CSV format.
|
281
|
+
#
|
282
|
+
def recent_statement_csv
|
283
|
+
require 'csv'
|
284
|
+
string = ''
|
285
|
+
csv = CSV::Writer.create(string)
|
286
|
+
for row in recent_statement_array
|
287
|
+
csv << row
|
288
|
+
end
|
289
|
+
return string
|
230
290
|
end
|
231
291
|
|
232
292
|
#
|
@@ -354,7 +414,6 @@ class FirstDirect
|
|
354
414
|
row.at('td[1]/a[2]'),
|
355
415
|
row.at('td[3]/strong')
|
356
416
|
].map do |v|
|
357
|
-
require 'cgi'
|
358
417
|
v.inner_html.gsub(' ', ' ').strip.gsub('£', '£')
|
359
418
|
end
|
360
419
|
b.link = Helpers.strip_js( row.at('td[1]/a[1]') )
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firstdirect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.2"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edward Speyer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-07-
|
12
|
+
date: 2008-07-08 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|