gocardless 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.1.0 - May 25, 2012
2
+
3
+ - Accept merchant_id as a client constructor param
4
+
5
+
1
6
  ## 1.0.1 - May 14, 2012
2
7
 
3
8
  - Update oauth2 dependency version, fixes installation issue
@@ -41,6 +41,7 @@ module GoCardless
41
41
  :token_url => '/oauth/access_token')
42
42
 
43
43
  self.access_token = args[:token] if args[:token]
44
+ @merchant_id = args[:merchant_id] if args[:merchant_id]
44
45
  end
45
46
 
46
47
  # Generate the OAuth authorize url
@@ -83,12 +84,15 @@ module GoCardless
83
84
  # (as returned by {#access_token})
84
85
  def access_token=(token)
85
86
  token, scope = token.sub(/^bearer\s+/i, '').split(' ', 2)
86
- if scope.nil?
87
- raise ArgumentError, ('Access token missing scope. Use format '
88
- '<token> <scope>')
89
- end
87
+ scope ||= ''
88
+
90
89
  @access_token = OAuth2::AccessToken.new(@oauth_client, token)
91
90
  @access_token.params['scope'] = scope
91
+
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
92
96
  end
93
97
 
94
98
  # Issue an GET request to the API server
@@ -260,6 +264,12 @@ module GoCardless
260
264
 
261
265
  private
262
266
 
267
+ # Return the merchant id, throwing a proper error if it's missing.
268
+ def merchant_id
269
+ raise ClientError, 'No merchant id set' unless @merchant_id
270
+ @merchant_id
271
+ end
272
+
263
273
  # Send a request to the GoCardless API servers
264
274
  #
265
275
  # @param [Symbol] method the HTTP method to use (e.g. +:get+, +:post+)
@@ -344,13 +354,6 @@ module GoCardless
344
354
  url.query = Utils.normalize_params(params)
345
355
  url.to_s
346
356
  end
347
-
348
- def merchant_id
349
- raise ClientError, 'Access token missing' unless @access_token
350
- scope = @access_token.params['scope'].split
351
- perm = scope.select {|p| p.start_with?('manage_merchant:') }.first
352
- perm.split(':')[1]
353
- end
354
357
  end
355
358
  end
356
359
 
@@ -1,3 +1,3 @@
1
1
  module GoCardless
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -30,11 +30,21 @@ describe GoCardless::Client do
30
30
  GoCardless::Client.new({:app_secret => @app_secret})
31
31
  end.should raise_exception(GoCardless::ClientError)
32
32
  end
33
+
33
34
  it "without an app_secret should raise an error" do
34
35
  lambda do
35
36
  GoCardless::Client.new({:app_id => @app_id})
36
37
  end.should raise_exception(GoCardless::ClientError)
37
38
  end
39
+
40
+ it "sets a merchant id if it's given" do
41
+ client = GoCardless::Client.new({
42
+ :app_id => @app_id,
43
+ :app_secret => @app_secret,
44
+ :merchant_id => 'xyz'
45
+ })
46
+ client.send('merchant_id').should == 'xyz'
47
+ end
38
48
  end
39
49
 
40
50
  before do
@@ -124,17 +134,17 @@ describe GoCardless::Client do
124
134
  token.params['scope'].should == 'a:1 b:2'
125
135
  end
126
136
 
137
+ it "pulls out the merchant_id when present" do
138
+ @client.access_token = 'TOKEN123 manage_merchant:xyz'
139
+ @client.send('merchant_id').should == 'xyz'
140
+ end
141
+
127
142
  it "ignores 'bearer' if it is present at the start of the string" do
128
143
  @client.access_token = 'Bearer TOKEN manage_merchant:123'
129
144
  token = @client.instance_variable_get(:@access_token)
130
145
  token.token.should == 'TOKEN'
131
146
  token.params['scope'].should == 'manage_merchant:123'
132
147
  end
133
-
134
- it "handles invalid values correctly" do
135
- token = 'TOKEN123' # missing scope
136
- expect { @client.access_token = token }.to raise_exception ArgumentError
137
- end
138
148
  end
139
149
 
140
150
  describe "#api_get" do
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: 3005118107932468525
4
+ hash: 3461773182973075480
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 0
9
8
  - 1
10
- version: 1.0.1
9
+ - 0
10
+ version: 1.1.0
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-05-14 00:00:00 Z
19
+ date: 2012-05-25 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: oauth2