gocardless 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -7,7 +7,6 @@ rvm:
7
7
  - jruby-19mode
8
8
  - rbx-18mode
9
9
  - ruby-head
10
- - jruby-head
11
10
  - ree
12
11
  notifications:
13
12
  email:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.3.2 - October 01, 2012
2
+
3
+ - Fix filtering on sub resource methods, e.g. `merchant.bills(source_id: 'x')`
4
+
1
5
  ## 1.3.1 - September 26, 2012
2
6
 
3
7
  - Remove explicit rubygems requires
@@ -11,40 +11,5 @@ module GoCardless
11
11
  :pending_balance,
12
12
  :next_payout_amount
13
13
  date_accessor :created_at, :next_payout_date
14
-
15
- def subscriptions(params = {})
16
- path = "/merchants/#{self.id}/subscriptions"
17
- @client.api_get(path, params).map do |attrs|
18
- GoCardless::Subscription.new_with_client(@client, attrs)
19
- end
20
- end
21
-
22
- def pre_authorizations(params = {})
23
- path = "/merchants/#{self.id}/pre_authorizations"
24
- @client.api_get(path, params).map do |attrs|
25
- GoCardless::PreAuthorization.new_with_client(@client, attrs)
26
- end
27
- end
28
-
29
- def users(params = {})
30
- path = "/merchants/#{self.id}/users"
31
- @client.api_get(path, params).map do |attrs|
32
- GoCardless::User.new_with_client(@client, attrs)
33
- end
34
- end
35
-
36
- def bills(params = {})
37
- path = "/merchants/#{self.id}/bills"
38
- @client.api_get(path, params).map do |attrs|
39
- GoCardless::Bill.new_with_client(@client, attrs)
40
- end
41
- end
42
-
43
- def payments(params = {})
44
- path = "/merchants/#{self.id}/payments"
45
- @client.api_get(path, params).map do |attrs|
46
- GoCardless::Payment.new_with_client(@client, attrs)
47
- end
48
- end
49
14
  end
50
15
  end
@@ -3,36 +3,31 @@ require 'date'
3
3
  module GoCardless
4
4
  class Resource
5
5
  def initialize(hash = {})
6
- # Handle sub resources
7
- sub_resource_uris = hash.delete('sub_resource_uris')
8
- unless sub_resource_uris.nil?
9
- # Need to define a method for each sub resource
10
- sub_resource_uris.each do |name,uri|
11
- uri = URI.parse(uri)
12
-
13
- # Convert the query string to a hash
14
- default_query = if uri.query.nil? || uri.query == ''
15
- nil
16
- else
17
- Hash[CGI.parse(uri.query).map { |k,v| [k,v.first] }]
18
- end
19
-
20
- # Strip api prefix from path
21
- path = uri.path.sub(%r{^/api/v\d+}, '')
6
+ # Define an object singleton method for each sub resource
7
+ hash.delete('sub_resource_uris') { [] }.each do |name, uri|
8
+ uri = URI.parse(uri)
9
+
10
+ # Convert the query string to a params hash
11
+ default_query = if uri.query.nil? || uri.query.empty?
12
+ {}
13
+ else
14
+ Hash[CGI.parse(uri.query).map { |k,v| [k,v.first] }]
15
+ end
22
16
 
23
- # Modify the instance's metaclass to add the method
24
- metaclass = class << self; self; end
25
- metaclass.send(:define_method, name) do |*args|
26
- # 'name' will be something like 'bills', convert it to Bill and
27
- # look up the resource class with that name
28
- class_name = Utils.camelize(Utils.singularize(name.to_s))
29
- klass = GoCardless.const_get(class_name)
17
+ # Strip api prefix from path
18
+ path = uri.path.sub(%r{^/api/v\d+}, '')
19
+
20
+ # Modify the instance's metaclass to add the method
21
+ metaclass = class << self; self; end
22
+ metaclass.send(:define_method, name) do |*args|
23
+ # 'name' will be something like 'bills', convert it to Bill and
24
+ # look up the resource class with that name
25
+ class_name = Utils.camelize(Utils.singularize(name.to_s))
26
+ klass = GoCardless.const_get(class_name)
27
+ query = default_query.merge(args.first || {})
28
+ client.api_get(path, query).map do |attrs|
30
29
  # Convert the results to instances of the looked-up class
31
- params = args.first || {}
32
- query = default_query.nil? ? nil : default_query.merge(params)
33
- client.api_get(path, query).map do |attrs|
34
- klass.new(attrs).tap { |m| m.client = client }
35
- end
30
+ klass.new_with_client(client, attrs)
36
31
  end
37
32
  end
38
33
  end
@@ -1,3 +1,3 @@
1
1
  module GoCardless
2
- VERSION = '1.3.1'.freeze
2
+ VERSION = '1.3.2'.freeze
3
3
  end
@@ -376,7 +376,7 @@ describe GoCardless::Resource do
376
376
  r.bills
377
377
  end
378
378
 
379
- it "adds provided params to query string params" do
379
+ it "adds provided params to existing query string params" do
380
380
  client = mock()
381
381
  params = { 'merchant_id' => '1', :amount => '10.00' }
382
382
  client.expects(:api_get).with(anything, params).returns([])
@@ -384,6 +384,18 @@ describe GoCardless::Resource do
384
384
  r.bills(:amount => '10.00')
385
385
  end
386
386
 
387
+ it "adds provided params when there are no existing query string params" do
388
+ client = mock()
389
+ params = { :source_id => 'xxx' }
390
+ client.expects(:api_get).with(anything, params).returns([])
391
+ r = @test_resource.new_with_client(client, {
392
+ 'sub_resource_uris' => {
393
+ 'bills' => 'https://test.com/merchants/1/bills'
394
+ }
395
+ })
396
+ r.bills(:source_id => 'xxx')
397
+ end
398
+
387
399
  it "return instances of the correct resource class" do
388
400
  client = stub(:api_get => [{:id => 1}])
389
401
  r = @test_resource.new_with_client(client, @attrs)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gocardless
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-26 00:00:00.000000000 Z
13
+ date: 2012-10-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: oauth2
@@ -140,7 +140,6 @@ files:
140
140
  - spec/bill_spec.rb
141
141
  - spec/client_spec.rb
142
142
  - spec/gocardless_spec.rb
143
- - spec/merchant_spec.rb
144
143
  - spec/pre_authorization_spec.rb
145
144
  - spec/resource_spec.rb
146
145
  - spec/spec_helper.rb
@@ -174,7 +173,6 @@ test_files:
174
173
  - spec/bill_spec.rb
175
174
  - spec/client_spec.rb
176
175
  - spec/gocardless_spec.rb
177
- - spec/merchant_spec.rb
178
176
  - spec/pre_authorization_spec.rb
179
177
  - spec/resource_spec.rb
180
178
  - spec/spec_helper.rb
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardless::Merchant do
4
- before :each do
5
- @app_id = 'abc'
6
- @app_secret = 'xyz'
7
- @client = GoCardless::Client.new(:app_id => @app_id, :app_secret => @app_secret)
8
- @client.access_token = 'TOKEN123 manage_merchant:123'
9
- @redirect_uri = 'http://test.com/cb'
10
- end
11
-
12
- index_methods = [:subscriptions, :pre_authorizations, :users, :payments, :bills]
13
-
14
- index_methods.each do |method|
15
- it "##{method} works correctly" do
16
- merchant = GoCardless::Merchant.new_with_client(@client)
17
-
18
- data = [{:id => 1}, {:id => 2}]
19
- stub_get(@client, data)
20
-
21
- merchant.send(method).should be_a Array
22
- merchant.send(method).length.should == 2
23
- merchant.send(method).zip(data).each do |obj,attrs|
24
- class_name = GoCardless::Utils.camelize(method.to_s).sub(/s$/, '')
25
- obj.class.to_s.should == "GoCardless::#{class_name}"
26
- attrs.each { |k,v| obj.send(k).should == v }
27
- end
28
- end
29
- end
30
- end
31
-