syrup 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -7
- data/.rspec +2 -2
- data/CHANGELOG.rdoc +8 -2
- data/Gemfile +4 -4
- data/README.rdoc +46 -46
- data/Rakefile +8 -8
- data/TODO.rdoc +12 -12
- data/lib/syrup/account.rb +142 -143
- data/lib/syrup/information_missing_error.rb +8 -8
- data/lib/syrup/institutions/institution_base.rb +142 -142
- data/lib/syrup/institutions/uccu.rb +135 -0
- data/lib/syrup/institutions/zions_bank.rb +175 -175
- data/lib/syrup/transaction.rb +19 -19
- data/lib/syrup/version.rb +3 -3
- data/lib/syrup.rb +46 -46
- data/spec/spec_helper.rb +15 -15
- data/spec/syrup/account_spec.rb +52 -52
- data/spec/syrup/institutions/institution_base_spec.rb +119 -119
- data/spec/syrup/institutions/uccu_spec.rb +45 -0
- data/spec/syrup/institutions/zions_bank_spec.rb +40 -40
- data/spec/syrup/syrup_spec.rb +40 -40
- data/spec/syrup/transaction_spec.rb +20 -20
- data/syrup.gemspec +26 -26
- metadata +60 -42
@@ -1,120 +1,120 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
include Institutions
|
4
|
-
|
5
|
-
describe InstitutionBase do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@institution = InstitutionBase.new
|
9
|
-
@institution.stub(:fetch_accounts) do
|
10
|
-
[Account.new(:id => 1, :name => 'first')]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
it "keeps a list of classes that extend it" do
|
15
|
-
InstitutionBase.subclasses.should include(ZionsBank)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "can be setup" do
|
19
|
-
institution = InstitutionBase.new
|
20
|
-
institution.setup do |config|
|
21
|
-
config.username = 'username'
|
22
|
-
config.password = 'pass'
|
23
|
-
config.secret_questions = { 'Do you like candy?' => 'yes' }
|
24
|
-
end
|
25
|
-
|
26
|
-
institution.username.should == 'username'
|
27
|
-
institution.password.should == 'pass'
|
28
|
-
institution.secret_questions['Do you like candy?'].should == 'yes'
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when accounts are NOT populated" do
|
32
|
-
it "fetches them when accessed" do
|
33
|
-
@institution.should_receive :fetch_accounts
|
34
|
-
@institution.accounts
|
35
|
-
end
|
36
|
-
|
37
|
-
it "returns an account with the id populated" do
|
38
|
-
account = @institution.find_account_by_id 21
|
39
|
-
account.id.should == 21
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns a previously created account if one exists" do
|
43
|
-
original_account = @institution.find_account_by_id 3
|
44
|
-
different_account = Account.new(:id => 3)
|
45
|
-
|
46
|
-
new_account = @institution.find_account_by_id 3
|
47
|
-
new_account.should be(original_account)
|
48
|
-
new_account.should_not be(different_account)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when accounts are populated" do
|
53
|
-
before(:each) do
|
54
|
-
@institution.populated = true
|
55
|
-
end
|
56
|
-
|
57
|
-
it "doesn't fetch them again" do
|
58
|
-
@institution.should_not_receive :fetch_accounts
|
59
|
-
@institution.accounts
|
60
|
-
end
|
61
|
-
|
62
|
-
it "returns nil if asked for a non-existent account" do
|
63
|
-
account = @institution.find_account_by_id 21
|
64
|
-
account.should be_nil
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
context "while populating accounts" do
|
70
|
-
it "filters out non-existent accounts" do
|
71
|
-
@institution.find_account_by_id 21
|
72
|
-
@institution.accounts.each do |a|
|
73
|
-
a.id.should_not be(21)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
it "populates data in existent accounts" do
|
78
|
-
account = @institution.find_account_by_id 1
|
79
|
-
@institution.populate_accounts
|
80
|
-
account.name.should == 'first'
|
81
|
-
end
|
82
|
-
|
83
|
-
it "marks accounts as populated" do
|
84
|
-
@institution.accounts.each do |account|
|
85
|
-
account.populated?.should be_true
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
it "marks invalid accounts as invalid" do
|
90
|
-
account = @institution.find_account_by_id 21
|
91
|
-
@institution.populate_accounts
|
92
|
-
account.valid?.should be_false
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "when asked to populate one account" do
|
97
|
-
it "populates one account" do
|
98
|
-
@institution.stub(:fetch_account) do
|
99
|
-
Account.new :id => 2, :name => 'single account'
|
100
|
-
end
|
101
|
-
|
102
|
-
account = @institution.populate_account(2)
|
103
|
-
account.name.should == 'single account'
|
104
|
-
account.populated?.should be_true
|
105
|
-
end
|
106
|
-
|
107
|
-
it "can populate all accounts" do
|
108
|
-
@institution.stub(:fetch_account) do
|
109
|
-
[Account.new(:id => 2, :name => 'single account')]
|
110
|
-
end
|
111
|
-
|
112
|
-
invalid_account = @institution.find_account_by_id 21
|
113
|
-
@institution.populate_account(2)
|
114
|
-
@institution.populated?.should be_true
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
# it "populates transactions"
|
119
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include Institutions
|
4
|
+
|
5
|
+
describe InstitutionBase do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@institution = InstitutionBase.new
|
9
|
+
@institution.stub(:fetch_accounts) do
|
10
|
+
[Account.new(:id => 1, :name => 'first')]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "keeps a list of classes that extend it" do
|
15
|
+
InstitutionBase.subclasses.should include(ZionsBank)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can be setup" do
|
19
|
+
institution = InstitutionBase.new
|
20
|
+
institution.setup do |config|
|
21
|
+
config.username = 'username'
|
22
|
+
config.password = 'pass'
|
23
|
+
config.secret_questions = { 'Do you like candy?' => 'yes' }
|
24
|
+
end
|
25
|
+
|
26
|
+
institution.username.should == 'username'
|
27
|
+
institution.password.should == 'pass'
|
28
|
+
institution.secret_questions['Do you like candy?'].should == 'yes'
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when accounts are NOT populated" do
|
32
|
+
it "fetches them when accessed" do
|
33
|
+
@institution.should_receive :fetch_accounts
|
34
|
+
@institution.accounts
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns an account with the id populated" do
|
38
|
+
account = @institution.find_account_by_id 21
|
39
|
+
account.id.should == 21
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns a previously created account if one exists" do
|
43
|
+
original_account = @institution.find_account_by_id 3
|
44
|
+
different_account = Account.new(:id => 3)
|
45
|
+
|
46
|
+
new_account = @institution.find_account_by_id 3
|
47
|
+
new_account.should be(original_account)
|
48
|
+
new_account.should_not be(different_account)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when accounts are populated" do
|
53
|
+
before(:each) do
|
54
|
+
@institution.populated = true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "doesn't fetch them again" do
|
58
|
+
@institution.should_not_receive :fetch_accounts
|
59
|
+
@institution.accounts
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns nil if asked for a non-existent account" do
|
63
|
+
account = @institution.find_account_by_id 21
|
64
|
+
account.should be_nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
context "while populating accounts" do
|
70
|
+
it "filters out non-existent accounts" do
|
71
|
+
@institution.find_account_by_id 21
|
72
|
+
@institution.accounts.each do |a|
|
73
|
+
a.id.should_not be(21)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "populates data in existent accounts" do
|
78
|
+
account = @institution.find_account_by_id 1
|
79
|
+
@institution.populate_accounts
|
80
|
+
account.name.should == 'first'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "marks accounts as populated" do
|
84
|
+
@institution.accounts.each do |account|
|
85
|
+
account.populated?.should be_true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "marks invalid accounts as invalid" do
|
90
|
+
account = @institution.find_account_by_id 21
|
91
|
+
@institution.populate_accounts
|
92
|
+
account.valid?.should be_false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when asked to populate one account" do
|
97
|
+
it "populates one account" do
|
98
|
+
@institution.stub(:fetch_account) do
|
99
|
+
Account.new :id => 2, :name => 'single account'
|
100
|
+
end
|
101
|
+
|
102
|
+
account = @institution.populate_account(2)
|
103
|
+
account.name.should == 'single account'
|
104
|
+
account.populated?.should be_true
|
105
|
+
end
|
106
|
+
|
107
|
+
it "can populate all accounts" do
|
108
|
+
@institution.stub(:fetch_account) do
|
109
|
+
[Account.new(:id => 2, :name => 'single account')]
|
110
|
+
end
|
111
|
+
|
112
|
+
invalid_account = @institution.find_account_by_id 21
|
113
|
+
@institution.populate_account(2)
|
114
|
+
@institution.populated?.should be_true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# it "populates transactions"
|
119
|
+
|
120
120
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include Institutions
|
4
|
+
|
5
|
+
describe Uccu, :bank_integration => true do
|
6
|
+
before(:each) do
|
7
|
+
@bank = Uccu.new
|
8
|
+
@bank.setup do |config|
|
9
|
+
config.username = ""
|
10
|
+
config.password = ""
|
11
|
+
config.secret_questions = {}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "fetches one account"
|
16
|
+
it "fetches all accounts" do
|
17
|
+
accounts = @bank.fetch_accounts
|
18
|
+
accounts.each do |account|
|
19
|
+
puts "#{account.id} #{account.name}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "fetches transactions given a date range" do
|
24
|
+
account_id = 1
|
25
|
+
|
26
|
+
account = @bank.find_account_by_id(account_id)
|
27
|
+
account.instance_variable_get(:@prior_day_balance).should be_nil
|
28
|
+
account.instance_variable_get(:@current_balance).should be_nil
|
29
|
+
account.instance_variable_get(:@available_balance).should be_nil
|
30
|
+
|
31
|
+
transactions = @bank.fetch_transactions(account_id, Date.today - 30, Date.today)
|
32
|
+
|
33
|
+
transactions.each do |t|
|
34
|
+
p t
|
35
|
+
end
|
36
|
+
|
37
|
+
puts account.prior_day_balance
|
38
|
+
puts account.current_balance
|
39
|
+
puts account.available_balance
|
40
|
+
|
41
|
+
account.prior_day_balance.should be_nil
|
42
|
+
account.current_balance.should_not be_nil
|
43
|
+
account.available_balance.should_not be_nil
|
44
|
+
end
|
45
|
+
end
|
@@ -1,41 +1,41 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
include Institutions
|
4
|
-
|
5
|
-
describe ZionsBank, :bank_integration => true do
|
6
|
-
before(:each) do
|
7
|
-
@bank = ZionsBank.new
|
8
|
-
@bank.setup do |config|
|
9
|
-
config.username = ""
|
10
|
-
config.password = ""
|
11
|
-
config.secret_questions = {}
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it "fetches one account"
|
16
|
-
it "fetches all accounts" do
|
17
|
-
accounts = @bank.fetch_accounts
|
18
|
-
accounts.each do |account|
|
19
|
-
puts "#{account.id} #{account.name}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it "fetches transactions given a date range" do
|
24
|
-
account_id = 1
|
25
|
-
|
26
|
-
account = @bank.find_account_by_id(account_id)
|
27
|
-
account.instance_variable_get(:@prior_day_balance).should be_nil
|
28
|
-
account.instance_variable_get(:@current_balance).should be_nil
|
29
|
-
account.instance_variable_get(:@available_balance).should be_nil
|
30
|
-
|
31
|
-
@bank.fetch_transactions(account_id, Date.today - 30, Date.today)
|
32
|
-
|
33
|
-
puts account.prior_day_balance
|
34
|
-
puts account.current_balance
|
35
|
-
puts account.available_balance
|
36
|
-
|
37
|
-
account.prior_day_balance.should_not be_nil
|
38
|
-
account.current_balance.should_not be_nil
|
39
|
-
account.available_balance.should_not be_nil
|
40
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include Institutions
|
4
|
+
|
5
|
+
describe ZionsBank, :bank_integration => true do
|
6
|
+
before(:each) do
|
7
|
+
@bank = ZionsBank.new
|
8
|
+
@bank.setup do |config|
|
9
|
+
config.username = ""
|
10
|
+
config.password = ""
|
11
|
+
config.secret_questions = {}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "fetches one account"
|
16
|
+
it "fetches all accounts" do
|
17
|
+
accounts = @bank.fetch_accounts
|
18
|
+
accounts.each do |account|
|
19
|
+
puts "#{account.id} #{account.name}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "fetches transactions given a date range" do
|
24
|
+
account_id = 1
|
25
|
+
|
26
|
+
account = @bank.find_account_by_id(account_id)
|
27
|
+
account.instance_variable_get(:@prior_day_balance).should be_nil
|
28
|
+
account.instance_variable_get(:@current_balance).should be_nil
|
29
|
+
account.instance_variable_get(:@available_balance).should be_nil
|
30
|
+
|
31
|
+
@bank.fetch_transactions(account_id, Date.today - 30, Date.today)
|
32
|
+
|
33
|
+
puts account.prior_day_balance
|
34
|
+
puts account.current_balance
|
35
|
+
puts account.available_balance
|
36
|
+
|
37
|
+
account.prior_day_balance.should_not be_nil
|
38
|
+
account.current_balance.should_not be_nil
|
39
|
+
account.available_balance.should_not be_nil
|
40
|
+
end
|
41
41
|
end
|
data/spec/syrup/syrup_spec.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Syrup do
|
4
|
-
it "lists all institutions" do
|
5
|
-
institution_list = Syrup.institutions
|
6
|
-
|
7
|
-
institution_list.size.should be(
|
8
|
-
|
9
|
-
institution_list.should include(Institutions::ZionsBank)
|
10
|
-
|
11
|
-
institution_list.each do |institution|
|
12
|
-
institution.should respond_to(:name)
|
13
|
-
institution.should respond_to(:id)
|
14
|
-
|
15
|
-
inst = institution.new
|
16
|
-
inst.should respond_to(:fetch_account)
|
17
|
-
inst.should respond_to(:fetch_accounts)
|
18
|
-
inst.should respond_to(:fetch_transactions)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns nil if you try to setup an unknown institution" do
|
23
|
-
Syrup.setup_institution('unknown').should be_nil
|
24
|
-
end
|
25
|
-
|
26
|
-
it "sets up a Zions Bank institution" do
|
27
|
-
username = "user"
|
28
|
-
password = "pass"
|
29
|
-
secret_questions = { 'Do you eat?' => 'yes' }
|
30
|
-
|
31
|
-
zions = Syrup.setup_institution('zions_bank') do |config|
|
32
|
-
config.username = username
|
33
|
-
config.password = password
|
34
|
-
config.secret_questions = secret_questions
|
35
|
-
end
|
36
|
-
|
37
|
-
zions.should_not be_nil
|
38
|
-
zions.class.should be(Syrup::Institutions::ZionsBank)
|
39
|
-
zions.username.should be(username)
|
40
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Syrup do
|
4
|
+
it "lists all institutions" do
|
5
|
+
institution_list = Syrup.institutions
|
6
|
+
|
7
|
+
institution_list.size.should be(2)
|
8
|
+
|
9
|
+
institution_list.should include(Institutions::ZionsBank)
|
10
|
+
|
11
|
+
institution_list.each do |institution|
|
12
|
+
institution.should respond_to(:name)
|
13
|
+
institution.should respond_to(:id)
|
14
|
+
|
15
|
+
inst = institution.new
|
16
|
+
inst.should respond_to(:fetch_account)
|
17
|
+
inst.should respond_to(:fetch_accounts)
|
18
|
+
inst.should respond_to(:fetch_transactions)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns nil if you try to setup an unknown institution" do
|
23
|
+
Syrup.setup_institution('unknown').should be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets up a Zions Bank institution" do
|
27
|
+
username = "user"
|
28
|
+
password = "pass"
|
29
|
+
secret_questions = { 'Do you eat?' => 'yes' }
|
30
|
+
|
31
|
+
zions = Syrup.setup_institution('zions_bank') do |config|
|
32
|
+
config.username = username
|
33
|
+
config.password = password
|
34
|
+
config.secret_questions = secret_questions
|
35
|
+
end
|
36
|
+
|
37
|
+
zions.should_not be_nil
|
38
|
+
zions.class.should be(Syrup::Institutions::ZionsBank)
|
39
|
+
zions.username.should be(username)
|
40
|
+
end
|
41
41
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Syrup::Transaction do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
@transaction = Transaction.new :amount => 10, :payee => "Newegg", :posted_at => DateTime.now
|
7
|
-
end
|
8
|
-
|
9
|
-
it "has an amount" do
|
10
|
-
@transaction.amount.should_not be_nil
|
11
|
-
end
|
12
|
-
|
13
|
-
it "has a payee" do
|
14
|
-
@transaction.payee.should_not be_nil
|
15
|
-
end
|
16
|
-
|
17
|
-
it "has a posted-at date" do
|
18
|
-
@transaction.posted_at.should_not be_nil
|
19
|
-
end
|
20
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Syrup::Transaction do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@transaction = Transaction.new :amount => 10, :payee => "Newegg", :posted_at => DateTime.now
|
7
|
+
end
|
8
|
+
|
9
|
+
it "has an amount" do
|
10
|
+
@transaction.amount.should_not be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has a payee" do
|
14
|
+
@transaction.payee.should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has a posted-at date" do
|
18
|
+
@transaction.posted_at.should_not be_nil
|
19
|
+
end
|
20
|
+
|
21
21
|
end
|
data/syrup.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "syrup/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "syrup"
|
7
|
-
s.version = Syrup::VERSION
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Don Wilson"]
|
10
|
-
s.email = ["dontangg@gmail.com"]
|
11
|
-
s.homepage = "http://github.com/dontangg/syrup"
|
12
|
-
s.summary = %q{Simple account balance and transactions extractor.}
|
13
|
-
s.description = %q{Simple account balance and transactions extractor by scraping bank websites.}
|
14
|
-
|
15
|
-
s.add_dependency "mechanize", ">= 1.0.0"
|
16
|
-
s.add_dependency "multi_json", ">= 1.0.3"
|
17
|
-
|
18
|
-
s.add_development_dependency "rspec", ">= 2.6.0"
|
19
|
-
|
20
|
-
s.rubyforge_project = s.name
|
21
|
-
|
22
|
-
s.files = `git ls-files`.split("\n")
|
23
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
-
s.require_paths = ["lib"]
|
26
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "syrup/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "syrup"
|
7
|
+
s.version = Syrup::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Don Wilson"]
|
10
|
+
s.email = ["dontangg@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/dontangg/syrup"
|
12
|
+
s.summary = %q{Simple account balance and transactions extractor.}
|
13
|
+
s.description = %q{Simple account balance and transactions extractor by scraping bank websites.}
|
14
|
+
|
15
|
+
s.add_dependency "mechanize", ">= 1.0.0"
|
16
|
+
s.add_dependency "multi_json", ">= 1.0.3"
|
17
|
+
|
18
|
+
s.add_development_dependency "rspec", ">= 2.6.0"
|
19
|
+
|
20
|
+
s.rubyforge_project = s.name
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
end
|