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.
- data/dwolla-ruby.gemspec +16 -21
- data/examples/accountInfo.rb +7 -7
- data/examples/balance.rb +5 -5
- data/examples/contacts.rb +4 -4
- data/examples/fundingSources.rb +4 -4
- data/examples/oauth.rb +6 -7
- data/examples/transactions.rb +32 -0
- data/lib/dwolla.rb +258 -37
- data/lib/dwolla/balance.rb +15 -0
- data/lib/dwolla/contacts.rb +22 -0
- data/lib/dwolla/errors/api_connection_error.rb +4 -0
- data/lib/dwolla/errors/api_error.rb +4 -0
- data/lib/dwolla/errors/authentication_error.rb +4 -0
- data/lib/dwolla/errors/dwolla_error.rb +20 -0
- data/lib/dwolla/errors/invalid_request_error.rb +10 -0
- data/lib/dwolla/errors/missing_parameter_error.rb +4 -0
- data/lib/dwolla/funding_sources.rb +65 -0
- data/lib/dwolla/json.rb +21 -0
- data/lib/dwolla/oauth.rb +43 -0
- data/lib/dwolla/offsite_gateway.rb +76 -0
- data/lib/dwolla/requests.rb +56 -0
- data/lib/dwolla/transactions.rb +60 -0
- data/lib/dwolla/users.rb +36 -0
- data/lib/dwolla/version.rb +1 -1
- metadata +37 -108
- data/Gemfile +0 -4
- data/examples/send.rb +0 -23
- data/lib/dwolla/client.rb +0 -56
- data/lib/dwolla/connection.rb +0 -47
- data/lib/dwolla/funding_source.rb +0 -18
- data/lib/dwolla/response/follow_redirects.rb +0 -44
- data/lib/dwolla/response/guard_server_error.rb +0 -32
- data/lib/dwolla/response/parse_json.rb +0 -27
- data/lib/dwolla/transaction.rb +0 -56
- data/lib/dwolla/user.rb +0 -121
- data/spec/dwolla/client_spec.rb +0 -51
- data/spec/dwolla/funding_source_spec.rb +0 -59
- data/spec/dwolla/response/follow_redirects_spec.rb +0 -38
- data/spec/dwolla/transaction_spec.rb +0 -212
- data/spec/dwolla/user_spec.rb +0 -292
- data/spec/dwolla_spec.rb +0 -19
- data/spec/fixtures/account_information.json +0 -13
- data/spec/fixtures/add_funding_source.json +0 -11
- data/spec/fixtures/balance.json +0 -5
- data/spec/fixtures/basic_information.json +0 -6
- data/spec/fixtures/contacts.json +0 -18
- data/spec/fixtures/error.json +0 -5
- data/spec/fixtures/register.json +0 -9
- data/spec/fixtures/request_transaction.json +0 -3
- data/spec/fixtures/send_transaction.json +0 -3
- data/spec/fixtures/sources.json +0 -13
- data/spec/spec_helper.rb +0 -10
- data/spec/support/helpers.rb +0 -29
data/lib/dwolla/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dwolla-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,32 +9,16 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - '='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 0.7.6
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - '='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.7.6
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: multi_json
|
15
|
+
name: rest-client
|
32
16
|
requirement: !ruby/object:Gem::Requirement
|
33
17
|
none: false
|
34
18
|
requirements:
|
35
19
|
- - ~>
|
36
20
|
- !ruby/object:Gem::Version
|
37
|
-
version: '1.
|
21
|
+
version: '1.4'
|
38
22
|
type: :runtime
|
39
23
|
prerelease: false
|
40
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,73 +26,47 @@ dependencies:
|
|
42
26
|
requirements:
|
43
27
|
- - ~>
|
44
28
|
- !ruby/object:Gem::Version
|
45
|
-
version: '1.
|
29
|
+
version: '1.4'
|
46
30
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
31
|
+
name: multi_json
|
48
32
|
requirement: !ruby/object:Gem::Requirement
|
49
33
|
none: false
|
50
34
|
requirements:
|
51
35
|
- - ! '>='
|
52
36
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
37
|
+
version: 1.0.4
|
38
|
+
- - <
|
60
39
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
|
63
|
-
name: rake
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :development
|
40
|
+
version: '2'
|
41
|
+
type: :runtime
|
71
42
|
prerelease: false
|
72
43
|
version_requirements: !ruby/object:Gem::Requirement
|
73
44
|
none: false
|
74
45
|
requirements:
|
75
46
|
- - ! '>='
|
76
47
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
78
|
-
-
|
79
|
-
name: rspec
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ! '>='
|
48
|
+
version: 1.0.4
|
49
|
+
- - <
|
84
50
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
51
|
+
version: '2'
|
94
52
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
53
|
+
name: addressable
|
96
54
|
requirement: !ruby/object:Gem::Requirement
|
97
55
|
none: false
|
98
56
|
requirements:
|
99
57
|
- - ! '>='
|
100
58
|
- !ruby/object:Gem::Version
|
101
|
-
version: '
|
102
|
-
type: :
|
59
|
+
version: '2'
|
60
|
+
type: :runtime
|
103
61
|
prerelease: false
|
104
62
|
version_requirements: !ruby/object:Gem::Requirement
|
105
63
|
none: false
|
106
64
|
requirements:
|
107
65
|
- - ! '>='
|
108
66
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
67
|
+
version: '2'
|
110
68
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
69
|
+
name: rake
|
112
70
|
requirement: !ruby/object:Gem::Requirement
|
113
71
|
none: false
|
114
72
|
requirements:
|
@@ -123,7 +81,8 @@ dependencies:
|
|
123
81
|
- - ! '>='
|
124
82
|
- !ruby/object:Gem::Version
|
125
83
|
version: '0'
|
126
|
-
description: Official Ruby Wrapper for Dwolla's API
|
84
|
+
description: Official Ruby Wrapper for Dwolla's API. Completely re-written based on
|
85
|
+
Stripe's Ruby Bindings.
|
127
86
|
email:
|
128
87
|
- michael@dwolla.com
|
129
88
|
executables: []
|
@@ -131,7 +90,6 @@ extensions: []
|
|
131
90
|
extra_rdoc_files: []
|
132
91
|
files:
|
133
92
|
- .gitignore
|
134
|
-
- Gemfile
|
135
93
|
- README.md
|
136
94
|
- Rakefile
|
137
95
|
- dwolla-ruby.gemspec
|
@@ -142,36 +100,25 @@ files:
|
|
142
100
|
- examples/fundingSources.rb
|
143
101
|
- examples/oauth.rb
|
144
102
|
- examples/offsiteGateway.rb
|
145
|
-
- examples/
|
103
|
+
- examples/transactions.rb
|
146
104
|
- lib/dwolla.rb
|
147
|
-
- lib/dwolla/
|
148
|
-
- lib/dwolla/
|
105
|
+
- lib/dwolla/balance.rb
|
106
|
+
- lib/dwolla/contacts.rb
|
107
|
+
- lib/dwolla/errors/api_connection_error.rb
|
108
|
+
- lib/dwolla/errors/api_error.rb
|
109
|
+
- lib/dwolla/errors/authentication_error.rb
|
110
|
+
- lib/dwolla/errors/dwolla_error.rb
|
111
|
+
- lib/dwolla/errors/invalid_request_error.rb
|
112
|
+
- lib/dwolla/errors/missing_parameter_error.rb
|
149
113
|
- lib/dwolla/exceptions.rb
|
150
|
-
- lib/dwolla/
|
151
|
-
- lib/dwolla/
|
152
|
-
- lib/dwolla/
|
153
|
-
- lib/dwolla/
|
154
|
-
- lib/dwolla/
|
155
|
-
- lib/dwolla/
|
114
|
+
- lib/dwolla/funding_sources.rb
|
115
|
+
- lib/dwolla/json.rb
|
116
|
+
- lib/dwolla/oauth.rb
|
117
|
+
- lib/dwolla/offsite_gateway.rb
|
118
|
+
- lib/dwolla/requests.rb
|
119
|
+
- lib/dwolla/transactions.rb
|
120
|
+
- lib/dwolla/users.rb
|
156
121
|
- lib/dwolla/version.rb
|
157
|
-
- spec/dwolla/client_spec.rb
|
158
|
-
- spec/dwolla/funding_source_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/add_funding_source.json
|
165
|
-
- spec/fixtures/balance.json
|
166
|
-
- spec/fixtures/basic_information.json
|
167
|
-
- spec/fixtures/contacts.json
|
168
|
-
- spec/fixtures/error.json
|
169
|
-
- spec/fixtures/register.json
|
170
|
-
- spec/fixtures/request_transaction.json
|
171
|
-
- spec/fixtures/send_transaction.json
|
172
|
-
- spec/fixtures/sources.json
|
173
|
-
- spec/spec_helper.rb
|
174
|
-
- spec/support/helpers.rb
|
175
122
|
homepage: https://github.com/dwolla/dwolla-ruby
|
176
123
|
licenses: []
|
177
124
|
post_install_message:
|
@@ -196,22 +143,4 @@ rubygems_version: 1.8.24
|
|
196
143
|
signing_key:
|
197
144
|
specification_version: 3
|
198
145
|
summary: Official Ruby Wrapper for Dwolla's API
|
199
|
-
test_files:
|
200
|
-
- spec/dwolla/client_spec.rb
|
201
|
-
- spec/dwolla/funding_source_spec.rb
|
202
|
-
- spec/dwolla/response/follow_redirects_spec.rb
|
203
|
-
- spec/dwolla/transaction_spec.rb
|
204
|
-
- spec/dwolla/user_spec.rb
|
205
|
-
- spec/dwolla_spec.rb
|
206
|
-
- spec/fixtures/account_information.json
|
207
|
-
- spec/fixtures/add_funding_source.json
|
208
|
-
- spec/fixtures/balance.json
|
209
|
-
- spec/fixtures/basic_information.json
|
210
|
-
- spec/fixtures/contacts.json
|
211
|
-
- spec/fixtures/error.json
|
212
|
-
- spec/fixtures/register.json
|
213
|
-
- spec/fixtures/request_transaction.json
|
214
|
-
- spec/fixtures/send_transaction.json
|
215
|
-
- spec/fixtures/sources.json
|
216
|
-
- spec/spec_helper.rb
|
217
|
-
- spec/support/helpers.rb
|
146
|
+
test_files: []
|
data/Gemfile
DELETED
data/examples/send.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# Include the Dwolla gem
|
2
|
-
require 'rubygems'
|
3
|
-
require 'pp'
|
4
|
-
require '../lib/dwolla'
|
5
|
-
|
6
|
-
# Include any required keys
|
7
|
-
require '_keys.rb'
|
8
|
-
|
9
|
-
# Instantiate a new Dwolla User client
|
10
|
-
# And, Sseed a previously generated access token
|
11
|
-
DwollaUser = Dwolla::User.me($token)
|
12
|
-
|
13
|
-
|
14
|
-
# EXAMPLE 1:
|
15
|
-
# Send money ($1.00) to a Dwolla ID
|
16
|
-
transactionId = DwollaUser.send_money_to('812-626-8794', 1.00, $pin)
|
17
|
-
pp transactionId
|
18
|
-
|
19
|
-
|
20
|
-
# EXAMPLE 2:
|
21
|
-
# Send money ($1.00) to an email address, with a note
|
22
|
-
transactionId = DwollaUser.send_money_to('michael@dwolla.com', 1.00, $pin, 'Email', 'Everyone loves getting money')
|
23
|
-
pp transactionId
|
data/lib/dwolla/client.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class Client
|
3
|
-
include Dwolla::Connection
|
4
|
-
|
5
|
-
def initialize(client, secret)
|
6
|
-
@client, @secret = client, secret
|
7
|
-
end
|
8
|
-
|
9
|
-
def user(id)
|
10
|
-
user_attributes_hash = get("users/#{id}")
|
11
|
-
User.new(user_attributes_hash)
|
12
|
-
end
|
13
|
-
|
14
|
-
def register_user(user_attributes_hash)
|
15
|
-
params = auth_params.merge(user_attributes_hash)
|
16
|
-
|
17
|
-
returned_user_hash = post("register/", params)
|
18
|
-
User.new(returned_user_hash)
|
19
|
-
end
|
20
|
-
|
21
|
-
def auth_url(redirect_uri=nil, scope='send|transactions|balance|request|contacts|accountinfofull|funding')
|
22
|
-
params = {
|
23
|
-
'scope' => scope,
|
24
|
-
'response_type' => 'code',
|
25
|
-
'client_id' => @client
|
26
|
-
}
|
27
|
-
unless redirect_uri.nil?
|
28
|
-
params['redirect_uri'] = redirect_uri
|
29
|
-
end
|
30
|
-
querystring = params.map{|k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&")
|
31
|
-
|
32
|
-
return 'https://www.dwolla.com/oauth/v2/authenticate?' + querystring
|
33
|
-
end
|
34
|
-
|
35
|
-
def request_token(code, redirect_uri=nil)
|
36
|
-
params = {
|
37
|
-
'client_id' => @client,
|
38
|
-
'client_secret' => @secret,
|
39
|
-
'grant_type' => 'authorization_code',
|
40
|
-
'code' => code
|
41
|
-
}
|
42
|
-
unless redirect_uri.nil?
|
43
|
-
params['redirect_uri'] = redirect_uri
|
44
|
-
end
|
45
|
-
|
46
|
-
resp = get('https://www.dwolla.com/oauth/v2/token', params)
|
47
|
-
|
48
|
-
return resp['access_token']
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
def auth_params
|
53
|
-
{ :client_id => @client, :client_secret => @secret }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/lib/dwolla/connection.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
module Dwolla
|
2
|
-
module Connection
|
3
|
-
private
|
4
|
-
def connection
|
5
|
-
default_options = {
|
6
|
-
:headers => {
|
7
|
-
:accept => 'application/json',
|
8
|
-
:content_type => 'application/json',
|
9
|
-
:user_agent => Dwolla.user_agent,
|
10
|
-
}
|
11
|
-
}
|
12
|
-
|
13
|
-
@connection ||= Faraday.new(Dwolla.endpoint, default_options) do |builder|
|
14
|
-
builder.use Dwolla::Response::FollowRedirects
|
15
|
-
builder.use Dwolla::Response::ParseJson
|
16
|
-
builder.use Dwolla::Response::GuardServerError
|
17
|
-
|
18
|
-
builder.use Faraday::Request::UrlEncoded
|
19
|
-
|
20
|
-
builder.response :logger if Dwolla.debugging?
|
21
|
-
builder.adapter Faraday.default_adapter
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def get(path, params={})
|
26
|
-
request(:get, path, params)
|
27
|
-
end
|
28
|
-
|
29
|
-
def post(path, params={})
|
30
|
-
request(:post, path, params)
|
31
|
-
end
|
32
|
-
|
33
|
-
def request(method, path, params)
|
34
|
-
response = connection.send(method) do |request|
|
35
|
-
case method.to_sym
|
36
|
-
when :delete, :get
|
37
|
-
request.url(path, params.merge(auth_params))
|
38
|
-
when :post
|
39
|
-
request.path = path
|
40
|
-
params.merge!(auth_params) if auth_params
|
41
|
-
request.body = MultiJson.dump(params) unless params.empty?
|
42
|
-
end
|
43
|
-
end
|
44
|
-
response.body
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Dwolla
|
2
|
-
class FundingSource
|
3
|
-
attr_accessor :id, :name, :type, :verified
|
4
|
-
def verified?
|
5
|
-
!!verified
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.from_json(options)
|
9
|
-
source = FundingSource.new
|
10
|
-
source.id = options["Id"]
|
11
|
-
source.name = options["Name"]
|
12
|
-
source.type = options["Type"]
|
13
|
-
source.verified = options["Verified"]
|
14
|
-
source
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Dwolla
|
2
|
-
module Response
|
3
|
-
class RedirectLimitReached < Faraday::Error::ClientError
|
4
|
-
attr_reader :response
|
5
|
-
|
6
|
-
def initialize(response)
|
7
|
-
super "too many redirects; last one to: #{response['location']}"
|
8
|
-
@response = response
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class FollowRedirects < Faraday::Middleware
|
13
|
-
REDIRECTS = [301, 302, 303, 307]
|
14
|
-
# default value for max redirects followed
|
15
|
-
FOLLOW_LIMIT = 3
|
16
|
-
|
17
|
-
def initialize(app, options = {})
|
18
|
-
super(app)
|
19
|
-
@options = options
|
20
|
-
@follow_limit = options[:limit] || FOLLOW_LIMIT
|
21
|
-
end
|
22
|
-
|
23
|
-
def call(env)
|
24
|
-
process_response(@app.call(env), @follow_limit)
|
25
|
-
end
|
26
|
-
|
27
|
-
def process_response(response, follows)
|
28
|
-
response.on_complete do |env|
|
29
|
-
if redirect? response
|
30
|
-
raise RedirectLimitReached, response if follows.zero?
|
31
|
-
env[:url] += response['location']
|
32
|
-
env[:method] = :get
|
33
|
-
response = process_response(@app.call(env), follows - 1)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
response
|
37
|
-
end
|
38
|
-
|
39
|
-
def redirect?(response)
|
40
|
-
REDIRECTS.include? response.status
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Dwolla
|
2
|
-
module Response
|
3
|
-
class InternalServerError < Faraday::Error::ClientError
|
4
|
-
attr_reader :response
|
5
|
-
|
6
|
-
def initialize(response)
|
7
|
-
super "Internal Server Error"
|
8
|
-
@response = response
|
9
|
-
end
|
10
|
-
end
|
11
|
-
class AccessDeniedError < Faraday::Error::ClientError
|
12
|
-
attr_reader :response
|
13
|
-
|
14
|
-
def initialize(response)
|
15
|
-
super "Access was denied."
|
16
|
-
@response = response
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class GuardServerError < Faraday::Response::Middleware
|
21
|
-
def on_complete(env)
|
22
|
-
if env[:status] == 500
|
23
|
-
if env[:body].match /Access is denied/
|
24
|
-
raise AccessDeniedError, env[:body]
|
25
|
-
else
|
26
|
-
raise InternalServerError, env[:body]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|