/
nw
executable file
·43 lines (38 loc) · 1.24 KB
/
nw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'natwest'
require 'highline/import'
CONFIG = File.expand_path("~/.natwest.yaml")
if File.exists?(CONFIG)
if File.world_readable?(CONFIG) or not File.owned?(CONFIG)
mode = File.stat(CONFIG).mode.to_s(8)
$stderr.puts "#{CONFIG}: Insecure permissions: #{mode}"
end
end
credentials = YAML.load(File.read(CONFIG)) rescue {}
['customer number', 'PIN', 'password'].each do |credential|
key = credential.tr(' ','_').downcase.to_sym
next if credentials.key?(key)
unless $stdin.tty? and $stdout.tty?
$stderr.puts "Can't prompt for credentials; STDIN or STDOUT is not a TTY"
exit(1)
end
credentials[key] = ask("Please enter your #{credential}:") do |q|
q.echo = false
end
end
Natwest::Customer.new.tap do |nw|
nw.login credentials
nw.accounts.each do |acc|
puts '###'
puts "#{acc.name} [#{acc.number}; #{acc.sort_code}] " +
"balance: #{acc.balance}; available: #{acc.available}"
puts "\nRecent Transactions:"
acc.transactions.each do |trans|
amount = trans[:credit] ? "+#{trans[:credit]}" : "-#{trans[:debit]}"
puts "#{trans[:date]}: #{amount}"
puts "\t" + trans[:details]
end
puts
end
end