dwolla-ruby 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/dwolla-ruby.gemspec +16 -21
  2. data/examples/accountInfo.rb +7 -7
  3. data/examples/balance.rb +5 -5
  4. data/examples/contacts.rb +4 -4
  5. data/examples/fundingSources.rb +4 -4
  6. data/examples/oauth.rb +6 -7
  7. data/examples/transactions.rb +32 -0
  8. data/lib/dwolla.rb +258 -37
  9. data/lib/dwolla/balance.rb +15 -0
  10. data/lib/dwolla/contacts.rb +22 -0
  11. data/lib/dwolla/errors/api_connection_error.rb +4 -0
  12. data/lib/dwolla/errors/api_error.rb +4 -0
  13. data/lib/dwolla/errors/authentication_error.rb +4 -0
  14. data/lib/dwolla/errors/dwolla_error.rb +20 -0
  15. data/lib/dwolla/errors/invalid_request_error.rb +10 -0
  16. data/lib/dwolla/errors/missing_parameter_error.rb +4 -0
  17. data/lib/dwolla/funding_sources.rb +65 -0
  18. data/lib/dwolla/json.rb +21 -0
  19. data/lib/dwolla/oauth.rb +43 -0
  20. data/lib/dwolla/offsite_gateway.rb +76 -0
  21. data/lib/dwolla/requests.rb +56 -0
  22. data/lib/dwolla/transactions.rb +60 -0
  23. data/lib/dwolla/users.rb +36 -0
  24. data/lib/dwolla/version.rb +1 -1
  25. metadata +37 -108
  26. data/Gemfile +0 -4
  27. data/examples/send.rb +0 -23
  28. data/lib/dwolla/client.rb +0 -56
  29. data/lib/dwolla/connection.rb +0 -47
  30. data/lib/dwolla/funding_source.rb +0 -18
  31. data/lib/dwolla/response/follow_redirects.rb +0 -44
  32. data/lib/dwolla/response/guard_server_error.rb +0 -32
  33. data/lib/dwolla/response/parse_json.rb +0 -27
  34. data/lib/dwolla/transaction.rb +0 -56
  35. data/lib/dwolla/user.rb +0 -121
  36. data/spec/dwolla/client_spec.rb +0 -51
  37. data/spec/dwolla/funding_source_spec.rb +0 -59
  38. data/spec/dwolla/response/follow_redirects_spec.rb +0 -38
  39. data/spec/dwolla/transaction_spec.rb +0 -212
  40. data/spec/dwolla/user_spec.rb +0 -292
  41. data/spec/dwolla_spec.rb +0 -19
  42. data/spec/fixtures/account_information.json +0 -13
  43. data/spec/fixtures/add_funding_source.json +0 -11
  44. data/spec/fixtures/balance.json +0 -5
  45. data/spec/fixtures/basic_information.json +0 -6
  46. data/spec/fixtures/contacts.json +0 -18
  47. data/spec/fixtures/error.json +0 -5
  48. data/spec/fixtures/register.json +0 -9
  49. data/spec/fixtures/request_transaction.json +0 -3
  50. data/spec/fixtures/send_transaction.json +0 -3
  51. data/spec/fixtures/sources.json +0 -13
  52. data/spec/spec_helper.rb +0 -10
  53. data/spec/support/helpers.rb +0 -29
@@ -1,292 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Dwolla::User do
4
- let(:oauth_token) { 'valid_token' }
5
- let(:token_param) { "oauth_token=#{oauth_token}" }
6
-
7
- describe "fetching your full account information" do
8
- before do
9
- stub_get('/users', token_param).
10
- to_return(:body => fixture("account_information.json"))
11
- end
12
-
13
- it "should request the correct resource" do
14
- user = Dwolla::User.me(oauth_token).fetch
15
-
16
- a_get('/users', token_param).should have_been_made
17
- end
18
-
19
- it "should return full information" do
20
- user = Dwolla::User.me(oauth_token).fetch
21
-
22
- user.should be_a Dwolla::User
23
- user.id.should == '812-111-1111'
24
- user.name.should == 'Test User'
25
- user.latitude.should == 41.584546
26
- user.longitude.should == -93.634167
27
- user.city.should == 'Des Moines'
28
- user.state.should == 'IA'
29
- user.type.should == 'Personal'
30
- user.oauth_token.should == oauth_token
31
- end
32
-
33
- it "should raise a error if fetch failed" do
34
- stub_get('/users', token_param).
35
- to_return(:body => fixture("error.json"))
36
-
37
- expect{ Dwolla::User.me(oauth_token).fetch }.to \
38
- raise_error(Dwolla::RequestException, "Token does not have access to requested resource.")
39
- end
40
- end
41
-
42
- describe "sending money" do
43
- context "to a dwolla account" do
44
- it "should make the correct transaction" do
45
- user = Dwolla::User.new(:oauth_token => '12345', :id => '1')
46
- destination_user = Dwolla::User.new(:id => '2')
47
- amount = 10
48
- pin = '2222'
49
- description = "Sending a transaction"
50
-
51
-
52
- transaction = double('transaction')
53
- transaction_id = 123
54
-
55
- Dwolla::Transaction.should_receive(:new).with(:origin => user,
56
- :destination => destination_user,
57
- :destination_type => 'dwolla',
58
- :description => description,
59
- :amount => 10,
60
- :type => :send,
61
- :pin => '2222',
62
- :funds_source=>nil,
63
- :assume_costs=>nil).and_return(transaction)
64
-
65
- transaction.should_receive(:execute).and_return(transaction_id)
66
-
67
- user.send_money_to(destination_user, amount, pin, 'dwolla', description).should == 123
68
- end
69
- end
70
- context "to an email address" do
71
- it "should make the correct transaction" do
72
- user = Dwolla::User.new(:oauth_token => '12345', :id => '1')
73
- destination_user = 'user@example.com'
74
- description = "Sending a transaction"
75
- amount = 10
76
- pin = '2222'
77
-
78
-
79
- transaction = double('transaction')
80
- transaction_id = 123
81
-
82
- Dwolla::Transaction.should_receive(:new).with(:origin => user,
83
- :destination => destination_user,
84
- :destination_type => 'email',
85
- :description => description,
86
- :amount => 10,
87
- :type => :send,
88
- :pin => '2222',
89
- :funds_source=>nil,
90
- :assume_costs=>nil).and_return(transaction)
91
-
92
- transaction.should_receive(:execute).and_return(transaction_id)
93
-
94
- user.send_money_to(destination_user, amount, pin, 'email', description).should == 123
95
- end
96
- end
97
- context "assume costs" do
98
- it "should make the correct transaction and assume costs if set to true" do
99
- user = Dwolla::User.new(:oauth_token => '12345', :id => '1')
100
- destination_user = 'user@example.com'
101
- description = "sending a transaction"
102
- amount = 10
103
- pin = '2222'
104
-
105
-
106
- transaction = double('transaction')
107
- transaction_id = 123
108
-
109
- Dwolla::Transaction.should_receive(:new).with(:origin => user,
110
- :destination => destination_user,
111
- :destination_type => 'email',
112
- :description => description,
113
- :amount => 10,
114
- :type => :send,
115
- :pin => '2222',
116
- :funds_source=>nil,
117
- :assume_costs=>true).and_return(transaction)
118
-
119
- transaction.should_receive(:execute).and_return(transaction_id)
120
-
121
- user.send_money_to(destination_user, amount, pin, 'email', description, nil, true).should == 123
122
- end
123
- it "should make the correct transaction and assume costs if set to false" do
124
- user = Dwolla::User.new(:oauth_token => '12345', :id => '1')
125
- destination_user = 'user@example.com'
126
- description = "sending a transaction"
127
- amount = 10
128
- pin = '2222'
129
-
130
-
131
- transaction = double('transaction')
132
- transaction_id = 123
133
-
134
- Dwolla::Transaction.should_receive(:new).with(:origin => user,
135
- :destination => destination_user,
136
- :destination_type => 'email',
137
- :description => description,
138
- :amount => 10,
139
- :type => :send,
140
- :pin => '2222',
141
- :funds_source=>nil,
142
- :assume_costs=>false).and_return(transaction)
143
-
144
- transaction.should_receive(:execute).and_return(transaction_id)
145
-
146
- user.send_money_to(destination_user, amount, pin, 'email', description, nil, false).should == 123
147
- end
148
- end
149
- end
150
-
151
- describe "requesting money" do
152
- context "from a dwolla account" do
153
- it "should make the correct transaction" do
154
- user = Dwolla::User.new(:oauth_token => '12345', :id => '1')
155
- source_user_id = '2'
156
- amount = 10
157
- pin = '2222'
158
- description = "Sending a transaction"
159
-
160
- transaction = double('transaction')
161
- transaction_id = 123
162
-
163
- Dwolla::Transaction.should_receive(:new).with(:origin => user,
164
- :source => source_user_id,
165
- :source_type => 'dwolla',
166
- :description => description,
167
- :amount => 10,
168
- :type => :request,
169
- :pin => '2222').and_return(transaction)
170
-
171
- transaction.should_receive(:execute).and_return(transaction_id)
172
-
173
- user.request_money_from(source_user_id, amount, pin, 'dwolla', description).should == 123
174
- end
175
- end
176
- context "from an email address" do
177
- it "should make the correct transaction" do
178
- user = Dwolla::User.new(:oauth_token => '12345', :id => '1')
179
- source_user_id = 'user@example.com'
180
- amount = 10
181
- pin = '2222'
182
- description = "Sending a transaction"
183
-
184
- transaction = double('transaction')
185
- transaction_id = 123
186
-
187
- Dwolla::Transaction.should_receive(:new).with(:origin => user,
188
- :source => source_user_id,
189
- :source_type => 'email',
190
- :description => description,
191
- :amount => 10,
192
- :type => :request,
193
- :pin => '2222').and_return(transaction)
194
-
195
- transaction.should_receive(:execute).and_return(transaction_id)
196
-
197
- user.request_money_from(source_user_id, amount, pin, 'email', description).should == 123
198
- end
199
- end
200
- end
201
-
202
- it "knows his balance" do
203
- stub_get('/balance', token_param).
204
- to_return(:body => fixture("balance.json"))
205
-
206
- user = Dwolla::User.me(oauth_token)
207
- user.balance.should == 55.76
208
- end
209
-
210
-
211
- describe "contacts" do
212
- it "should request the correct resource when unfiltered" do
213
- user = Dwolla::User.me(oauth_token)
214
-
215
- stub_get('/contacts', token_param).
216
- to_return(:body => fixture("contacts.json"))
217
-
218
- user.contacts
219
-
220
- a_get('/contacts', token_param).should have_been_made
221
- end
222
-
223
- it "should request the correct resource when seaching by name" do
224
- user = Dwolla::User.me(oauth_token)
225
-
226
- stub_get("/contacts?search=Bob&#{token_param}").
227
- to_return(:body => fixture("contacts.json"))
228
-
229
- user.contacts(:search => 'Bob')
230
-
231
- a_get("/contacts?search=Bob&#{token_param}").should have_been_made
232
- end
233
-
234
- it "should request the correct resource when filtering by type" do
235
- user = Dwolla::User.me(oauth_token)
236
-
237
- stub_get("/contacts?type=Facebook&#{token_param}").
238
- to_return(:body => fixture("contacts.json"))
239
-
240
- user.contacts(:type => 'Facebook')
241
-
242
- a_get("/contacts?type=Facebook&#{token_param}").should have_been_made
243
- end
244
-
245
- it "should request the correct resource when limiting" do
246
- user = Dwolla::User.me(oauth_token)
247
-
248
- stub_get("/contacts?limit=2&#{token_param}").
249
- to_return(:body => fixture("contacts.json"))
250
-
251
- user.contacts(:limit => 2)
252
-
253
- a_get("/contacts?limit=2&#{token_param}").should have_been_made
254
- end
255
-
256
- it "should request the correct resource when using all together" do
257
- user = Dwolla::User.me(oauth_token)
258
-
259
- stub_get("/contacts?search=Bob&type=Facebook&limit=2&#{token_param}").
260
- to_return(:body => fixture("contacts.json"))
261
-
262
- user.contacts(:search => "Bob", :type => "Facebook", :limit => 2)
263
-
264
- a_get("/contacts?search=Bob&type=Facebook&limit=2&#{token_param}").should have_been_made
265
- end
266
-
267
- it "should return the contact users properly" do
268
- user = Dwolla::User.me(oauth_token)
269
-
270
- stub_get("/contacts", token_param).
271
- to_return(:body => fixture("contacts.json"))
272
-
273
- contacts = user.contacts
274
-
275
- first_contact = contacts.first
276
-
277
- first_contact.should be_a Dwolla::User
278
- first_contact.id.should == "12345"
279
- first_contact.name.should == "Ben Facebook Test"
280
- first_contact.image.should == "https://graph.facebook.com/12345/picture?type=square"
281
- first_contact.contact_type.should == "Facebook"
282
-
283
- second_contact = contacts.last
284
-
285
- second_contact.should be_a Dwolla::User
286
- second_contact.id.should == "812-111-1111"
287
- second_contact.name.should == "Ben Dwolla Test"
288
- second_contact.image.should == "https://www.dwolla.com/avatar.aspx?u=812-111-1111"
289
- second_contact.contact_type.should == "Dwolla"
290
- end
291
- end
292
- end
data/spec/dwolla_spec.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Dwolla do
4
- its(:endpoint) { should == "https://www.dwolla.com/oauth/rest" }
5
- its(:user_agent) { should == "Dwolla Ruby Wrapper" }
6
-
7
- describe 'debugging' do
8
- after do
9
- Dwolla.debug = false
10
- end
11
-
12
- it { should_not be_debugging }
13
-
14
- it 'should be debugging' do
15
- Dwolla.debug = true
16
- Dwolla.should be_debugging
17
- end
18
- end
19
- end
@@ -1,13 +0,0 @@
1
- {
2
- "Success": true,
3
- "Message": "Success",
4
- "Response": {
5
- "City": "Des Moines",
6
- "Id": "812-111-1111",
7
- "Latitude": 41.584546,
8
- "Longitude": -93.634167,
9
- "Name": "Test User",
10
- "State": "IA",
11
- "Type": "Personal"
12
- }
13
- }
@@ -1,11 +0,0 @@
1
- {
2
- "Success": true,
3
- "Message": "Success",
4
- "Response": {
5
- "Id": "34da835f235cd25302ef0c5c1cb1d4b9",
6
- "Name": "My Checking Account - Checking",
7
- "Type": "Checking",
8
- "Verified": false,
9
- "ProcessingType": "ACH"
10
- }
11
- }
@@ -1,5 +0,0 @@
1
- {
2
- "Success": true,
3
- "Message": "Success",
4
- "Response": 55.76
5
- }
@@ -1,6 +0,0 @@
1
- {
2
- "Id": "812-111-1111",
3
- "Latitude": 41.584546,
4
- "Longitude": -93.634167,
5
- "Name": "Test User"
6
- }
@@ -1,18 +0,0 @@
1
- {
2
- "Success": true,
3
- "Message": "Success",
4
- "Response": [
5
- {
6
- "Name": "Ben Facebook Test",
7
- "Id": "12345",
8
- "Type": "Facebook",
9
- "Image": "https://graph.facebook.com/12345/picture?type=square"
10
- },
11
- {
12
- "Name": "Ben Dwolla Test",
13
- "Id": "812-111-1111",
14
- "Type": "Dwolla",
15
- "Image": "https://www.dwolla.com/avatar.aspx?u=812-111-1111"
16
- }
17
- ]
18
- }
@@ -1,5 +0,0 @@
1
- {
2
- "Success": false,
3
- "Message": "Token does not have access to requested resource.",
4
- "Response": null
5
- }
@@ -1,9 +0,0 @@
1
- {
2
- "City":"Lansing",
3
- "State":"MI",
4
- "Type":"Personal",
5
- "Id":"812-111-1111",
6
- "Name":"Test User",
7
- "Latitude":0,
8
- "Longitude":0
9
- }
@@ -1,3 +0,0 @@
1
- {
2
- "RequestResult": 12345
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "SendResult": 12345
3
- }
@@ -1,13 +0,0 @@
1
- {
2
- "Success": true,
3
- "Message": "Success",
4
- "Response": [
5
- {
6
- "Id": "mE06khgHy9K/Ii9n5fbUEg==",
7
- "Name": "Checking - My Bank",
8
- "Type": "Checking",
9
- "Verified": true
10
- }
11
- ]
12
-
13
- }
data/spec/spec_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start
3
-
4
- $:.unshift File.expand_path('..', __FILE__)
5
- $:.unshift File.expand_path('../../lib', __FILE__)
6
-
7
- require 'dwolla-ruby'
8
- require 'rspec'
9
- require 'webmock/rspec'
10
- require 'support/helpers'
@@ -1,29 +0,0 @@
1
- def a_get(path, params = nil)
2
- url = Dwolla.endpoint + path
3
- url += "?#{params}" if params
4
- a_request(:get, url)
5
- end
6
-
7
- def a_post(path)
8
- url = Dwolla.endpoint + path
9
- a_request(:post, url)
10
- end
11
-
12
- def stub_get(path, params = nil)
13
- url = Dwolla.endpoint + path
14
- url += "?#{params}" if params
15
- stub_request(:get, url)
16
- end
17
-
18
- def stub_post(path)
19
- url = Dwolla.endpoint + path
20
- stub_request(:post, url)
21
- end
22
-
23
- def fixture_path
24
- File.expand_path("../../fixtures", __FILE__)
25
- end
26
-
27
- def fixture(file)
28
- IO.read(fixture_path + '/' + file)
29
- end