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.
- checksums.yaml +5 -13
- data/.gitignore +8 -8
- data/.travis.yml +7 -7
- data/Gemfile +1 -1
- data/README.md +154 -138
- data/Rakefile +8 -8
- data/dwolla-ruby.gemspec +27 -27
- data/examples/balance.rb +15 -15
- data/examples/contacts.rb +32 -32
- data/examples/fundingSources.rb +39 -39
- data/examples/oauth.rb +34 -34
- data/examples/offsiteGateway.rb +31 -31
- data/examples/transactions.rb +38 -38
- data/examples/users.rb +30 -30
- data/gemfiles/json.gemfile +2 -2
- data/lib/dwolla.rb +326 -326
- data/lib/dwolla/accounts.rb +21 -21
- data/lib/dwolla/balance.rb +15 -15
- data/lib/dwolla/contacts.rb +22 -22
- data/lib/dwolla/errors/api_connection_error.rb +3 -3
- data/lib/dwolla/errors/api_error.rb +3 -3
- data/lib/dwolla/errors/authentication_error.rb +3 -3
- data/lib/dwolla/errors/dwolla_error.rb +19 -19
- data/lib/dwolla/errors/invalid_request_error.rb +10 -10
- data/lib/dwolla/errors/missing_parameter_error.rb +3 -3
- data/lib/dwolla/exceptions.rb +4 -4
- data/lib/dwolla/funding_sources.rb +65 -65
- data/lib/dwolla/json.rb +20 -20
- data/lib/dwolla/oauth.rb +51 -51
- data/lib/dwolla/offsite_gateway.rb +152 -144
- data/lib/dwolla/register.rb +55 -55
- data/lib/dwolla/requests.rb +56 -56
- data/lib/dwolla/transactions.rb +71 -71
- data/lib/dwolla/users.rb +36 -36
- data/lib/dwolla/version.rb +3 -3
- data/test/test_dwolla.rb +197 -197
- data/test/test_helper.rb +423 -423
- metadata +17 -18
data/lib/dwolla/accounts.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class Accounts
|
3
|
-
def self.auto_withdrawl(enabled=true, funding_id=nil, token=nil)
|
4
|
-
raise MissingParameterError.new('No Funding ID Provided.') if funding_id.nil?
|
5
|
-
|
6
|
-
url = accounts_url + 'features/auto_withdrawl'
|
7
|
-
params = {
|
8
|
-
:enabled => enabled,
|
9
|
-
:fundingId => funding_id
|
10
|
-
}
|
11
|
-
|
12
|
-
Dwolla.request(:post, url, params, {}, token)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def self.accounts_url
|
18
|
-
return '/accounts/'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
class Accounts
|
3
|
+
def self.auto_withdrawl(enabled=true, funding_id=nil, token=nil)
|
4
|
+
raise MissingParameterError.new('No Funding ID Provided.') if funding_id.nil?
|
5
|
+
|
6
|
+
url = accounts_url + 'features/auto_withdrawl'
|
7
|
+
params = {
|
8
|
+
:enabled => enabled,
|
9
|
+
:fundingId => funding_id
|
10
|
+
}
|
11
|
+
|
12
|
+
Dwolla.request(:post, url, params, {}, token)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.accounts_url
|
18
|
+
return '/accounts/'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/dwolla/balance.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class Balance
|
3
|
-
def self.get(token=nil)
|
4
|
-
url = balance_url
|
5
|
-
|
6
|
-
Dwolla.request(:get, url, {}, {}, token)
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def self.balance_url
|
12
|
-
return '/balance/'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
class Balance
|
3
|
+
def self.get(token=nil)
|
4
|
+
url = balance_url
|
5
|
+
|
6
|
+
Dwolla.request(:get, url, {}, {}, token)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def self.balance_url
|
12
|
+
return '/balance/'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/dwolla/contacts.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class Contacts
|
3
|
-
def self.get(filters={}, token=nil)
|
4
|
-
url = contacts_url
|
5
|
-
|
6
|
-
Dwolla.request(:get, url, filters, {}, token)
|
7
|
-
end
|
8
|
-
|
9
|
-
|
10
|
-
def self.nearby(filters={})
|
11
|
-
url = contacts_url + 'nearby'
|
12
|
-
|
13
|
-
Dwolla.request(:get, url, filters, {}, false)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def self.contacts_url
|
19
|
-
return '/contacts/'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
class Contacts
|
3
|
+
def self.get(filters={}, token=nil)
|
4
|
+
url = contacts_url
|
5
|
+
|
6
|
+
Dwolla.request(:get, url, filters, {}, token)
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def self.nearby(filters={})
|
11
|
+
url = contacts_url + 'nearby'
|
12
|
+
|
13
|
+
Dwolla.request(:get, url, filters, {}, false)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.contacts_url
|
19
|
+
return '/contacts/'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class APIConnectionError < DwollaError
|
3
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
class APIConnectionError < DwollaError
|
3
|
+
end
|
4
4
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class APIError < DwollaError
|
3
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
class APIError < DwollaError
|
3
|
+
end
|
4
4
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class AuthenticationError < DwollaError
|
3
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
class AuthenticationError < DwollaError
|
3
|
+
end
|
4
4
|
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class DwollaError < StandardError
|
3
|
-
attr_reader :message
|
4
|
-
attr_reader :http_status
|
5
|
-
attr_reader :http_body
|
6
|
-
attr_reader :json_body
|
7
|
-
|
8
|
-
def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil)
|
9
|
-
@message = message
|
10
|
-
@http_status = http_status
|
11
|
-
@http_body = http_body
|
12
|
-
@json_body = json_body
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_s
|
16
|
-
status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
|
17
|
-
"#{status_string}#{@message}"
|
18
|
-
end
|
19
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
class DwollaError < StandardError
|
3
|
+
attr_reader :message
|
4
|
+
attr_reader :http_status
|
5
|
+
attr_reader :http_body
|
6
|
+
attr_reader :json_body
|
7
|
+
|
8
|
+
def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil)
|
9
|
+
@message = message
|
10
|
+
@http_status = http_status
|
11
|
+
@http_body = http_body
|
12
|
+
@json_body = json_body
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
|
17
|
+
"#{status_string}#{@message}"
|
18
|
+
end
|
19
|
+
end
|
20
20
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class InvalidRequestError < DwollaError
|
3
|
-
attr_accessor :param
|
4
|
-
|
5
|
-
def initialize(message, param, http_status=nil, http_body=nil, json_body=nil)
|
6
|
-
super(message, http_status, http_body, json_body)
|
7
|
-
@param = param
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
class InvalidRequestError < DwollaError
|
3
|
+
attr_accessor :param
|
4
|
+
|
5
|
+
def initialize(message, param, http_status=nil, http_body=nil, json_body=nil)
|
6
|
+
super(message, http_status, http_body, json_body)
|
7
|
+
@param = param
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class MissingParameterError < DwollaError
|
3
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
class MissingParameterError < DwollaError
|
3
|
+
end
|
4
4
|
end
|
data/lib/dwolla/exceptions.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class RequestException < Exception
|
3
|
-
end
|
4
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
class RequestException < Exception
|
3
|
+
end
|
4
|
+
end
|
@@ -1,65 +1,65 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class FundingSources
|
3
|
-
def self.get(id=nil, token=nil)
|
4
|
-
url = funding_sources_url
|
5
|
-
|
6
|
-
url += id.to_s unless id.nil?
|
7
|
-
|
8
|
-
Dwolla.request(:get, url, {}, {}, token)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.withdraw(id=nil, params={}, token=nil)
|
12
|
-
raise MissingParameterError.new('No Funding Source ID Provided.') if id.nil?
|
13
|
-
raise MissingParameterError.new('No PIN Provided.') unless params[:pin]
|
14
|
-
raise MissingParameterError.new('No Amount Provided.') unless params[:amount]
|
15
|
-
|
16
|
-
url = funding_sources_url
|
17
|
-
url += id.to_s + '/withdraw'
|
18
|
-
|
19
|
-
Dwolla.request(:post, url, params, {}, token)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.deposit(id=nil, params={}, token=nil)
|
23
|
-
raise MissingParameterError.new('No Funding Source ID Provided.') if id.nil?
|
24
|
-
raise MissingParameterError.new('No PIN Provided.') unless params[:pin]
|
25
|
-
raise MissingParameterError.new('No Amount Provided.') unless params[:amount]
|
26
|
-
|
27
|
-
url = funding_sources_url
|
28
|
-
url += id.to_s + '/deposit'
|
29
|
-
|
30
|
-
Dwolla.request(:post, url, params, {}, token)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.add(params={}, token=nil)
|
34
|
-
raise MissingParameterError.new('No Account Number Provided.') unless params[:account_number]
|
35
|
-
raise MissingParameterError.new('No Routing Number (ABA) Provided.') unless params[:routing_number]
|
36
|
-
raise MissingParameterError.new('No Account Type Provided.') unless params[:account_type]
|
37
|
-
raise MissingParameterError.new('No Account Name Provided.') unless params[:name]
|
38
|
-
|
39
|
-
url = funding_sources_url
|
40
|
-
|
41
|
-
Dwolla.request(:post, url, params, {}, token)
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.verify(id=nil, params={}, token=nil)
|
45
|
-
raise MissingParameterError.new('No Funding Source ID Provided.') if id.nil?
|
46
|
-
raise MissingParameterError.new('No Deposit 1 Amount Provided.') unless params[:deposit1]
|
47
|
-
raise MissingParameterError.new('No Deposit 2 Amount Provided.') unless params[:deposit2]
|
48
|
-
|
49
|
-
url = funding_sources_url
|
50
|
-
url += id.to_s + '/verify'
|
51
|
-
|
52
|
-
Dwolla.request(:post, url, params, {}, token)
|
53
|
-
end
|
54
|
-
|
55
|
-
class << self
|
56
|
-
alias_method :listing, :get
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def self.funding_sources_url
|
62
|
-
return '/fundingsources/'
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
class FundingSources
|
3
|
+
def self.get(id=nil, token=nil)
|
4
|
+
url = funding_sources_url
|
5
|
+
|
6
|
+
url += id.to_s unless id.nil?
|
7
|
+
|
8
|
+
Dwolla.request(:get, url, {}, {}, token)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.withdraw(id=nil, params={}, token=nil)
|
12
|
+
raise MissingParameterError.new('No Funding Source ID Provided.') if id.nil?
|
13
|
+
raise MissingParameterError.new('No PIN Provided.') unless params[:pin]
|
14
|
+
raise MissingParameterError.new('No Amount Provided.') unless params[:amount]
|
15
|
+
|
16
|
+
url = funding_sources_url
|
17
|
+
url += id.to_s + '/withdraw'
|
18
|
+
|
19
|
+
Dwolla.request(:post, url, params, {}, token)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.deposit(id=nil, params={}, token=nil)
|
23
|
+
raise MissingParameterError.new('No Funding Source ID Provided.') if id.nil?
|
24
|
+
raise MissingParameterError.new('No PIN Provided.') unless params[:pin]
|
25
|
+
raise MissingParameterError.new('No Amount Provided.') unless params[:amount]
|
26
|
+
|
27
|
+
url = funding_sources_url
|
28
|
+
url += id.to_s + '/deposit'
|
29
|
+
|
30
|
+
Dwolla.request(:post, url, params, {}, token)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.add(params={}, token=nil)
|
34
|
+
raise MissingParameterError.new('No Account Number Provided.') unless params[:account_number]
|
35
|
+
raise MissingParameterError.new('No Routing Number (ABA) Provided.') unless params[:routing_number]
|
36
|
+
raise MissingParameterError.new('No Account Type Provided.') unless params[:account_type]
|
37
|
+
raise MissingParameterError.new('No Account Name Provided.') unless params[:name]
|
38
|
+
|
39
|
+
url = funding_sources_url
|
40
|
+
|
41
|
+
Dwolla.request(:post, url, params, {}, token)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.verify(id=nil, params={}, token=nil)
|
45
|
+
raise MissingParameterError.new('No Funding Source ID Provided.') if id.nil?
|
46
|
+
raise MissingParameterError.new('No Deposit 1 Amount Provided.') unless params[:deposit1]
|
47
|
+
raise MissingParameterError.new('No Deposit 2 Amount Provided.') unless params[:deposit2]
|
48
|
+
|
49
|
+
url = funding_sources_url
|
50
|
+
url += id.to_s + '/verify'
|
51
|
+
|
52
|
+
Dwolla.request(:post, url, params, {}, token)
|
53
|
+
end
|
54
|
+
|
55
|
+
class << self
|
56
|
+
alias_method :listing, :get
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def self.funding_sources_url
|
62
|
+
return '/fundingsources/'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/dwolla/json.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
module Dwolla
|
2
|
-
module JSON
|
3
|
-
if MultiJson.respond_to?(:dump)
|
4
|
-
def self.dump(*args)
|
5
|
-
MultiJson.dump(*args)
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.load(*args)
|
9
|
-
MultiJson.load(*args)
|
10
|
-
end
|
11
|
-
else
|
12
|
-
def self.dump(*args)
|
13
|
-
MultiJson.encode(*args)
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.load(*args)
|
17
|
-
MultiJson.decode(*args)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
module Dwolla
|
2
|
+
module JSON
|
3
|
+
if MultiJson.respond_to?(:dump)
|
4
|
+
def self.dump(*args)
|
5
|
+
MultiJson.dump(*args)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.load(*args)
|
9
|
+
MultiJson.load(*args)
|
10
|
+
end
|
11
|
+
else
|
12
|
+
def self.dump(*args)
|
13
|
+
MultiJson.encode(*args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.load(*args)
|
17
|
+
MultiJson.decode(*args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
21
|
end
|
data/lib/dwolla/oauth.rb
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
-
module Dwolla
|
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
|
-
|
6
|
-
params = {
|
7
|
-
:scope => scope,
|
8
|
-
:response_type => 'code',
|
9
|
-
:client_id => Dwolla::api_key
|
10
|
-
}
|
11
|
-
|
12
|
-
params['redirect_uri'] = redirect_uri unless redirect_uri.nil?
|
13
|
-
|
14
|
-
uri = Addressable::URI.new
|
15
|
-
uri.query_values = params
|
16
|
-
|
17
|
-
if Dwolla::debug and Dwolla::sandbox
|
18
|
-
puts "[DWOLLA SANDBOX MODE OPERATION]"
|
19
|
-
end
|
20
|
-
|
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
|
-
params['redirect_uri'] = redirect_uri unless redirect_uri.nil?
|
33
|
-
|
34
|
-
resp = Dwolla.request(:get, token_url, params, {}, false, false, true)
|
35
|
-
|
36
|
-
raise APIError.new(resp['error_description']) unless resp['access_token']
|
37
|
-
|
38
|
-
return resp['access_token']
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def self.auth_url
|
44
|
-
Dwolla.hostname + '/oauth/v2/authenticate'
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.token_url
|
48
|
-
Dwolla.hostname + '/oauth/v2/token'
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
1
|
+
module Dwolla
|
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
|
+
|
6
|
+
params = {
|
7
|
+
:scope => scope,
|
8
|
+
:response_type => 'code',
|
9
|
+
:client_id => Dwolla::api_key
|
10
|
+
}
|
11
|
+
|
12
|
+
params['redirect_uri'] = redirect_uri unless redirect_uri.nil?
|
13
|
+
|
14
|
+
uri = Addressable::URI.new
|
15
|
+
uri.query_values = params
|
16
|
+
|
17
|
+
if Dwolla::debug and Dwolla::sandbox
|
18
|
+
puts "[DWOLLA SANDBOX MODE OPERATION]"
|
19
|
+
end
|
20
|
+
|
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
|
+
params['redirect_uri'] = redirect_uri unless redirect_uri.nil?
|
33
|
+
|
34
|
+
resp = Dwolla.request(:get, token_url, params, {}, false, false, true)
|
35
|
+
|
36
|
+
raise APIError.new(resp['error_description']) unless resp['access_token']
|
37
|
+
|
38
|
+
return resp['access_token']
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def self.auth_url
|
44
|
+
Dwolla.hostname + '/oauth/v2/authenticate'
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.token_url
|
48
|
+
Dwolla.hostname + '/oauth/v2/token'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|