gocardless 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/lib/gocardless/client.rb +16 -5
- data/lib/gocardless/version.rb +1 -1
- data/spec/client_spec.rb +15 -13
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 1.2.1 - July 11, 2012
|
2
|
+
|
3
|
+
- Fix bug which caused Client#merchant to fail after #fetch_access_token was
|
4
|
+
called during the merchant authorization flow (this only concerns partners).
|
5
|
+
|
1
6
|
## 1.2.0 - June 19, 2012
|
2
7
|
|
3
8
|
- Add some extra attributes to resources (e.g. status, merchant's balance, etc)
|
data/lib/gocardless/client.rb
CHANGED
@@ -45,6 +45,7 @@ module GoCardless
|
|
45
45
|
end
|
46
46
|
|
47
47
|
# Generate the OAuth authorize url
|
48
|
+
#
|
48
49
|
# @param [Hash] options parameters to be included in the url.
|
49
50
|
# +:redirect_uri+ is required.
|
50
51
|
# @return [String] the authorize url
|
@@ -61,12 +62,19 @@ module GoCardless
|
|
61
62
|
end
|
62
63
|
alias :new_merchant_url :authorize_url
|
63
64
|
|
64
|
-
#
|
65
|
+
# Exchange the authorization code for an access token
|
66
|
+
#
|
65
67
|
# @param [String] auth_code to exchange for the access_token
|
66
68
|
# @return [String] the access_token required to make API calls to resources
|
67
69
|
def fetch_access_token(auth_code, options)
|
68
70
|
raise ArgumentError, ':redirect_uri required' unless options[:redirect_uri]
|
71
|
+
# Exchange the auth code for an access token
|
69
72
|
@access_token = @oauth_client.auth_code.get_token(auth_code, options)
|
73
|
+
|
74
|
+
# Use the scope to figure out which merchant we're managing
|
75
|
+
scope = @access_token.params[:scope] || @access_token.params['scope']
|
76
|
+
set_merchant_id_from_scope(scope)
|
77
|
+
|
70
78
|
self.access_token
|
71
79
|
end
|
72
80
|
|
@@ -89,10 +97,7 @@ module GoCardless
|
|
89
97
|
@access_token = OAuth2::AccessToken.new(@oauth_client, token)
|
90
98
|
@access_token.params['scope'] = scope
|
91
99
|
|
92
|
-
unless @merchant_id
|
93
|
-
perm = scope.split.select {|p| p.start_with?('manage_merchant:') }.first
|
94
|
-
@merchant_id = perm.split(':')[1] if perm
|
95
|
-
end
|
100
|
+
set_merchant_id_from_scope(scope) unless @merchant_id
|
96
101
|
end
|
97
102
|
|
98
103
|
# Issue an GET request to the API server
|
@@ -272,6 +277,12 @@ module GoCardless
|
|
272
277
|
@merchant_id
|
273
278
|
end
|
274
279
|
|
280
|
+
# Pull the merchant id out of the access scope
|
281
|
+
def set_merchant_id_from_scope(scope)
|
282
|
+
perm = scope.split.select {|p| p.start_with?('manage_merchant:') }.first
|
283
|
+
@merchant_id = perm.split(':')[1] if perm
|
284
|
+
end
|
285
|
+
|
275
286
|
# Send a request to the GoCardless API servers
|
276
287
|
#
|
277
288
|
# @param [Symbol] method the HTTP method to use (e.g. +:get+, +:post+)
|
data/lib/gocardless/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -92,31 +92,33 @@ describe GoCardless::Client do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
describe "with valid params" do
|
95
|
+
let(:oauth_client) { @client.instance_variable_get(:@oauth_client) }
|
96
|
+
let(:fake_token) do
|
97
|
+
stub(:params => {'scope' => 'manage_merchant:x'}, :token => 'abc')
|
98
|
+
end
|
99
|
+
|
100
|
+
before { oauth_client.auth_code.stubs(:get_token).returns(fake_token) }
|
101
|
+
|
95
102
|
it "calls correct method with correct args" do
|
96
103
|
auth_code = 'fakecode'
|
97
|
-
access_token = mock
|
98
|
-
|
99
|
-
@client.instance_variable_get(:@access_token).should be_nil
|
100
104
|
|
101
|
-
oauth_client = @client.instance_variable_get(:@oauth_client)
|
102
105
|
oauth_client.auth_code.expects(:get_token).with(
|
103
106
|
auth_code, has_entry(:redirect_uri => @redirect_uri)
|
104
|
-
)
|
107
|
+
).returns(fake_token)
|
105
108
|
|
106
109
|
@client.fetch_access_token(auth_code, {:redirect_uri => @redirect_uri})
|
107
110
|
end
|
108
111
|
|
109
112
|
it "sets @access_token" do
|
110
|
-
access_token = mock
|
111
|
-
access_token.stubs(:params).returns('scope' => '')
|
112
|
-
access_token.stubs(:token).returns('')
|
113
|
-
|
114
|
-
oauth_client = @client.instance_variable_get(:@oauth_client)
|
115
|
-
oauth_client.auth_code.expects(:get_token).returns(access_token)
|
116
|
-
|
117
113
|
@client.instance_variable_get(:@access_token).should be_nil
|
118
114
|
@client.fetch_access_token('code', {:redirect_uri => @redirect_uri})
|
119
|
-
@client.instance_variable_get(:@access_token).should ==
|
115
|
+
@client.instance_variable_get(:@access_token).should == fake_token
|
116
|
+
end
|
117
|
+
|
118
|
+
it "sets @merchant_id" do
|
119
|
+
@client.instance_variable_get(:@merchant_id).should be_nil
|
120
|
+
@client.fetch_access_token('code', {:redirect_uri => @redirect_uri})
|
121
|
+
@client.instance_variable_get(:@merchant_id).should == 'x'
|
120
122
|
end
|
121
123
|
end
|
122
124
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gocardless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 849635752354842289
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 1
|
10
|
+
version: 1.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Harry Marr
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-
|
19
|
+
date: 2012-07-11 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: oauth2
|