natwest 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -10
- data/VERSION +1 -1
- data/bin/nw +12 -8
- data/lib/natwest.rb +23 -34
- metadata +34 -19
data/Rakefile
CHANGED
@@ -15,6 +15,7 @@ begin
|
|
15
15
|
gem.add_development_dependency "yard", ">= 0"
|
16
16
|
gem.add_dependency "highline", ">= 0"
|
17
17
|
gem.extra_rdoc_files = []
|
18
|
+
gem.rdoc_options = []
|
18
19
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
20
|
end
|
20
21
|
Jeweler::GemcutterTasks.new
|
@@ -22,16 +23,9 @@ rescue LoadError
|
|
22
23
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
24
|
end
|
24
25
|
|
25
|
-
require '
|
26
|
-
|
27
|
-
spec.
|
28
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
29
|
-
end
|
30
|
-
|
31
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
32
|
-
spec.libs << 'lib' << 'spec'
|
33
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
34
|
-
spec.rcov = true
|
26
|
+
require 'rspec/core/rake_task'
|
27
|
+
Rspec::Core::RakeTask.new do |spec|
|
28
|
+
spec.ruby_opts = '-r./spec/spec_helper'
|
35
29
|
end
|
36
30
|
|
37
31
|
task :spec => :check_dependencies
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/nw
CHANGED
@@ -26,14 +26,18 @@ credentials = YAML.load(File.read(CONFIG)) rescue {}
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
Natwest::
|
29
|
+
Natwest::Customer.new.tap do |nw|
|
30
30
|
nw.login credentials
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
nw.accounts.each do |acc|
|
32
|
+
puts '###'
|
33
|
+
puts "#{acc.name} [#{acc.number}; #{acc.sort_code}] " +
|
34
|
+
"balance: #{acc.balance}; available: #{acc.available}"
|
35
|
+
puts "\nRecent Transactions:"
|
36
|
+
acc.transactions.each do |trans|
|
37
|
+
amount = trans[:credit] ? "+#{trans[:credit]}" : "-#{trans[:debit]}"
|
38
|
+
puts "#{trans[:date]}: #{amount}"
|
39
|
+
puts "\t" + trans[:details]
|
40
|
+
end
|
41
|
+
puts
|
38
42
|
end
|
39
43
|
end
|
data/lib/natwest.rb
CHANGED
@@ -64,49 +64,38 @@ module Natwest
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
class
|
67
|
+
class Customer
|
68
68
|
include Login
|
69
69
|
NO_DETAILS = 'No further transaction details held'
|
70
70
|
attr_accessor :page
|
71
71
|
|
72
72
|
def initialize
|
73
|
-
@ua =
|
73
|
+
@ua = Mechanize.new {|ua| ua.user_agent_alias = 'Windows IE 7'}
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
def balance
|
94
|
-
meta_row.css('td')[3].inner_text
|
95
|
-
end
|
96
|
-
|
97
|
-
def available
|
98
|
-
meta_row.css('td')[4].inner_text
|
99
|
-
end
|
100
|
-
|
101
|
-
def recent_transactions
|
102
|
-
page.parser.css('table.InnerAccountTable > tbody > tr').map do |tr|
|
103
|
-
transaction = Hash[[:date, :details, :credit, :debit].
|
104
|
-
zip((cells = tr.css('td')).map(&:inner_text))]
|
105
|
-
unless (further = cells[1]['title']) == NO_DETAILS
|
106
|
-
transaction[:details] += " (#{further.squeeze(' ')})"
|
76
|
+
def accounts
|
77
|
+
page.parser.css('table.AccountTable > tbody > tr').each_slice(2).map do |meta, statement|
|
78
|
+
Account.new.tap do |acc|
|
79
|
+
acc.name = meta.at('td > span.AccountName').inner_text
|
80
|
+
acc.number = meta.at('td > span.AccountNumber').inner_text.gsub(/[^\d]/,'')
|
81
|
+
acc.sort_code = meta.at('td > span.SortCode').inner_text.gsub(/[^\d-]/,'')
|
82
|
+
acc.balance = meta.css('td')[-2].inner_text
|
83
|
+
acc.available = meta.css('td')[-1].inner_text
|
84
|
+
acc.transactions =
|
85
|
+
statement.css('table.InnerAccountTable > tbody > tr').map do |tr|
|
86
|
+
transaction = Hash[[:date, :details, :credit, :debit].
|
87
|
+
zip((cells = tr.css('td')).map(&:inner_text))]
|
88
|
+
unless (further = cells[1]['title']) == NO_DETAILS
|
89
|
+
transaction[:details] += " (#{further.squeeze(' ')})"
|
90
|
+
end
|
91
|
+
Hash[transaction.map{|k,v| [k, v == ' - ' ? nil : v]}]
|
92
|
+
end
|
107
93
|
end
|
108
|
-
Hash[transaction.map{|k,v| [k, v == ' - ' ? nil : v]}]
|
109
94
|
end
|
110
95
|
end
|
111
96
|
end
|
97
|
+
|
98
|
+
class Account
|
99
|
+
attr_accessor :name, :number, :sort_code, :balance, :available, :transactions
|
100
|
+
end
|
112
101
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: natwest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Run Paint Run Run
|
@@ -9,39 +14,47 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-05-05 00:00:00 +01:00
|
13
18
|
default_executable: nw
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
23
31
|
version: 1.2.9
|
24
|
-
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: yard
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
33
43
|
version: "0"
|
34
|
-
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
35
46
|
- !ruby/object:Gem::Dependency
|
36
47
|
name: highline
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
50
|
requirements:
|
41
51
|
- - ">="
|
42
52
|
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
43
55
|
version: "0"
|
44
|
-
|
56
|
+
type: :runtime
|
57
|
+
version_requirements: *id003
|
45
58
|
description: View balance and recent transactions of a Natwest account from the command line.
|
46
59
|
email: runrun@runpaint.org
|
47
60
|
executables:
|
@@ -67,26 +80,28 @@ homepage: http://github.com/runpaint/natwest
|
|
67
80
|
licenses: []
|
68
81
|
|
69
82
|
post_install_message:
|
70
|
-
rdoc_options:
|
71
|
-
|
83
|
+
rdoc_options: []
|
84
|
+
|
72
85
|
require_paths:
|
73
86
|
- lib
|
74
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
88
|
requirements:
|
76
89
|
- - ">="
|
77
90
|
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 0
|
78
93
|
version: "0"
|
79
|
-
version:
|
80
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
95
|
requirements:
|
82
96
|
- - ">="
|
83
97
|
- !ruby/object:Gem::Version
|
98
|
+
segments:
|
99
|
+
- 0
|
84
100
|
version: "0"
|
85
|
-
version:
|
86
101
|
requirements: []
|
87
102
|
|
88
103
|
rubyforge_project:
|
89
|
-
rubygems_version: 1.3.
|
104
|
+
rubygems_version: 1.3.6
|
90
105
|
signing_key:
|
91
106
|
specification_version: 3
|
92
107
|
summary: Rudimentary API for Natwest Online Banking
|