gocardless 1.6.3 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  script: "rake spec"
2
2
  rvm:
3
+ - 2.0.0
3
4
  - 1.9.3
4
5
  - 1.9.2
5
6
  - 1.8.7
data/CHANGELOG.md CHANGED
@@ -1,8 +1,16 @@
1
+ ## 1.7.0 - April 19, 2013
2
+
3
+ - Adds `retry!` method to Bill, allowing you to re-attempt collection where a
4
+ bill has a status of `failed`
5
+ - Publicise Client#merchant_id
6
+ - Deprecate old syntax for setting merchant id / scope
7
+ - Add User#name method, for getting a user's full name
8
+ - Add `?` methods for checking resource statuses (e.g. `Subscription#active?`)
9
+
1
10
  ## 1.6.3 - February 11, 2013
2
11
 
3
12
  - Handle empty arrays in Utils#flatten_params
4
13
 
5
-
6
14
  ## 1.6.2 - January 25, 2013
7
15
 
8
16
  - Add fee accessors to Bill
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![GoCardless Ruby Client Library](https://s3-eu-west-1.amazonaws.com/gocardless/images/client-lib-headers/ruby-lib-header.png)
1
+ [![GoCardless Ruby Client Library](https://s3-eu-west-1.amazonaws.com/gocardless/images/client-lib-headers/ruby-lib-header.png)](https://gocardless.com/docs?language=ruby)
2
2
 
3
3
  The GoCardless Ruby client provides a simple Ruby interface to the GoCardless
4
4
  API.
data/gocardless.gemspec CHANGED
@@ -8,6 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.add_development_dependency 'mocha', '~> 0.9.12'
9
9
  gem.add_development_dependency 'yard', '~> 0.7.3'
10
10
  gem.add_development_dependency 'activesupport', '~> 3.1'
11
+ gem.add_development_dependency 'rake', '~> 10.0'
11
12
 
12
13
  gem.authors = ['Harry Marr', 'Tom Blomfield']
13
14
  gem.description = %q{A Ruby wrapper for the GoCardless API}
@@ -35,6 +35,11 @@ module GoCardless
35
35
  @source_type = Utils.underscore(klass)
36
36
  end
37
37
 
38
+ def retry!
39
+ path = self.class.endpoint.gsub(':id', id.to_s) + '/retry'
40
+ client.api_post(path)
41
+ end
42
+
38
43
  def save
39
44
  save_data({
40
45
  :bill => {
@@ -46,5 +51,25 @@ module GoCardless
46
51
  })
47
52
  self
48
53
  end
54
+
55
+ def pending?
56
+ status == 'pending'
57
+ end
58
+
59
+ def paid?
60
+ status == 'paid'
61
+ end
62
+
63
+ def failed?
64
+ status == 'failed'
65
+ end
66
+
67
+ def withdrawn?
68
+ status == 'withdrawn'
69
+ end
70
+
71
+ def refunded?
72
+ status == 'refunded'
73
+ end
49
74
  end
50
75
  end
@@ -83,11 +83,18 @@ module GoCardless
83
83
 
84
84
  # Set the client's access token
85
85
  #
86
- # @param [String] token a string with format <code>"#{token} #{scope}"</code>
86
+ # @param [String] token a string with format <code>"#{token}"</code>
87
87
  # (as returned by {#access_token})
88
88
  def access_token=(token)
89
89
  token, scope = token.sub(/^bearer\s+/i, '').split(' ', 2)
90
- scope ||= ''
90
+ if scope
91
+ warn "[DEPRECATION] (gocardless-ruby) merchant_id is now a separate " +
92
+ "attribute, the manage_merchant scope should no longer be " +
93
+ "included in the 'token' attribute. See http://git.io/G9y37Q " +
94
+ "for more info."
95
+ else
96
+ scope = ''
97
+ end
91
98
 
92
99
  @access_token = OAuth2::AccessToken.new(@oauth_client, token)
93
100
  @access_token.params['scope'] = scope
@@ -95,6 +102,14 @@ module GoCardless
95
102
  set_merchant_id_from_scope(scope) unless @merchant_id
96
103
  end
97
104
 
105
+ # Return the merchant id, throwing a proper error if it's missing.
106
+ def merchant_id
107
+ raise ClientError, 'No merchant id set' unless @merchant_id
108
+ @merchant_id
109
+ end
110
+
111
+ attr_writer :merchant_id
112
+
98
113
  # Issue an GET request to the API server
99
114
  #
100
115
  # @note this method is for internal use
@@ -285,12 +300,6 @@ module GoCardless
285
300
 
286
301
  private
287
302
 
288
- # Return the merchant id, throwing a proper error if it's missing.
289
- def merchant_id
290
- raise ClientError, 'No merchant id set' unless @merchant_id
291
- @merchant_id
292
- end
293
-
294
303
  # Pull the merchant id out of the access scope
295
304
  def set_merchant_id_from_scope(scope)
296
305
  perm = scope.split.select {|p| p.start_with?('manage_merchant:') }.first
@@ -31,6 +31,22 @@ module GoCardless
31
31
  client.api_put(path)
32
32
  end
33
33
 
34
+ def inactive?
35
+ status == 'inactive'
36
+ end
37
+
38
+ def active?
39
+ status == 'active'
40
+ end
41
+
42
+ def cancelled?
43
+ status == 'cancelled'
44
+ end
45
+
46
+ def expired?
47
+ status == 'expired'
48
+ end
49
+
34
50
  end
35
51
  end
36
52
 
@@ -25,6 +25,22 @@ module GoCardless
25
25
  client.api_put(path)
26
26
  end
27
27
 
28
+ def inactive?
29
+ status == 'inactive'
30
+ end
31
+
32
+ def active?
33
+ status == 'active'
34
+ end
35
+
36
+ def cancelled?
37
+ status == 'cancelled'
38
+ end
39
+
40
+ def expired?
41
+ status == 'expired'
42
+ end
43
+
28
44
  end
29
45
  end
30
46
 
@@ -4,5 +4,9 @@ module GoCardless
4
4
 
5
5
  attr_accessor :name, :first_name, :last_name, :email
6
6
  date_accessor :created_at
7
+
8
+ def name
9
+ "#{first_name} #{last_name}".strip
10
+ end
7
11
  end
8
12
  end
@@ -1,3 +1,3 @@
1
1
  module GoCardless
2
- VERSION = '1.6.3'.freeze
2
+ VERSION = '1.7.0'.freeze
3
3
  end
data/spec/bill_spec.rb CHANGED
@@ -5,13 +5,14 @@ describe GoCardless::Bill do
5
5
  @app_id = 'abc'
6
6
  @app_secret = 'xyz'
7
7
  GoCardless.account_details = {:app_id => @app_id, :app_secret => @app_secret,
8
- :token => 'xxx manage_merchant:1'}
8
+ :token => 'xxx', :merchant_id => '1'}
9
9
  @client = GoCardless.client
10
10
  end
11
11
 
12
12
  it "source getter works" do
13
13
  b = GoCardless::Bill.new(:source_type => :subscription, :source_id => 123)
14
- @client.access_token = 'TOKEN manage_merchant:123'
14
+ @client.access_token = 'TOKEN'
15
+ @client.merchant_id = '123'
15
16
  stub_get(@client, :id => 123)
16
17
  source = b.source
17
18
  source.should be_a GoCardless::Subscription
@@ -24,4 +25,60 @@ describe GoCardless::Bill do
24
25
  b.source_id.should == 123
25
26
  b.source_type.should.to_s == 'subscription'
26
27
  end
28
+
29
+ it "should be able to be retried" do
30
+ b = GoCardless::Bill.new(:id => 123)
31
+ @client.expects(:api_post).with('/bills/123/retry')
32
+ b.retry!
33
+ end
34
+
35
+ describe "pending query method" do
36
+ it "returns true when the subscription status is pending" do
37
+ GoCardless::Bill.new(:status => 'pending').pending?.should be_true
38
+ end
39
+
40
+ it "returns false otherwise" do
41
+ GoCardless::Bill.new.pending?.should be_false
42
+ end
43
+ end
44
+
45
+ describe "paid query method" do
46
+ it "returns true when the subscription status is paid" do
47
+ GoCardless::Bill.new(:status => 'paid').paid?.should be_true
48
+ end
49
+
50
+ it "returns false otherwise" do
51
+ GoCardless::Bill.new.paid?.should be_false
52
+ end
53
+ end
54
+
55
+ describe "failed query method" do
56
+ it "returns true when the subscription status is failed" do
57
+ GoCardless::Bill.new(:status => 'failed').failed?.should be_true
58
+ end
59
+
60
+ it "returns false otherwise" do
61
+ GoCardless::Bill.new.failed?.should be_false
62
+ end
63
+ end
64
+
65
+ describe "withdrawn query method" do
66
+ it "returns true when the subscription status is withdrawn" do
67
+ GoCardless::Bill.new(:status => 'withdrawn').withdrawn?.should be_true
68
+ end
69
+
70
+ it "returns false otherwise" do
71
+ GoCardless::Bill.new.withdrawn?.should be_false
72
+ end
73
+ end
74
+
75
+ describe "refunded query method" do
76
+ it "returns true when the subscription status is refunded" do
77
+ GoCardless::Bill.new(:status => 'refunded').refunded?.should be_true
78
+ end
79
+
80
+ it "returns false otherwise" do
81
+ GoCardless::Bill.new.refunded?.should be_false
82
+ end
83
+ end
27
84
  end
data/spec/client_spec.rb CHANGED
@@ -146,6 +146,8 @@ describe GoCardless::Client do
146
146
  end
147
147
 
148
148
  describe "#access_token=" do
149
+ before { @client.stubs(:warn) }
150
+
149
151
  it "deserializes access token correctly" do
150
152
  @client.access_token = 'TOKEN123 a:1 b:2'
151
153
  token = @client.instance_variable_get(:@access_token)
@@ -158,6 +160,16 @@ describe GoCardless::Client do
158
160
  @client.send('merchant_id').should == 'xyz'
159
161
  end
160
162
 
163
+ it "issues a deprecation warning when the scope is present" do
164
+ @client.expects(:warn)
165
+ @client.access_token = 'TOKEN123 manage_merchant:xyz'
166
+ end
167
+
168
+ it "doesn't issue a deprecation warning when the scope is missing" do
169
+ @client.expects(:warn).never
170
+ @client.access_token = 'TOKEN123'
171
+ end
172
+
161
173
  it "ignores 'bearer' if it is present at the start of the string" do
162
174
  @client.access_token = 'Bearer TOKEN manage_merchant:123'
163
175
  token = @client.instance_variable_get(:@access_token)
@@ -168,7 +180,7 @@ describe GoCardless::Client do
168
180
 
169
181
  describe "#api_get" do
170
182
  it "uses the correct path prefix" do
171
- @client.access_token = 'TOKEN123 a:1 b:2'
183
+ @client.access_token = 'TOKEN123'
172
184
  token = @client.instance_variable_get(:@access_token)
173
185
  r = mock
174
186
  r.stubs(:parsed)
@@ -183,7 +195,7 @@ describe GoCardless::Client do
183
195
 
184
196
  describe "#api_post" do
185
197
  it "encodes data to json" do
186
- @client.access_token = 'TOKEN123 a:1 b:2'
198
+ @client.access_token = 'TOKEN123'
187
199
  token = @client.instance_variable_get(:@access_token)
188
200
  r = mock
189
201
  r.stubs(:parsed)
@@ -198,7 +210,8 @@ describe GoCardless::Client do
198
210
 
199
211
  describe "#merchant" do
200
212
  it "looks up the correct merchant" do
201
- @client.access_token = 'TOKEN a manage_merchant:123 b'
213
+ @client.access_token = 'TOKEN'
214
+ @client.merchant_id = '123'
202
215
  response = mock
203
216
  response.expects(:parsed)
204
217
 
@@ -212,7 +225,8 @@ describe GoCardless::Client do
212
225
  end
213
226
 
214
227
  it "creates a Merchant object" do
215
- @client.access_token = 'TOKEN manage_merchant:123'
228
+ @client.access_token = 'TOKEN'
229
+ @client.merchant_id = '123'
216
230
  response = mock
217
231
  response.expects(:parsed).returns({:name => 'test', :id => 123})
218
232
 
@@ -229,7 +243,8 @@ describe GoCardless::Client do
229
243
  %w{subscription pre_authorization user bill payment}.each do |resource|
230
244
  describe "##{resource}" do
231
245
  it "returns the correct #{GoCardless::Utils.camelize(resource)} object" do
232
- @client.access_token = 'TOKEN manage_merchant:123'
246
+ @client.access_token = 'TOKEN'
247
+ @client.merchant_id = '123'
233
248
  stub_get(@client, {:id => 123})
234
249
  obj = @client.send(resource, 123)
235
250
  obj.should be_a GoCardless.const_get(GoCardless::Utils.camelize(resource))
@@ -373,7 +388,8 @@ describe GoCardless::Client do
373
388
  describe "#new_limit_url" do
374
389
  before(:each) do
375
390
  @merchant_id = '123'
376
- @client.access_token = "TOKEN manage_merchant:#{@merchant_id}"
391
+ @client.access_token = "TOKEN"
392
+ @client.merchant_id = @merchant_id
377
393
  end
378
394
 
379
395
  def get_params(url)
@@ -446,7 +462,7 @@ describe GoCardless::Client do
446
462
 
447
463
  describe "#merchant_id" do
448
464
  it "returns the merchant id when an access token is set" do
449
- @client.access_token = 'TOKEN manage_merchant:123'
465
+ @client.merchant_id = '123'
450
466
  @client.send(:merchant_id).should == '123'
451
467
  end
452
468
 
@@ -4,7 +4,8 @@ describe GoCardless do
4
4
  before do
5
5
  unset_ivar GoCardless, :client
6
6
  unset_ivar GoCardless, :account_details
7
- @details = {:app_id => 'X', :app_secret => 'X', :token => 'X manage_merchant:1'}
7
+ @details = { :app_id => 'X', :app_secret => 'X',
8
+ :token => 'X', :merchant_id => '1' }
8
9
  end
9
10
 
10
11
  describe ".account_details=" do
@@ -5,7 +5,7 @@ describe GoCardless::PreAuthorization do
5
5
  @app_id = 'abc'
6
6
  @app_secret = 'xyz'
7
7
  GoCardless.account_details = {:app_id => @app_id, :app_secret => @app_secret,
8
- :token => 'xxx manage_merchant:1'}
8
+ :token => 'xxx', :merchant_id => '1'}
9
9
  @client = GoCardless.client
10
10
  end
11
11
 
@@ -15,4 +15,43 @@ describe GoCardless::PreAuthorization do
15
15
  s.cancel!
16
16
  end
17
17
 
18
+ describe "inactive query method" do
19
+ it "returns true when the subscription status is inactive" do
20
+ GoCardless::PreAuthorization.new(:status => 'inactive').inactive?.should be_true
21
+ end
22
+
23
+ it "returns false otherwise" do
24
+ GoCardless::PreAuthorization.new.inactive?.should be_false
25
+ end
26
+ end
27
+
28
+ describe "active query method" do
29
+ it "returns true when the subscription status is active" do
30
+ GoCardless::PreAuthorization.new(:status => 'active').active?.should be_true
31
+ end
32
+
33
+ it "returns false otherwise" do
34
+ GoCardless::PreAuthorization.new.active?.should be_false
35
+ end
36
+ end
37
+
38
+ describe "cancelled query method" do
39
+ it "returns true when the subscription status is cancelled" do
40
+ GoCardless::PreAuthorization.new(:status => 'cancelled').cancelled?.should be_true
41
+ end
42
+
43
+ it "returns false otherwise" do
44
+ GoCardless::PreAuthorization.new.cancelled?.should be_false
45
+ end
46
+ end
47
+
48
+ describe "expired query method" do
49
+ it "returns true when the subscription status is expired" do
50
+ GoCardless::PreAuthorization.new(:status => 'expired').expired?.should be_true
51
+ end
52
+
53
+ it "returns false otherwise" do
54
+ GoCardless::PreAuthorization.new.expired?.should be_false
55
+ end
56
+ end
18
57
  end
@@ -156,7 +156,8 @@ describe GoCardless::Resource do
156
156
 
157
157
  resource = test_resource.new_with_client(@client)
158
158
  resource.instance_variable_set(:@user_id, 123)
159
- @client.access_token = 'TOKEN manage_merchant:123'
159
+ @client.access_token = 'TOKEN'
160
+ @client.merchant_id = '123'
160
161
  stub_get(@client, {:id => 123})
161
162
  user = resource.user
162
163
  user.should be_a GoCardless::User
@@ -5,7 +5,7 @@ describe GoCardless::Subscription do
5
5
  @app_id = 'abc'
6
6
  @app_secret = 'xyz'
7
7
  GoCardless.account_details = {:app_id => @app_id, :app_secret => @app_secret,
8
- :token => 'xxx manage_merchant:1'}
8
+ :token => 'xxx', :merchant_id => '1'}
9
9
  @client = GoCardless.client
10
10
  end
11
11
 
@@ -15,4 +15,43 @@ describe GoCardless::Subscription do
15
15
  s.cancel!
16
16
  end
17
17
 
18
+ describe "inactive query method" do
19
+ it "returns true when the subscription status is inactive" do
20
+ GoCardless::Subscription.new(:status => 'inactive').inactive?.should be_true
21
+ end
22
+
23
+ it "returns false otherwise" do
24
+ GoCardless::Subscription.new.inactive?.should be_false
25
+ end
26
+ end
27
+
28
+ describe "active query method" do
29
+ it "returns true when the subscription status is active" do
30
+ GoCardless::Subscription.new(:status => 'active').active?.should be_true
31
+ end
32
+
33
+ it "returns false otherwise" do
34
+ GoCardless::Subscription.new.active?.should be_false
35
+ end
36
+ end
37
+
38
+ describe "cancelled query method" do
39
+ it "returns true when the subscription status is cancelled" do
40
+ GoCardless::Subscription.new(:status => 'cancelled').cancelled?.should be_true
41
+ end
42
+
43
+ it "returns false otherwise" do
44
+ GoCardless::Subscription.new.cancelled?.should be_false
45
+ end
46
+ end
47
+
48
+ describe "expired query method" do
49
+ it "returns true when the subscription status is expired" do
50
+ GoCardless::Subscription.new(:status => 'expired').expired?.should be_true
51
+ end
52
+
53
+ it "returns false otherwise" do
54
+ GoCardless::Subscription.new.expired?.should be_false
55
+ end
56
+ end
18
57
  end
data/spec/user_spec.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardless::User do
4
+ let(:user) { GoCardless::User.new(:id => 123, :first_name => first, :last_name => last) }
5
+
6
+ describe "#name" do
7
+ subject { user.name }
8
+
9
+ context "with first and last name" do
10
+ let(:first) { "First" }
11
+ let(:last) { "Last" }
12
+ it { should == "First Last" }
13
+ end
14
+
15
+ context "with first name only" do
16
+ let(:first) { "First" }
17
+ let(:last) { nil }
18
+ it { should == "First" }
19
+ end
20
+
21
+ context "with last name only" do
22
+ let(:first) { nil }
23
+ let(:last) { "Last" }
24
+ it { should == "Last" }
25
+ end
26
+
27
+ context "with no first or last name" do
28
+ let(:first) { nil }
29
+ let(:last) { nil }
30
+ it { should == "" }
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gocardless
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.6.3
5
+ version: 1.7.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Harry Marr
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-11 00:00:00.000000000 Z
13
+ date: 2013-04-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  version_requirements: !ruby/object:Gem::Requirement
@@ -108,6 +108,22 @@ dependencies:
108
108
  - !ruby/object:Gem::Version
109
109
  version: '3.1'
110
110
  none: false
111
+ - !ruby/object:Gem::Dependency
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ~>
115
+ - !ruby/object:Gem::Version
116
+ version: '10.0'
117
+ none: false
118
+ name: rake
119
+ type: :development
120
+ prerelease: false
121
+ requirement: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '10.0'
126
+ none: false
111
127
  description: A Ruby wrapper for the GoCardless API
112
128
  email:
113
129
  - developers@gocardless.com
@@ -144,6 +160,7 @@ files:
144
160
  - spec/resource_spec.rb
145
161
  - spec/spec_helper.rb
146
162
  - spec/subscription_spec.rb
163
+ - spec/user_spec.rb
147
164
  - spec/utils_spec.rb
148
165
  homepage: https://github.com/gocardless/gocardless-ruby
149
166
  licenses: []
@@ -177,5 +194,6 @@ test_files:
177
194
  - spec/resource_spec.rb
178
195
  - spec/spec_helper.rb
179
196
  - spec/subscription_spec.rb
197
+ - spec/user_spec.rb
180
198
  - spec/utils_spec.rb
181
199
  has_rdoc: