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 +0 -1
- data/CHANGELOG.md +4 -0
- data/lib/gocardless/merchant.rb +0 -35
- data/lib/gocardless/resource.rb +23 -28
- data/lib/gocardless/version.rb +1 -1
- data/spec/resource_spec.rb +13 -1
- metadata +2 -4
- data/spec/merchant_spec.rb +0 -31
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/gocardless/merchant.rb
CHANGED
@@ -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
|
data/lib/gocardless/resource.rb
CHANGED
@@ -3,36 +3,31 @@ require 'date'
|
|
3
3
|
module GoCardless
|
4
4
|
class Resource
|
5
5
|
def initialize(hash = {})
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
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
|
data/lib/gocardless/version.rb
CHANGED
data/spec/resource_spec.rb
CHANGED
@@ -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.
|
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-
|
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
|
data/spec/merchant_spec.rb
DELETED
@@ -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
|
-
|