dwolla-ruby 1.0.0

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.
@@ -0,0 +1,260 @@
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').and_return(transaction)
62
+
63
+ transaction.should_receive(:execute).and_return(transaction_id)
64
+
65
+ user.send_money_to(destination_user, amount, pin, 'dwolla', description).should == 123
66
+ end
67
+ end
68
+ context "to an email address" do
69
+ it "should make the correct transaction" do
70
+ user = Dwolla::User.new(:oauth_token => '12345', :id => '1')
71
+ destination_user = 'user@example.com'
72
+ description = "Sending a transaction"
73
+ amount = 10
74
+ pin = '2222'
75
+
76
+
77
+ transaction = double('transaction')
78
+ transaction_id = 123
79
+
80
+ Dwolla::Transaction.should_receive(:new).with(:origin => user,
81
+ :destination => destination_user,
82
+ :destination_type => 'email',
83
+ :description => description,
84
+ :amount => 10,
85
+ :type => :send,
86
+ :pin => '2222').and_return(transaction)
87
+
88
+ transaction.should_receive(:execute).and_return(transaction_id)
89
+
90
+ user.send_money_to(destination_user, amount, pin, 'email', description).should == 123
91
+ end
92
+ end
93
+ end
94
+
95
+ describe "requesting money" do
96
+ context "from a dwolla account" do
97
+ it "should make the correct transaction" do
98
+ user = Dwolla::User.new(:oauth_token => '12345', :id => '1')
99
+ source_user_id = '2'
100
+ amount = 10
101
+ pin = '2222'
102
+ description = "Sending a transaction"
103
+
104
+ transaction = double('transaction')
105
+ transaction_id = 123
106
+
107
+ Dwolla::Transaction.should_receive(:new).with(:origin => user,
108
+ :source => source_user_id,
109
+ :source_type => 'dwolla',
110
+ :description => description,
111
+ :amount => 10,
112
+ :type => :request,
113
+ :pin => '2222').and_return(transaction)
114
+
115
+ transaction.should_receive(:execute).and_return(transaction_id)
116
+
117
+ user.request_money_from(source_user_id, amount, pin, 'dwolla', description).should == 123
118
+ end
119
+ end
120
+ context "from an email address" do
121
+ it "should make the correct transaction" do
122
+ user = Dwolla::User.new(:oauth_token => '12345', :id => '1')
123
+ source_user_id = 'user@example.com'
124
+ amount = 10
125
+ pin = '2222'
126
+ description = "Sending a transaction"
127
+
128
+ transaction = double('transaction')
129
+ transaction_id = 123
130
+
131
+ Dwolla::Transaction.should_receive(:new).with(:origin => user,
132
+ :source => source_user_id,
133
+ :source_type => 'email',
134
+ :description => description,
135
+ :amount => 10,
136
+ :type => :request,
137
+ :pin => '2222').and_return(transaction)
138
+
139
+ transaction.should_receive(:execute).and_return(transaction_id)
140
+
141
+ user.request_money_from(source_user_id, amount, pin, 'email', description).should == 123
142
+ end
143
+ end
144
+ end
145
+
146
+ it "knows his balance" do
147
+ stub_get('/balance', token_param).
148
+ to_return(:body => fixture("balance.json"))
149
+
150
+ user = Dwolla::User.me(oauth_token)
151
+ user.balance.should == 55.76
152
+ end
153
+
154
+ describe "Getting a list of funding sources" do
155
+ before :each do
156
+ user = Dwolla::User.me(oauth_token)
157
+ stub_request(:get, "https://www.dwolla.com/oauth/rest/fundingsources?oauth_token=valid_token").
158
+ with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Dwolla Ruby Wrapper'}).
159
+ to_return(:body => fixture("sources.json"))
160
+ @account = user.funding_sources.first
161
+ end
162
+ it "should be a FundingSource object" do
163
+ @account.should be_kind_of(Dwolla::FundingSource)
164
+ end
165
+ it "should get the correct id" do
166
+ @account.id.should == "mE06khgHy9K/Ii9n5fbUEg=="
167
+ end
168
+ it "should get the right name" do
169
+ @account.name.should == "Checking - My Bank"
170
+ end
171
+ it "should get the right type" do
172
+ @account.type.should == "Checking"
173
+ end
174
+ it "should get whether the account is verified" do
175
+ @account.should be_verified
176
+ end
177
+ end
178
+
179
+ describe "contacts" do
180
+ it "should request the correct resource when unfiltered" do
181
+ user = Dwolla::User.me(oauth_token)
182
+
183
+ stub_get('/contacts', token_param).
184
+ to_return(:body => fixture("contacts.json"))
185
+
186
+ user.contacts
187
+
188
+ a_get('/contacts', token_param).should have_been_made
189
+ end
190
+
191
+ it "should request the correct resource when seaching by name" do
192
+ user = Dwolla::User.me(oauth_token)
193
+
194
+ stub_get("/contacts?search=Bob&#{token_param}").
195
+ to_return(:body => fixture("contacts.json"))
196
+
197
+ user.contacts(:search => 'Bob')
198
+
199
+ a_get("/contacts?search=Bob&#{token_param}").should have_been_made
200
+ end
201
+
202
+ it "should request the correct resource when filtering by type" do
203
+ user = Dwolla::User.me(oauth_token)
204
+
205
+ stub_get("/contacts?type=Facebook&#{token_param}").
206
+ to_return(:body => fixture("contacts.json"))
207
+
208
+ user.contacts(:type => 'Facebook')
209
+
210
+ a_get("/contacts?type=Facebook&#{token_param}").should have_been_made
211
+ end
212
+
213
+ it "should request the correct resource when limiting" do
214
+ user = Dwolla::User.me(oauth_token)
215
+
216
+ stub_get("/contacts?limit=2&#{token_param}").
217
+ to_return(:body => fixture("contacts.json"))
218
+
219
+ user.contacts(:limit => 2)
220
+
221
+ a_get("/contacts?limit=2&#{token_param}").should have_been_made
222
+ end
223
+
224
+ it "should request the correct resource when using all together" do
225
+ user = Dwolla::User.me(oauth_token)
226
+
227
+ stub_get("/contacts?search=Bob&type=Facebook&limit=2&#{token_param}").
228
+ to_return(:body => fixture("contacts.json"))
229
+
230
+ user.contacts(:search => "Bob", :type => "Facebook", :limit => 2)
231
+
232
+ a_get("/contacts?search=Bob&type=Facebook&limit=2&#{token_param}").should have_been_made
233
+ end
234
+
235
+ it "should return the contact users properly" do
236
+ user = Dwolla::User.me(oauth_token)
237
+
238
+ stub_get("/contacts", token_param).
239
+ to_return(:body => fixture("contacts.json"))
240
+
241
+ contacts = user.contacts
242
+
243
+ first_contact = contacts.first
244
+
245
+ first_contact.should be_a Dwolla::User
246
+ first_contact.id.should == "12345"
247
+ first_contact.name.should == "Ben Facebook Test"
248
+ first_contact.image.should == "https://graph.facebook.com/12345/picture?type=square"
249
+ first_contact.contact_type.should == "Facebook"
250
+
251
+ second_contact = contacts.last
252
+
253
+ second_contact.should be_a Dwolla::User
254
+ second_contact.id.should == "812-111-1111"
255
+ second_contact.name.should == "Ben Dwolla Test"
256
+ second_contact.image.should == "https://www.dwolla.com/avatar.aspx?u=812-111-1111"
257
+ second_contact.contact_type.should == "Dwolla"
258
+ end
259
+ end
260
+ end
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "Success": true,
3
+ "Message": "Success",
4
+ "Response": 55.76
5
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "Id": "812-111-1111",
3
+ "Latitude": 41.584546,
4
+ "Longitude": -93.634167,
5
+ "Name": "Test User"
6
+ }
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "Success": false,
3
+ "Message": "Token does not have access to requested resource.",
4
+ "Response": null
5
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "RequestResult": 12345
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "SendResult": 12345
3
+ }
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,10 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ $:.unshift File.expand_path('..', __FILE__)
5
+ $:.unshift File.expand_path('../../lib', __FILE__)
6
+
7
+ require 'dwolla'
8
+ require 'rspec'
9
+ require 'webmock/rspec'
10
+ require 'support/helpers'
@@ -0,0 +1,29 @@
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
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dwolla-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jefferson Girao
9
+ - Michael Schonfeld
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-09-27 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: faraday
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - '='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.7.6
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - '='
29
+ - !ruby/object:Gem::Version
30
+ version: 0.7.6
31
+ - !ruby/object:Gem::Dependency
32
+ name: multi_json
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - '='
37
+ - !ruby/object:Gem::Version
38
+ version: 1.3.6
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.3.6
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: rspec
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: webmock
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ description: Official Ruby Wrapper for Dwolla's API
128
+ email:
129
+ - contato@jefferson.eti.br
130
+ - michael@dwolla.com
131
+ executables: []
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - .gitignore
136
+ - Gemfile
137
+ - README.md
138
+ - Rakefile
139
+ - dwolla.gemspec
140
+ - examples/_keys.rb
141
+ - examples/accountInfo.rb
142
+ - examples/contacts.rb
143
+ - examples/fundingSources.rb
144
+ - examples/oauth.rb
145
+ - examples/offsiteGateway.rb
146
+ - examples/send.rb
147
+ - lib/dwolla.rb
148
+ - lib/dwolla/client.rb
149
+ - lib/dwolla/connection.rb
150
+ - lib/dwolla/exceptions.rb
151
+ - lib/dwolla/funding_source.rb
152
+ - lib/dwolla/response/follow_redirects.rb
153
+ - lib/dwolla/response/guard_server_error.rb
154
+ - lib/dwolla/response/parse_json.rb
155
+ - lib/dwolla/transaction.rb
156
+ - lib/dwolla/user.rb
157
+ - lib/dwolla/version.rb
158
+ - spec/dwolla/client_spec.rb
159
+ - spec/dwolla/response/follow_redirects_spec.rb
160
+ - spec/dwolla/transaction_spec.rb
161
+ - spec/dwolla/user_spec.rb
162
+ - spec/dwolla_spec.rb
163
+ - spec/fixtures/account_information.json
164
+ - spec/fixtures/balance.json
165
+ - spec/fixtures/basic_information.json
166
+ - spec/fixtures/contacts.json
167
+ - spec/fixtures/error.json
168
+ - spec/fixtures/request_transaction.json
169
+ - spec/fixtures/send_transaction.json
170
+ - spec/fixtures/sources.json
171
+ - spec/spec_helper.rb
172
+ - spec/support/helpers.rb
173
+ homepage: https://github.com/dwolla/dwolla-ruby
174
+ licenses: []
175
+ post_install_message:
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ requirements: []
192
+ rubyforge_project: dwolla
193
+ rubygems_version: 1.8.24
194
+ signing_key:
195
+ specification_version: 3
196
+ summary: Official Ruby Wrapper for Dwolla's API
197
+ test_files:
198
+ - spec/dwolla/client_spec.rb
199
+ - spec/dwolla/response/follow_redirects_spec.rb
200
+ - spec/dwolla/transaction_spec.rb
201
+ - spec/dwolla/user_spec.rb
202
+ - spec/dwolla_spec.rb
203
+ - spec/fixtures/account_information.json
204
+ - spec/fixtures/balance.json
205
+ - spec/fixtures/basic_information.json
206
+ - spec/fixtures/contacts.json
207
+ - spec/fixtures/error.json
208
+ - spec/fixtures/request_transaction.json
209
+ - spec/fixtures/send_transaction.json
210
+ - spec/fixtures/sources.json
211
+ - spec/spec_helper.rb
212
+ - spec/support/helpers.rb