aggcat 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/aggcat/base.rb CHANGED
@@ -68,7 +68,7 @@ module Aggcat
68
68
  signed_info = %[<ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#_#{reference_id}"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>#{encoded_digest.strip}</ds:DigestValue></ds:Reference></ds:SignedInfo>]
69
69
  signature_value = Nokogiri::XML(signed_info).canonicalize
70
70
  key = OpenSSL::PKey::RSA.new(File.read(@certificate_path))
71
- encoded_signature_value = Base64.encode64(key.sign(OpenSSL::Digest::SHA1.new, signature_value)).gsub!(/\n/, '')
71
+ encoded_signature_value = Base64.encode64(key.sign(OpenSSL::Digest::SHA1.new, signature_value)).gsub(/\n/, '')
72
72
  Base64.encode64(assertion % [encoded_digest, encoded_signature_value])
73
73
  end
74
74
 
data/lib/aggcat/client.rb CHANGED
@@ -42,11 +42,11 @@ module Aggcat
42
42
 
43
43
  def account_transactions(account_id, start_date, end_date = nil)
44
44
  validate(account_id: account_id, start_date: start_date)
45
- uri = "/accounts/#{account_id}/transactions?txnStartDate=#{start_date.strftime(DATE_FORMAT)}"
45
+ path = "/accounts/#{account_id}/transactions?txnStartDate=#{start_date.strftime(DATE_FORMAT)}"
46
46
  if end_date
47
- uri += "&txnEndDate=#{end_date.strftime(DATE_FORMAT)}"
47
+ path += "&txnEndDate=#{end_date.strftime(DATE_FORMAT)}"
48
48
  end
49
- get(uri)
49
+ get(path)
50
50
  end
51
51
 
52
52
  def update_login(institution_id, login_id, username, password)
@@ -72,27 +72,27 @@ module Aggcat
72
72
 
73
73
  protected
74
74
 
75
- def get(uri, headers = {})
76
- request(:get, uri, headers)
75
+ def get(path, headers = {})
76
+ request(:get, path, headers)
77
77
  end
78
78
 
79
- def post(uri, body, headers = {})
80
- request(:post, uri, body, headers.merge({'Content-Type' => 'application/xml'}))
79
+ def post(path, body, headers = {})
80
+ request(:post, path, body, headers.merge({'Content-Type' => 'application/xml'}))
81
81
  end
82
82
 
83
- def put(uri, body, headers = {})
84
- request(:put, uri, body, headers.merge({'Content-Type' => 'application/xml'}))
83
+ def put(path, body, headers = {})
84
+ request(:put, path, body, headers.merge({'Content-Type' => 'application/xml'}))
85
85
  end
86
86
 
87
- def delete(uri, headers = {})
88
- request(:delete, uri, headers.merge({'Content-Type' => 'application/xml'}))
87
+ def delete(path, headers = {})
88
+ request(:delete, path, headers.merge({'Content-Type' => 'application/xml'}))
89
89
  end
90
90
 
91
91
  private
92
92
 
93
- def request(method, uri, *options)
94
- response = oauth_client.send(method.to_sym, BASE_URL + uri, *options)
95
- result = {:response_code => response.code, :response => parse_xml(response.body)}
93
+ def request(method, path, *options)
94
+ response = oauth_client.send(method.to_sym, BASE_URL + path, *options)
95
+ result = {:status_code => response.code, :result => parse_xml(response.body)}
96
96
  if response['challengeSessionId']
97
97
  result[:challenge_session_id] = response['challengeSessionId']
98
98
  result[:challenge_node_id] = response['challengeNodeId']
@@ -110,7 +110,7 @@ module Aggcat
110
110
 
111
111
  def credentials(institution_id, username, password)
112
112
  institution = institution(institution_id)
113
- keys = institution[:response][:institution_detail][:keys][:key].sort { |a, b| a[:display_order] <=> b[:display_order] }
113
+ keys = institution[:result][:institution_detail][:keys][:key].sort { |a, b| a[:display_order] <=> b[:display_order] }
114
114
  hash = {
115
115
  keys[0][:name] => username,
116
116
  keys[1][:name] => password
@@ -1,3 +1,3 @@
1
1
  module Aggcat
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -49,6 +49,6 @@ class AggcatTest < Test::Unit::TestCase
49
49
  Aggcat.scope('1')
50
50
  stub_get('/institutions').to_return(:body => fixture('institutions.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
51
51
  response = Aggcat.institutions
52
- assert_equal response[:response][:institutions][:institution][0][:institution_id].to_i, 100000
52
+ assert_equal response[:result][:institutions][:institution][0][:institution_id].to_i, 100000
53
53
  end
54
54
  end
@@ -17,22 +17,21 @@ class ClientTest < Test::Unit::TestCase
17
17
  def test_institutions
18
18
  stub_get('/institutions').to_return(:body => fixture('institutions.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
19
19
  response = @client.institutions
20
- assert_equal response[:response][:institutions][:institution][0][:institution_id].to_i, 100000
20
+ assert_equal response[:result][:institutions][:institution][0][:institution_id].to_i, 100000
21
21
  end
22
22
 
23
23
  def test_institution
24
24
  institution_id = '100000'
25
25
  stub_get("/institutions/#{institution_id}").to_return(:body => fixture('institution.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
26
26
  response = @client.institution(institution_id)
27
- assert_equal institution_id, response[:response][:institution_detail][:institution_id]
27
+ assert_equal institution_id, response[:result][:institution_detail][:institution_id]
28
28
  end
29
29
 
30
30
  def test_institution_with_bad_args
31
- exception = assert_raise(ArgumentError) { @client.institution(nil) }
32
- assert_equal('institution_id is required', exception.message)
33
-
34
- exception = assert_raise(ArgumentError) { @client.institution('') }
35
- assert_equal('institution_id is required', exception.message)
31
+ [nil, ''].each do |arg|
32
+ exception = assert_raise(ArgumentError) { @client.institution(arg) }
33
+ assert_equal('institution_id is required', exception.message)
34
+ end
36
35
  end
37
36
 
38
37
  def test_discover_and_add_accounts
@@ -40,8 +39,8 @@ class ClientTest < Test::Unit::TestCase
40
39
  stub_get("/institutions/#{institution_id}").to_return(:body => fixture('institution.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
41
40
  stub_post("/institutions/#{institution_id}/logins").to_return(:body => fixture('account.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
42
41
  response = @client.discover_and_add_accounts(institution_id, 'username', 'password')
43
- assert_equal institution_id, response[:response][:account_list][:banking_account][:institution_id]
44
- assert_equal '000000000001', response[:response][:account_list][:banking_account][:account_id]
42
+ assert_equal institution_id, response[:result][:account_list][:banking_account][:institution_id]
43
+ assert_equal '000000000001', response[:result][:account_list][:banking_account][:account_id]
45
44
  end
46
45
 
47
46
  def test_discover_and_add_accounts_with_challenge
@@ -49,50 +48,42 @@ class ClientTest < Test::Unit::TestCase
49
48
  stub_get("/institutions/#{institution_id}").to_return(:body => fixture('institution.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
50
49
  stub_post("/institutions/#{institution_id}/logins").to_return(:code => 401, :body => fixture('account.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
51
50
  response = @client.discover_and_add_accounts(institution_id, 'username', 'password')
52
- assert_equal institution_id, response[:response][:account_list][:banking_account][:institution_id]
53
- assert_equal '000000000001', response[:response][:account_list][:banking_account][:account_id]
51
+ assert_equal institution_id, response[:result][:account_list][:banking_account][:institution_id]
52
+ assert_equal '000000000001', response[:result][:account_list][:banking_account][:account_id]
54
53
  end
55
54
 
56
55
  def test_discover_and_add_accounts_bad_args
57
- exception = assert_raise(ArgumentError) { @client.discover_and_add_accounts(nil, 'username', 'password') }
58
- assert_equal('institution_id is required', exception.message)
59
-
60
- exception = assert_raise(ArgumentError) { @client.discover_and_add_accounts('', 'username', 'password') }
61
- assert_equal('institution_id is required', exception.message)
62
-
63
- exception = assert_raise(ArgumentError) { @client.discover_and_add_accounts(1, nil, 'password') }
64
- assert_equal('username is required', exception.message)
65
-
66
- exception = assert_raise(ArgumentError) { @client.discover_and_add_accounts(1, '', 'password') }
67
- assert_equal('username is required', exception.message)
56
+ [nil, ''].each do |arg|
57
+ exception = assert_raise(ArgumentError) { @client.discover_and_add_accounts(arg, 'username', 'password') }
58
+ assert_equal('institution_id is required', exception.message)
68
59
 
69
- exception = assert_raise(ArgumentError) { @client.discover_and_add_accounts(1, 'username', nil) }
70
- assert_equal('password is required', exception.message)
60
+ exception = assert_raise(ArgumentError) { @client.discover_and_add_accounts(1, arg, 'password') }
61
+ assert_equal('username is required', exception.message)
71
62
 
72
- exception = assert_raise(ArgumentError) { @client.discover_and_add_accounts(1, 'username', '') }
73
- assert_equal('password is required', exception.message)
63
+ exception = assert_raise(ArgumentError) { @client.discover_and_add_accounts(1, 'username', arg) }
64
+ assert_equal('password is required', exception.message)
65
+ end
74
66
  end
75
67
 
76
68
  def test_account
77
69
  account_id = '000000000001'
78
70
  stub_get("/accounts/#{account_id}").to_return(:body => fixture('account.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
79
71
  response = @client.account(account_id)
80
- assert_equal account_id, response[:response][:account_list][:banking_account][:account_id]
72
+ assert_equal account_id, response[:result][:account_list][:banking_account][:account_id]
81
73
  end
82
74
 
83
75
  def test_account_bad_args
84
- exception = assert_raise(ArgumentError) { @client.account(nil) }
85
- assert_equal('account_id is required', exception.message)
86
-
87
- exception = assert_raise(ArgumentError) { @client.account('') }
88
- assert_equal('account_id is required', exception.message)
76
+ [nil, ''].each do |arg|
77
+ exception = assert_raise(ArgumentError) { @client.account(arg) }
78
+ assert_equal('account_id is required', exception.message)
79
+ end
89
80
  end
90
81
 
91
82
  def test_accounts
92
83
  stub_get('/accounts').to_return(:body => fixture('accounts.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
93
84
  response = @client.accounts
94
- assert_equal '11111', response[:response][:account_list][:banking_account][0][:institution_id]
95
- assert_equal '75000033002', response[:response][:account_list][:banking_account][0][:account_id]
85
+ assert_equal '11111', response[:result][:account_list][:banking_account][0][:institution_id]
86
+ assert_equal '75000033002', response[:result][:account_list][:banking_account][0][:account_id]
96
87
  end
97
88
 
98
89
  def test_account_transactions
@@ -101,7 +92,7 @@ class ClientTest < Test::Unit::TestCase
101
92
  uri = "/accounts/#{account_id}/transactions?txnStartDate=#{start_date.strftime(Aggcat::Base::DATE_FORMAT)}"
102
93
  stub_get(uri).to_return(:body => fixture('transactions.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
103
94
  response = @client.account_transactions(account_id, start_date)
104
- assert_equal '75000088503', response[:response][:transaction_list][:credit_card_transaction][:id]
95
+ assert_equal '75000088503', response[:result][:transaction_list][:credit_card_transaction][:id]
105
96
  end
106
97
 
107
98
  def test_account_transactions_with_dates
@@ -113,44 +104,39 @@ class ClientTest < Test::Unit::TestCase
113
104
  uri = "/accounts/#{account_id}/transactions?txnStartDate=#{start_date.strftime(Aggcat::Base::DATE_FORMAT)}&txnEndDate=#{end_date.strftime(Aggcat::Base::DATE_FORMAT)}"
114
105
  stub_get(uri).to_return(:body => fixture('transactions.xml'), :headers => {:content_type => 'application/xml; charset=utf-8', :challengeSessionId => challenge_session_id, :challengeNodeId => challenge_node_id})
115
106
  response = @client.account_transactions(account_id, start_date, end_date)
116
- assert_equal '75000088503', response[:response][:transaction_list][:credit_card_transaction][:id]
107
+ assert_equal '75000088503', response[:result][:transaction_list][:credit_card_transaction][:id]
117
108
  assert_equal response[:challenge_session_id], challenge_session_id
118
109
  assert_equal response[:challenge_node_id], challenge_node_id
119
110
  end
120
111
 
121
112
  def test_account_transactions_bad_args
122
- exception = assert_raise(ArgumentError) { @client.account_transactions(nil, Date.today) }
123
- assert_equal('account_id is required', exception.message)
124
-
125
- exception = assert_raise(ArgumentError) { @client.account_transactions('', Date.today) }
126
- assert_equal('account_id is required', exception.message)
113
+ [nil, ''].each do |arg|
114
+ exception = assert_raise(ArgumentError) { @client.account_transactions(arg, Date.today) }
115
+ assert_equal('account_id is required', exception.message)
127
116
 
128
- exception = assert_raise(ArgumentError) { @client.account_transactions(1, nil) }
129
- assert_equal('start_date is required', exception.message)
130
-
131
- exception = assert_raise(ArgumentError) { @client.account_transactions(1, '') }
132
- assert_equal('start_date is required', exception.message)
117
+ exception = assert_raise(ArgumentError) { @client.account_transactions(1, arg) }
118
+ assert_equal('start_date is required', exception.message)
119
+ end
133
120
  end
134
121
 
135
122
  def test_delete_account
136
123
  account_id = '000000000001'
137
124
  stub_delete("/accounts/#{account_id}").to_return(:status => 200)
138
125
  response = @client.delete_account(account_id)
139
- assert_equal '200', response[:response_code]
126
+ assert_equal '200', response[:status_code]
140
127
  end
141
128
 
142
129
  def test_delete_account_bad_args
143
- exception = assert_raise(ArgumentError) { @client.delete_account(nil) }
144
- assert_equal('account_id is required', exception.message)
145
-
146
- exception = assert_raise(ArgumentError) { @client.delete_account('') }
147
- assert_equal('account_id is required', exception.message)
130
+ [nil, ''].each do |arg|
131
+ exception = assert_raise(ArgumentError) { @client.delete_account(arg) }
132
+ assert_equal('account_id is required', exception.message)
133
+ end
148
134
  end
149
135
 
150
136
  def test_delete_customer
151
137
  stub_delete('/customers').to_return(:status => 200)
152
138
  response = @client.delete_customer
153
- assert_equal '200', response[:response_code]
139
+ assert_equal '200', response[:status_code]
154
140
  end
155
141
 
156
142
  def test_update_login
@@ -159,33 +145,23 @@ class ClientTest < Test::Unit::TestCase
159
145
  stub_get("/institutions/#{institution_id}").to_return(:body => fixture('institution.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
160
146
  stub_put("/logins/#{login_id}?refresh=true").to_return(:status => 200)
161
147
  response = @client.update_login(institution_id, login_id, 'usename', 'password')
162
- assert_equal '200', response[:response_code]
148
+ assert_equal '200', response[:status_code]
163
149
  end
164
150
 
165
151
  def test_update_login_bad_args
166
- exception = assert_raise(ArgumentError) { @client.update_login(nil, 1, 'username', 'password') }
167
- assert_equal('institution_id is required', exception.message)
168
-
169
- exception = assert_raise(ArgumentError) { @client.update_login('', 1, 'username', 'password') }
170
- assert_equal('institution_id is required', exception.message)
152
+ [nil, ''].each do |arg|
153
+ exception = assert_raise(ArgumentError) { @client.update_login(arg, 1, 'username', 'password') }
154
+ assert_equal('institution_id is required', exception.message)
171
155
 
172
- exception = assert_raise(ArgumentError) { @client.update_login(1, nil, 'username', 'password') }
173
- assert_equal('login_id is required', exception.message)
156
+ exception = assert_raise(ArgumentError) { @client.update_login(1, arg, 'username', 'password') }
157
+ assert_equal('login_id is required', exception.message)
174
158
 
175
- exception = assert_raise(ArgumentError) { @client.update_login(1, '', 'username', 'password') }
176
- assert_equal('login_id is required', exception.message)
159
+ exception = assert_raise(ArgumentError) { @client.update_login(1, 1, arg, 'password') }
160
+ assert_equal('username is required', exception.message)
177
161
 
178
- exception = assert_raise(ArgumentError) { @client.update_login(1, 1, nil, 'password') }
179
- assert_equal('username is required', exception.message)
180
-
181
- exception = assert_raise(ArgumentError) { @client.update_login(1, 1, '', 'password') }
182
- assert_equal('username is required', exception.message)
183
-
184
- exception = assert_raise(ArgumentError) { @client.update_login(1, 1, 'username', nil) }
185
- assert_equal('password is required', exception.message)
186
-
187
- exception = assert_raise(ArgumentError) { @client.update_login(1, 1, 'username', '') }
188
- assert_equal('password is required', exception.message)
162
+ exception = assert_raise(ArgumentError) { @client.update_login(1, 1, 'username', arg) }
163
+ assert_equal('password is required', exception.message)
164
+ end
189
165
  end
190
166
 
191
167
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aggcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: