dwolla-ruby 2.5.1 → 2.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,71 +1,71 @@
1
- module Dwolla
2
- class Transactions
3
- def self.get(id=nil, filters={}, token=nil)
4
- url = transactions_url
5
-
6
- if id.is_a?(Hash)
7
- filters = id
8
- id = nil
9
- else
10
- filters = {}
11
- end
12
-
13
- url += id.to_s unless id.nil?
14
-
15
- Dwolla.request(:get, url, filters, {}, token)
16
- end
17
-
18
- def self.stats(filters={}, token=nil)
19
- url = transactions_url + 'stats'
20
-
21
- Dwolla.request(:get, url, filters, {}, token)
22
- end
23
-
24
- def self.create(params={}, token=nil)
25
- raise MissingParameterError.new('No PIN Provided.') unless params[:pin]
26
- raise MissingParameterError.new('No Destination ID Provided.') unless params[:destinationId]
27
- raise MissingParameterError.new('No Amount Provided.') unless params[:amount]
28
-
29
- url = transactions_url + 'send'
30
-
31
- Dwolla.request(:post, url, params, {}, token)
32
- end
33
-
34
- def self.refund(params={}, token=nil)
35
- raise MissingParameterError.new('No PIN Provided.') unless params[:pin]
36
- raise MissingParameterError.new('No Funding Source Provided.') unless params[:fundsSource]
37
- raise MissingParameterError.new('No Transaction ID Provided.') unless params[:transactionId]
38
- raise MissingParameterError.new('No Amount Provided.') unless params[:amount]
39
-
40
- url = transactions_url + 'refund'
41
-
42
- Dwolla.request(:post, url, params, {}, token)
43
- end
44
-
45
- def self.guest_send(params={})
46
- raise MissingParameterError.new('No Destination ID Provided.') unless params[:destinationId]
47
- raise MissingParameterError.new('No Amount Provided.') unless params[:amount]
48
- raise MissingParameterError.new('No First Name Provided.') unless params[:firstName]
49
- raise MissingParameterError.new('No Last Name Provided.') unless params[:lastName]
50
- raise MissingParameterError.new('No Email Address Provided.') unless params[:emailAddress]
51
- raise MissingParameterError.new('No Routing Number (ABA) Provided.') unless params[:routingNumber]
52
- raise MissingParameterError.new('No Account Number Provided.') unless params[:accountNumber]
53
- raise MissingParameterError.new('No Account Type Provided.') unless params[:accountType]
54
-
55
- url = transactions_url + 'guestsend'
56
-
57
- Dwolla.request(:post, url, params, {}, false)
58
- end
59
-
60
- class << self
61
- alias_method :listing, :get
62
- alias_method :send, :create
63
- end
64
-
65
- private
66
-
67
- def self.transactions_url
68
- return '/transactions/'
69
- end
70
- end
71
- end
1
+ module Dwolla
2
+ class Transactions
3
+ def self.get(id=nil, filters={}, token=nil)
4
+ url = transactions_url
5
+
6
+ if id.is_a?(Hash)
7
+ filters = id
8
+ id = nil
9
+ else
10
+ filters = {}
11
+ end
12
+
13
+ url += id.to_s unless id.nil?
14
+
15
+ Dwolla.request(:get, url, filters, {}, token)
16
+ end
17
+
18
+ def self.stats(filters={}, token=nil)
19
+ url = transactions_url + 'stats'
20
+
21
+ Dwolla.request(:get, url, filters, {}, token)
22
+ end
23
+
24
+ def self.create(params={}, token=nil)
25
+ raise MissingParameterError.new('No PIN Provided.') unless params[:pin]
26
+ raise MissingParameterError.new('No Destination ID Provided.') unless params[:destinationId]
27
+ raise MissingParameterError.new('No Amount Provided.') unless params[:amount]
28
+
29
+ url = transactions_url + 'send'
30
+
31
+ Dwolla.request(:post, url, params, {}, token)
32
+ end
33
+
34
+ def self.refund(params={}, token=nil)
35
+ raise MissingParameterError.new('No PIN Provided.') unless params[:pin]
36
+ raise MissingParameterError.new('No Funding Source Provided.') unless params[:fundsSource]
37
+ raise MissingParameterError.new('No Transaction ID Provided.') unless params[:transactionId]
38
+ raise MissingParameterError.new('No Amount Provided.') unless params[:amount]
39
+
40
+ url = transactions_url + 'refund'
41
+
42
+ Dwolla.request(:post, url, params, {}, token)
43
+ end
44
+
45
+ def self.guest_send(params={})
46
+ raise MissingParameterError.new('No Destination ID Provided.') unless params[:destinationId]
47
+ raise MissingParameterError.new('No Amount Provided.') unless params[:amount]
48
+ raise MissingParameterError.new('No First Name Provided.') unless params[:firstName]
49
+ raise MissingParameterError.new('No Last Name Provided.') unless params[:lastName]
50
+ raise MissingParameterError.new('No Email Address Provided.') unless params[:emailAddress]
51
+ raise MissingParameterError.new('No Routing Number (ABA) Provided.') unless params[:routingNumber]
52
+ raise MissingParameterError.new('No Account Number Provided.') unless params[:accountNumber]
53
+ raise MissingParameterError.new('No Account Type Provided.') unless params[:accountType]
54
+
55
+ url = transactions_url + 'guestsend'
56
+
57
+ Dwolla.request(:post, url, params, {}, false)
58
+ end
59
+
60
+ class << self
61
+ alias_method :listing, :get
62
+ alias_method :send, :create
63
+ end
64
+
65
+ private
66
+
67
+ def self.transactions_url
68
+ return '/transactions/'
69
+ end
70
+ end
71
+ end
@@ -1,36 +1,36 @@
1
- module Dwolla
2
- class Users
3
- def self.get(id=nil, token=nil)
4
- url = users_url
5
-
6
- unless id.nil?
7
- url += id.to_s
8
- @oauth = false
9
- else
10
- @oauth = token.nil? ? true : token
11
- end
12
-
13
- Dwolla.request(:get, url, {}, {}, @oauth)
14
- end
15
-
16
- def self.me(token=nil)
17
- # I'm not using the 'alias_method' fn
18
- # because the .me method should not
19
- # honor any parameters (i.e. User IDs)
20
- # passed to it
21
- self.get(nil, token)
22
- end
23
-
24
- def self.nearby(filters={})
25
- url = users_url + 'nearby'
26
-
27
- Dwolla.request(:get, url, filters, {}, false)
28
- end
29
-
30
- private
31
-
32
- def self.users_url
33
- return '/users/'
34
- end
35
- end
36
- end
1
+ module Dwolla
2
+ class Users
3
+ def self.get(id=nil, token=nil)
4
+ url = users_url
5
+
6
+ unless id.nil?
7
+ url += id.to_s
8
+ @oauth = false
9
+ else
10
+ @oauth = token.nil? ? true : token
11
+ end
12
+
13
+ Dwolla.request(:get, url, {}, {}, @oauth)
14
+ end
15
+
16
+ def self.me(token=nil)
17
+ # I'm not using the 'alias_method' fn
18
+ # because the .me method should not
19
+ # honor any parameters (i.e. User IDs)
20
+ # passed to it
21
+ self.get(nil, token)
22
+ end
23
+
24
+ def self.nearby(filters={})
25
+ url = users_url + 'nearby'
26
+
27
+ Dwolla.request(:get, url, filters, {}, false)
28
+ end
29
+
30
+ private
31
+
32
+ def self.users_url
33
+ return '/users/'
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
- module Dwolla
2
- VERSION = "2.5.1"
3
- end
1
+ module Dwolla
2
+ VERSION = "2.5.5"
3
+ end
@@ -1,198 +1,198 @@
1
- # -*- coding: utf-8 -*-
2
- require File.expand_path('../test_helper', __FILE__)
3
- require 'test/unit'
4
- require 'shoulda'
5
- require 'mocha/setup'
6
- require 'pp'
7
- require 'rest-client'
8
- require 'cgi'
9
- require 'uri'
10
-
11
- class TestDwollaRuby < Test::Unit::TestCase
12
- include Mocha
13
-
14
- context "API Wrapper" do
15
- setup do
16
- @mock = mock
17
- Dwolla.mock_rest_client = @mock
18
- end
19
-
20
- teardown do
21
- Dwolla.mock_rest_client = nil
22
- end
23
-
24
- should "not specifying a token should raise an exception on user-centric calls" do
25
- Dwolla.token = nil
26
- assert_raises Dwolla::AuthenticationError do
27
- Dwolla::Balance.get
28
- end
29
- end
30
-
31
- should "not specifying api credentials should raise an exception on app-centric calls" do
32
- Dwolla.api_key = nil
33
- assert_raises Dwolla::AuthenticationError do
34
- Dwolla::Contacts.nearby
35
- end
36
- end
37
-
38
- context "with valid token" do
39
- setup do
40
- Dwolla.token="foo"
41
- end
42
-
43
- teardown do
44
- Dwolla.token=nil
45
- end
46
-
47
- context "balance tests" do
48
- should "balance should be retrievable" do
49
- @mock.expects(:get).once.returns(test_response(test_balance))
50
- balance = Dwolla::Balance.get
51
- assert balance.kind_of? Float
52
- end
53
- end
54
-
55
- context "contacts tests" do
56
- should "be able to get a user's contacts" do
57
- @mock.expects(:get).once.returns(test_response(test_contacts_array))
58
- contacts = Dwolla::Contacts.get
59
- assert contacts.kind_of? Array
60
- end
61
- end
62
-
63
- context "funding sources tests" do
64
- should "should be able to get a user's funding source by its id" do
65
- @mock.expects(:get).once.returns(test_response(test_fundingsource_byid))
66
- fundingsource = Dwolla::FundingSources.get('funding_source_id')
67
- assert fundingsource.kind_of? Object
68
- end
69
-
70
- should "should be able to get a user's funding sources" do
71
- @mock.expects(:get).once.returns(test_response(test_fundingsources_array))
72
- fundingsources = Dwolla::FundingSources.get
73
- assert fundingsources.kind_of? Array
74
- end
75
-
76
- should "should be able to withdraw to a user's funding source" do
77
- @mock.expects(:post).once.returns(test_response(test_fundingsource_withdraw))
78
- withdraw = Dwolla::FundingSources.withdraw('funding_source_id', {:pin => '0000', :amount => '1.00'})
79
- assert withdraw.kind_of? Object
80
- end
81
-
82
- should "should be able to deposit from a user's funding source" do
83
- @mock.expects(:post).once.returns(test_response(test_fundingsource_deposit))
84
- withdraw = Dwolla::FundingSources.withdraw('funding_source_id', {:pin => '0000', :amount => '1.00'})
85
- assert withdraw.kind_of? Object
86
- end
87
-
88
- should "should be able to add a funding source for a user" do
89
-
90
- end
91
-
92
- should "should be able to verify a user's funding source" do
93
-
94
- end
95
- end
96
-
97
- context "requests tests" do
98
- should "should be able to get a user's pending money requests" do
99
- @mock.expects(:get).once.returns(test_response(test_requests_array))
100
- requests = Dwolla::Requests.get
101
- assert requests.kind_of? Array
102
- end
103
-
104
- should "should be able to get a user's pending money request by its id" do
105
- @mock.expects(:get).once.returns(test_response(test_request_byid))
106
- request = Dwolla::Requests.get('request_id')
107
- assert request.kind_of? Object
108
- end
109
-
110
- should "should be able to cancel a user's pending money request" do
111
- @mock.expects(:post).once.returns(test_response(test_request_cancel))
112
- request = Dwolla::Requests.cancel('request_id')
113
- assert request.kind_of? String
114
- end
115
-
116
- should "should be able to create a new money request for a user" do
117
- @mock.expects(:post).once.returns(test_response(test_request))
118
- request = Dwolla::Requests.request({:pin => 1111, :amount => 0.01, :sourceId => 'alex@dwolla.com'})
119
- assert request.kind_of? Integer
120
- end
121
-
122
- should "should be a able to fulfill a user's pending money request" do
123
- @mock.expects(:post).once.returns(test_response(test_request_fulfill))
124
- request = Dwolla::Requests.fulfill('2219682', {:pin => 1111})
125
- assert request.kind_of? Object
126
- end
127
- end
128
-
129
- context "transactions tests" do
130
- should "should be able to get a user's transaction information by its id" do
131
- @mock.expects(:get).once.returns(test_response(test_transaction_byid))
132
- transactions = Dwolla::Transactions.get('transaction_id')
133
- assert transactions.kind_of? Object
134
- end
135
-
136
- should "should be able to get a user's transaction history" do
137
- @mock.expects(:get).once.returns(test_response(test_transactions_array))
138
- transactions = Dwolla::Transactions.get
139
- assert transactions.kind_of? Array
140
- end
141
-
142
- should "should be able to get a user's transaction statistics" do
143
- @mock.expects(:get).once.returns(test_response(test_transactions_stats))
144
- stats = Dwolla::Transactions.stats
145
- assert stats.kind_of? Object
146
- end
147
-
148
- should "should be able to send money from a user's account" do
149
- @mock.expects(:post).once.returns(test_response(test_send))
150
- send = Dwolla::Transactions.send({:pin => 1111, :destinationId => '812-734-7288', :amount => 0.01})
151
- assert send.kind_of? Integer
152
- end
153
- end
154
-
155
- context "users tests" do
156
- should "should be able to get a user's information" do
157
- @mock.expects(:get).once.returns(test_response(test_user_self))
158
- user = Dwolla::Users.me
159
- assert user.kind_of? Object
160
- end
161
- end
162
- end
163
-
164
- context "with valid app credentials" do
165
- setup do
166
- Dwolla.api_key="foo"
167
- Dwolla.api_secret="bar"
168
- end
169
-
170
- teardown do
171
- Dwolla.api_key=nil
172
- Dwolla.api_secret=nil
173
- end
174
-
175
- context "contacts tests" do
176
- should "be able to get a list of nearby spots" do
177
- @mock.expects(:get).once.returns(test_response(test_contacts_array))
178
- spots = Dwolla::Contacts.nearby
179
- assert spots.kind_of? Array
180
- end
181
- end
182
-
183
- context "users tests" do
184
- should "should be able to get any user's information" do
185
- @mock.expects(:get).once.returns(test_response(test_user_byid))
186
- user = Dwolla::Users.get('alex@dwolla.com')
187
- assert user.kind_of? Object
188
- end
189
-
190
- should "should be able to get a list of nearby users" do
191
- @mock.expects(:get).once.returns(test_response(test_users_array))
192
- users = Dwolla::Users.nearby
193
- assert users.kind_of? Array
194
- end
195
- end
196
- end
197
- end
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path('../test_helper', __FILE__)
3
+ require 'test/unit'
4
+ require 'shoulda'
5
+ require 'mocha/setup'
6
+ require 'pp'
7
+ require 'rest-client'
8
+ require 'cgi'
9
+ require 'uri'
10
+
11
+ class TestDwollaRuby < Test::Unit::TestCase
12
+ include Mocha
13
+
14
+ context "API Wrapper" do
15
+ setup do
16
+ @mock = mock
17
+ Dwolla.mock_rest_client = @mock
18
+ end
19
+
20
+ teardown do
21
+ Dwolla.mock_rest_client = nil
22
+ end
23
+
24
+ should "not specifying a token should raise an exception on user-centric calls" do
25
+ Dwolla.token = nil
26
+ assert_raises Dwolla::AuthenticationError do
27
+ Dwolla::Balance.get
28
+ end
29
+ end
30
+
31
+ should "not specifying api credentials should raise an exception on app-centric calls" do
32
+ Dwolla.api_key = nil
33
+ assert_raises Dwolla::AuthenticationError do
34
+ Dwolla::Contacts.nearby
35
+ end
36
+ end
37
+
38
+ context "with valid token" do
39
+ setup do
40
+ Dwolla.token="foo"
41
+ end
42
+
43
+ teardown do
44
+ Dwolla.token=nil
45
+ end
46
+
47
+ context "balance tests" do
48
+ should "balance should be retrievable" do
49
+ @mock.expects(:get).once.returns(test_response(test_balance))
50
+ balance = Dwolla::Balance.get
51
+ assert balance.kind_of? Float
52
+ end
53
+ end
54
+
55
+ context "contacts tests" do
56
+ should "be able to get a user's contacts" do
57
+ @mock.expects(:get).once.returns(test_response(test_contacts_array))
58
+ contacts = Dwolla::Contacts.get
59
+ assert contacts.kind_of? Array
60
+ end
61
+ end
62
+
63
+ context "funding sources tests" do
64
+ should "should be able to get a user's funding source by its id" do
65
+ @mock.expects(:get).once.returns(test_response(test_fundingsource_byid))
66
+ fundingsource = Dwolla::FundingSources.get('funding_source_id')
67
+ assert fundingsource.kind_of? Object
68
+ end
69
+
70
+ should "should be able to get a user's funding sources" do
71
+ @mock.expects(:get).once.returns(test_response(test_fundingsources_array))
72
+ fundingsources = Dwolla::FundingSources.get
73
+ assert fundingsources.kind_of? Array
74
+ end
75
+
76
+ should "should be able to withdraw to a user's funding source" do
77
+ @mock.expects(:post).once.returns(test_response(test_fundingsource_withdraw))
78
+ withdraw = Dwolla::FundingSources.withdraw('funding_source_id', {:pin => '0000', :amount => '1.00'})
79
+ assert withdraw.kind_of? Object
80
+ end
81
+
82
+ should "should be able to deposit from a user's funding source" do
83
+ @mock.expects(:post).once.returns(test_response(test_fundingsource_deposit))
84
+ withdraw = Dwolla::FundingSources.withdraw('funding_source_id', {:pin => '0000', :amount => '1.00'})
85
+ assert withdraw.kind_of? Object
86
+ end
87
+
88
+ should "should be able to add a funding source for a user" do
89
+
90
+ end
91
+
92
+ should "should be able to verify a user's funding source" do
93
+
94
+ end
95
+ end
96
+
97
+ context "requests tests" do
98
+ should "should be able to get a user's pending money requests" do
99
+ @mock.expects(:get).once.returns(test_response(test_requests_array))
100
+ requests = Dwolla::Requests.get
101
+ assert requests.kind_of? Array
102
+ end
103
+
104
+ should "should be able to get a user's pending money request by its id" do
105
+ @mock.expects(:get).once.returns(test_response(test_request_byid))
106
+ request = Dwolla::Requests.get('request_id')
107
+ assert request.kind_of? Object
108
+ end
109
+
110
+ should "should be able to cancel a user's pending money request" do
111
+ @mock.expects(:post).once.returns(test_response(test_request_cancel))
112
+ request = Dwolla::Requests.cancel('request_id')
113
+ assert request.kind_of? String
114
+ end
115
+
116
+ should "should be able to create a new money request for a user" do
117
+ @mock.expects(:post).once.returns(test_response(test_request))
118
+ request = Dwolla::Requests.request({:pin => 1111, :amount => 0.01, :sourceId => 'alex@dwolla.com'})
119
+ assert request.kind_of? Integer
120
+ end
121
+
122
+ should "should be a able to fulfill a user's pending money request" do
123
+ @mock.expects(:post).once.returns(test_response(test_request_fulfill))
124
+ request = Dwolla::Requests.fulfill('2219682', {:pin => 1111})
125
+ assert request.kind_of? Object
126
+ end
127
+ end
128
+
129
+ context "transactions tests" do
130
+ should "should be able to get a user's transaction information by its id" do
131
+ @mock.expects(:get).once.returns(test_response(test_transaction_byid))
132
+ transactions = Dwolla::Transactions.get('transaction_id')
133
+ assert transactions.kind_of? Object
134
+ end
135
+
136
+ should "should be able to get a user's transaction history" do
137
+ @mock.expects(:get).once.returns(test_response(test_transactions_array))
138
+ transactions = Dwolla::Transactions.get
139
+ assert transactions.kind_of? Array
140
+ end
141
+
142
+ should "should be able to get a user's transaction statistics" do
143
+ @mock.expects(:get).once.returns(test_response(test_transactions_stats))
144
+ stats = Dwolla::Transactions.stats
145
+ assert stats.kind_of? Object
146
+ end
147
+
148
+ should "should be able to send money from a user's account" do
149
+ @mock.expects(:post).once.returns(test_response(test_send))
150
+ send = Dwolla::Transactions.send({:pin => 1111, :destinationId => '812-734-7288', :amount => 0.01})
151
+ assert send.kind_of? Integer
152
+ end
153
+ end
154
+
155
+ context "users tests" do
156
+ should "should be able to get a user's information" do
157
+ @mock.expects(:get).once.returns(test_response(test_user_self))
158
+ user = Dwolla::Users.me
159
+ assert user.kind_of? Object
160
+ end
161
+ end
162
+ end
163
+
164
+ context "with valid app credentials" do
165
+ setup do
166
+ Dwolla.api_key="foo"
167
+ Dwolla.api_secret="bar"
168
+ end
169
+
170
+ teardown do
171
+ Dwolla.api_key=nil
172
+ Dwolla.api_secret=nil
173
+ end
174
+
175
+ context "contacts tests" do
176
+ should "be able to get a list of nearby spots" do
177
+ @mock.expects(:get).once.returns(test_response(test_contacts_array))
178
+ spots = Dwolla::Contacts.nearby
179
+ assert spots.kind_of? Array
180
+ end
181
+ end
182
+
183
+ context "users tests" do
184
+ should "should be able to get any user's information" do
185
+ @mock.expects(:get).once.returns(test_response(test_user_byid))
186
+ user = Dwolla::Users.get('alex@dwolla.com')
187
+ assert user.kind_of? Object
188
+ end
189
+
190
+ should "should be able to get a list of nearby users" do
191
+ @mock.expects(:get).once.returns(test_response(test_users_array))
192
+ users = Dwolla::Users.nearby
193
+ assert users.kind_of? Array
194
+ end
195
+ end
196
+ end
197
+ end
198
198
  end