dwolla-ruby 2.5.5 → 2.6.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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/README.md +17 -6
- data/dwolla-ruby.gemspec +1 -1
- data/examples/oauth.rb +23 -6
- data/lib/dwolla.rb +18 -18
- data/lib/dwolla/accounts.rb +7 -1
- data/lib/dwolla/contacts.rb +11 -3
- data/lib/dwolla/masspay.rb +53 -0
- data/lib/dwolla/oauth.rb +60 -35
- data/lib/dwolla/offsite_gateway.rb +2 -0
- data/lib/dwolla/transactions.rb +0 -15
- data/lib/dwolla/users.rb +6 -3
- data/lib/dwolla/version.rb +1 -1
- data/test/test_accounts.rb +19 -0
- data/test/test_balance.rb +10 -0
- data/test/test_contacts.rb +20 -0
- data/test/test_funding_sources.rb +65 -0
- data/test/test_masspay.rb +48 -0
- data/test/test_oauth.rb +31 -0
- data/test/test_offsite_gateway.rb +58 -0
- data/test/test_requests.rb +30 -0
- data/test/test_transactions.rb +52 -0
- data/test/test_users.rb +34 -0
- metadata +26 -23
- data/lib/dwolla/register.rb +0 -55
- data/test/test_dwolla.rb +0 -198
- data/test/test_helper.rb +0 -424
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fa2436e7ea681ce8fea9abe309bccee237536ea
|
4
|
+
data.tar.gz: c398209cf8011fc35adacf92c7cb69d1b5746217
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd72ed9f135dec234bc41e405bed7cf0ff47a09e1aa48612d0abdb3eb8ea77b678512865be123af6740a0bd51e16c7cfc1a1751c247d28d98ce483543c6dad94
|
7
|
+
data.tar.gz: 4513c77af15a22339576046eb1ea7d6346f0fba9f65a97d4e9ea488f879e55b39106be2322b931b447252a8008e43f2ee5b37fa20c694014474818ef70e6a08b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
Official Ruby wrapper for Dwolla's API
|
3
3
|
|
4
4
|
## Version
|
5
|
-
2.
|
5
|
+
2.6.0
|
6
|
+
|
7
|
+
[](https://travis-ci.org/Dwolla/dwolla-ruby)
|
6
8
|
|
7
9
|
## Requirements
|
8
10
|
- [Ruby](http://www.ruby-lang.org/)
|
@@ -10,11 +12,11 @@ Official Ruby wrapper for Dwolla's API
|
|
10
12
|
## Installation
|
11
13
|
The easiest way to install the dwolla-ruby gem for now is to use bundler and add the following line to your Gemfile:
|
12
14
|
|
13
|
-
|
15
|
+
`gem 'dwolla-ruby'`
|
14
16
|
|
15
17
|
The recommended way to install dwolla-ruby is through RubyGems:
|
16
18
|
|
17
|
-
|
19
|
+
`gem install dwolla-ruby`
|
18
20
|
|
19
21
|
## Examples / Quickstart
|
20
22
|
|
@@ -23,15 +25,21 @@ To use the examples in the /examples folder, first edit the _keys.rb file and ad
|
|
23
25
|
This repo includes various usage examples, including:
|
24
26
|
|
25
27
|
* Authenticating with OAuth [oauth.rb]
|
26
|
-
* Sending money [send.rb]
|
27
28
|
* Fetching user information [users.rb]
|
28
29
|
* Grabbing a user's contacts [contacts.rb]
|
29
30
|
* Listing a user's funding sources [fundingSources.rb]
|
30
|
-
* Transacting money [transactions.rb]
|
31
|
+
* Transacting money (includes sending) [transactions.rb]
|
31
32
|
* Getting a user's balance [balance.rb]
|
32
33
|
|
33
34
|
## Changelog
|
34
35
|
|
36
|
+
2.6.0
|
37
|
+
|
38
|
+
* **BREAKING CHANGE**: OAuth access tokens now expire. Instead of a string, `Dwolla::OAuth::get_token` now returns a hash with an `access_token`, `refresh_token`, and expiration times in seconds for both. In order to refresh authorization, use `Dwolla::OAuth.refresh_auth`
|
39
|
+
* **BREAKING CHANGE**: Guest send has been officially deprecated and removed from this gem.
|
40
|
+
* All MassPay endpoints have been included in this release for batch payment support.
|
41
|
+
* Proper unit tests implemented for all endpoints.
|
42
|
+
|
35
43
|
2.5.5
|
36
44
|
|
37
45
|
* Pulled in a merge request for syntax error (thanks, @mstahl)
|
@@ -121,8 +129,11 @@ This wrapper is heavily based off Stripe's Ruby Gem
|
|
121
129
|
|
122
130
|
## Support
|
123
131
|
|
132
|
+
We highly recommend seeking support on our forums, [located here!](https://discuss.dwolla.com/category/api-support)
|
133
|
+
|
124
134
|
- Dwolla API <api@dwolla.com>
|
125
|
-
-
|
135
|
+
- David Stancu <david@dwolla.com>
|
136
|
+
- Gordon Zheng <gordon@dwolla.com>
|
126
137
|
|
127
138
|
## References / Documentation
|
128
139
|
|
data/dwolla-ruby.gemspec
CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.homepage = "https://github.com/dwolla/dwolla-ruby"
|
10
10
|
s.summary = %q{Official Ruby Wrapper for Dwolla's API}
|
11
11
|
s.description = %q{Official Ruby Wrapper for Dwolla's API. Completely re-written based on Stripe's Ruby Bindings.}
|
12
|
+
s.license = 'MIT'
|
12
13
|
|
13
14
|
s.rubyforge_project = "dwolla-ruby"
|
14
15
|
|
@@ -21,7 +22,6 @@ Gem::Specification.new do |s|
|
|
21
22
|
s.add_dependency('addressable', '>= 2')
|
22
23
|
|
23
24
|
s.add_development_dependency('mocha')
|
24
|
-
s.add_development_dependency('shoulda')
|
25
25
|
s.add_development_dependency('test-unit')
|
26
26
|
s.add_development_dependency('rake')
|
27
27
|
end
|
data/examples/oauth.rb
CHANGED
@@ -18,17 +18,34 @@ redirect_uri = 'http://localhost:4567/oauth_return'
|
|
18
18
|
# Create an authentication URL
|
19
19
|
# that the user will be redirected to
|
20
20
|
get '/' do
|
21
|
-
|
22
|
-
|
21
|
+
authUrl = Dwolla::OAuth.get_auth_url(redirect_uri)
|
22
|
+
"To begin the OAuth process, send the user off to <a href=\"#{authUrl}\">#{authUrl}</a>"
|
23
23
|
end
|
24
24
|
|
25
25
|
|
26
26
|
# STEP 2:
|
27
27
|
# Exchange the temporary code given
|
28
28
|
# to us in the querystring, for
|
29
|
-
#
|
29
|
+
# an expiring OAuth access token and refresh token pair.
|
30
30
|
get '/oauth_return' do
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
code = params['code']
|
32
|
+
info = Dwolla::OAuth.get_token(code, redirect_uri)
|
33
|
+
token = info['access_token']
|
34
|
+
refresh_token = info['refresh_token']
|
35
|
+
"Your expiring OAuth access token is: <b>#{token}</b>, and your refresh token is <b>#{refresh_token}</b>"
|
34
36
|
end
|
37
|
+
|
38
|
+
# STEP 3:
|
39
|
+
#
|
40
|
+
# The array returned in step 2 as 'info' also contains
|
41
|
+
# expiration times for when the OAuth token will become
|
42
|
+
# invalid. Use this method to refresh your token with
|
43
|
+
# the provided refresh token.
|
44
|
+
#
|
45
|
+
get '/oauth_refresh' do
|
46
|
+
refresh_token = params['refresh_token']
|
47
|
+
info = Dwolla::OAuth.refresh_auth(refresh_token)
|
48
|
+
token = info['access_token']
|
49
|
+
refresh_token = info['refresh_token']
|
50
|
+
"Your expiring OAuth access token is: <b>#{token}</b>, and your refresh token is <b>#{refresh_token}</b>"
|
51
|
+
end
|
data/lib/dwolla.rb
CHANGED
@@ -7,28 +7,28 @@ require 'multi_json'
|
|
7
7
|
require 'addressable/uri'
|
8
8
|
|
9
9
|
# Version
|
10
|
-
|
10
|
+
require_relative 'dwolla/version'
|
11
11
|
|
12
12
|
# Resources
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
require_relative 'dwolla/json'
|
14
|
+
require_relative 'dwolla/transactions'
|
15
|
+
require_relative 'dwolla/requests'
|
16
|
+
require_relative 'dwolla/contacts'
|
17
|
+
require_relative 'dwolla/users'
|
18
|
+
require_relative 'dwolla/balance'
|
19
|
+
require_relative 'dwolla/funding_sources'
|
20
|
+
require_relative 'dwolla/oauth'
|
21
|
+
require_relative 'dwolla/offsite_gateway'
|
22
|
+
require_relative 'dwolla/accounts'
|
23
|
+
require_relative 'dwolla/masspay'
|
24
24
|
|
25
25
|
# Errors
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
require_relative 'dwolla/errors/dwolla_error'
|
27
|
+
require_relative 'dwolla/errors/api_connection_error'
|
28
|
+
require_relative 'dwolla/errors/api_error'
|
29
|
+
require_relative 'dwolla/errors/missing_parameter_error'
|
30
|
+
require_relative 'dwolla/errors/authentication_error'
|
31
|
+
require_relative 'dwolla/errors/invalid_request_error'
|
32
32
|
|
33
33
|
module Dwolla
|
34
34
|
@@api_key = nil
|
data/lib/dwolla/accounts.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
module Dwolla
|
2
2
|
class Accounts
|
3
|
-
def self.
|
3
|
+
def self.get_auto_withdrawal_status(token=nil)
|
4
|
+
url = accounts_url + 'features/auto_withdrawl'
|
5
|
+
|
6
|
+
Dwolla.request(:get, url, {}, {}, token)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.toggle_auto_withdrawl(enabled=true, funding_id=nil, token=nil)
|
4
10
|
raise MissingParameterError.new('No Funding ID Provided.') if funding_id.nil?
|
5
11
|
|
6
12
|
url = accounts_url + 'features/auto_withdrawl'
|
data/lib/dwolla/contacts.rb
CHANGED
@@ -7,10 +7,18 @@ module Dwolla
|
|
7
7
|
end
|
8
8
|
|
9
9
|
|
10
|
-
def self.nearby(filters={})
|
11
|
-
|
10
|
+
def self.nearby(lat=nil, lon=nil, filters={})
|
11
|
+
raise MissingParameterError.new('No Latitude Provided') unless lat
|
12
|
+
raise MissingParameterError.new('No Longitude Provided.') unless lon
|
12
13
|
|
13
|
-
|
14
|
+
url = contacts_url + 'nearby'
|
15
|
+
|
16
|
+
params = {
|
17
|
+
:latitude => lat,
|
18
|
+
:longitude => lon
|
19
|
+
}.merge(filters)
|
20
|
+
|
21
|
+
Dwolla.request(:get, url, params, {}, false)
|
14
22
|
end
|
15
23
|
|
16
24
|
private
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Dwolla
|
2
|
+
class MassPay
|
3
|
+
|
4
|
+
def self.get(token=nil)
|
5
|
+
Dwolla.request(:get, masspay_url, {}, {}, token);
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.create(params={}, token=nil)
|
9
|
+
raise MissingParameterError.new('No fundsSource ID Provided.') unless params[:fundsSource]
|
10
|
+
raise MissingParameterError.new('No PIN Provided.') unless params[:pin]
|
11
|
+
raise MissingParameterError.new('No Items Provided.') unless params[:items]
|
12
|
+
|
13
|
+
Dwolla.request(:post, masspay_url, params, {}, token)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.getItems(id=nil, params={}, token=nil)
|
17
|
+
raise MissingParameterError.new('No MassPay Job ID Provided.') if id.nil?
|
18
|
+
url = masspay_url
|
19
|
+
url += id.to_s unless id.nil?
|
20
|
+
url += '/items'
|
21
|
+
|
22
|
+
Dwolla.request(:get, url, params, {}, token)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.getItem(jobId=nil, itemId=nil, token=nil)
|
26
|
+
raise MissingParameterError.new('No MassPay Job ID Provided.') if jobId.nil?
|
27
|
+
raise MissingParameterError.new('No Item ID Provided.') if itemId.nil?
|
28
|
+
|
29
|
+
url = masspay_url
|
30
|
+
url += jobId.to_s unless jobId.nil?
|
31
|
+
url += '/items/'
|
32
|
+
url += itemId.to_s unless itemId.nil?
|
33
|
+
|
34
|
+
Dwolla.request(:get, url, {}, {}, token)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.getJob(id=nil, token=nil)
|
38
|
+
raise MissingParameterError.new('No MassPay Job ID Provided.') if id.nil?
|
39
|
+
|
40
|
+
url = masspay_url
|
41
|
+
url += id.to_s unless id.nil?
|
42
|
+
|
43
|
+
Dwolla.request(:get, url, {}, {}, token)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def self.masspay_url
|
49
|
+
return '/masspay/'
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/lib/dwolla/oauth.rb
CHANGED
@@ -1,51 +1,76 @@
|
|
1
1
|
module Dwolla
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class OAuth
|
3
|
+
def self.get_auth_url(redirect_uri=nil, scope=Dwolla::scope)
|
4
|
+
raise AuthenticationError.new('No Api Key Provided.') unless Dwolla::api_key
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
params = {
|
7
|
+
:scope => scope,
|
8
|
+
:response_type => 'code',
|
9
|
+
:client_id => Dwolla::api_key
|
10
|
+
}
|
11
11
|
|
12
|
-
|
12
|
+
params['redirect_uri'] = redirect_uri unless redirect_uri.nil?
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
uri = Addressable::URI.new
|
15
|
+
uri.query_values = params
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
if Dwolla::debug and Dwolla::sandbox
|
18
|
+
puts "[DWOLLA SANDBOX MODE OPERATION]"
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
return auth_url + '?' + uri.query
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.get_token(code=nil, redirect_uri=nil)
|
25
|
+
raise MissingParameterError.new('No Code Provided.') if code.nil?
|
26
|
+
|
27
|
+
params = {
|
28
|
+
:grant_type => 'authorization_code',
|
29
|
+
:code => code
|
30
|
+
}
|
31
|
+
|
32
|
+
# I realize this is ugly, but the unit tests fail
|
33
|
+
# if the key is accessed["like_this"] because the
|
34
|
+
# hash is compared with "quotes" and not :like_this.
|
35
|
+
|
36
|
+
# It may very well be my Ruby version
|
37
|
+
# TODO: Revisit this
|
38
|
+
(params = params.merge({:redirect_uri => redirect_uri})) unless redirect_uri.nil?
|
23
39
|
|
24
|
-
|
25
|
-
raise MissingParameterError.new('No Code Provided.') if code.nil?
|
40
|
+
resp = Dwolla.request(:get, token_url, params, {}, false, false, true)
|
26
41
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
42
|
+
# TODO: Revisit this to make it more unit test friendly, fails ['error_description'] due to
|
43
|
+
# key not existing, same on L58
|
44
|
+
return "No data received." unless resp.is_a?(Hash)
|
45
|
+
raise APIError.new(resp['error_description']) unless resp['access_token'] and resp['refresh_token']
|
31
46
|
|
32
|
-
|
47
|
+
return resp
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.refresh_auth(refresh_token=nil)
|
51
|
+
raise MissingParameterError.new('No Refresh Token Provided') if refresh_token.nil?
|
33
52
|
|
34
|
-
|
53
|
+
params = {
|
54
|
+
:grant_type => 'refresh_token',
|
55
|
+
:refresh_token => refresh_token
|
56
|
+
}
|
35
57
|
|
36
|
-
|
58
|
+
resp = Dwolla.request(:get, token_url, params, {}, false, false, true)
|
37
59
|
|
38
|
-
|
39
|
-
|
60
|
+
return "No data received." unless resp.is_a?(Hash)
|
61
|
+
raise APIError.new(resp['error_description']) unless resp.has_key['access_token'] and resp['refresh_token']
|
40
62
|
|
41
|
-
|
63
|
+
return resp
|
64
|
+
end
|
42
65
|
|
43
|
-
|
44
|
-
|
45
|
-
|
66
|
+
private
|
67
|
+
|
68
|
+
def self.auth_url
|
69
|
+
Dwolla.hostname + '/oauth/v2/authenticate'
|
70
|
+
end
|
46
71
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
72
|
+
def self.token_url
|
73
|
+
Dwolla.hostname + '/oauth/v2/token'
|
50
74
|
end
|
51
|
-
end
|
75
|
+
end
|
76
|
+
end
|
@@ -85,6 +85,8 @@ module Dwolla
|
|
85
85
|
}
|
86
86
|
|
87
87
|
resp = Dwolla.request(:post, request_url, params, {}, false, false, true)
|
88
|
+
|
89
|
+
return "No data received." unless resp.is_a?(Hash)
|
88
90
|
raise APIError.new(resp['Message']) unless resp['Result'] == 'Success'
|
89
91
|
|
90
92
|
return checkout_url + resp['CheckoutId']
|
data/lib/dwolla/transactions.rb
CHANGED
@@ -42,21 +42,6 @@ module Dwolla
|
|
42
42
|
Dwolla.request(:post, url, params, {}, token)
|
43
43
|
end
|
44
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
45
|
class << self
|
61
46
|
alias_method :listing, :get
|
62
47
|
alias_method :send, :create
|
data/lib/dwolla/users.rb
CHANGED
@@ -21,10 +21,13 @@ module Dwolla
|
|
21
21
|
self.get(nil, token)
|
22
22
|
end
|
23
23
|
|
24
|
-
def self.nearby(
|
25
|
-
|
24
|
+
def self.nearby(params={})
|
25
|
+
raise MissingParameterError.new('No Latitude Provided') unless params[:latitude]
|
26
|
+
raise MissingParameterError.new('No Longitude Provided') unless params[:longitude]
|
26
27
|
|
27
|
-
|
28
|
+
url = users_url + 'nearby'
|
29
|
+
|
30
|
+
Dwolla.request(:get, url, params, {}, false)
|
28
31
|
end
|
29
32
|
|
30
33
|
private
|
data/lib/dwolla/version.rb
CHANGED