killbill-client 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/killbill_client/models/payment_method.rb +11 -3
- data/lib/killbill_client/models/resource.rb +6 -3
- data/lib/killbill_client/models/resources.rb +18 -5
- data/lib/killbill_client/version.rb +1 -1
- data/spec/killbill_client/remote/model_spec.rb +42 -0
- data/spec/killbill_client/resources_spec.rb +15 -0
- metadata +23 -32
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: afc7f7b3206167692cc8e770b0d94c7dee22c3fc
|
4
|
+
data.tar.gz: 36f151c0680ad5b724e07f24ec285b3ad6fe7d65
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff6427c84fc9e582af9f2439793276478b883feb49c19fbaf4e273b7f3fd9de57342503f1cd0ef94eeab2fadb0a0d0d8cece83ed3643d94f9cfbc62024ccd766
|
7
|
+
data.tar.gz: d64f2c1ff40af7acfe76963cba4ca024b021809bc2e200308c45302443afe58579fb02b54dae552aa297a74ff3d7d8c176cf7e1ec6ffdc80ac88915aac9eddc4
|
@@ -20,12 +20,20 @@ module KillBillClient
|
|
20
20
|
options
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def find_in_batches(offset = 0, limit = 100, options = {})
|
24
|
+
get "#{KILLBILL_API_PAYMENT_METHODS_PREFIX}/#{Resource::KILLBILL_API_PAGINATION_PREFIX}",
|
25
|
+
{
|
26
|
+
:offset => offset,
|
27
|
+
:limit => limit
|
28
|
+
},
|
29
|
+
options
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_in_batches_by_search_key(search_key, offset = 0, limit = 100, options = {})
|
24
33
|
get "#{KILLBILL_API_PAYMENT_METHODS_PREFIX}/search/#{search_key}",
|
25
34
|
{
|
26
35
|
:offset => offset,
|
27
|
-
:limit => limit
|
28
|
-
:withPluginInfo => with_plugin_info
|
36
|
+
:limit => limit
|
29
37
|
},
|
30
38
|
options
|
31
39
|
end
|
@@ -4,7 +4,8 @@ module KillBillClient
|
|
4
4
|
module Model
|
5
5
|
class Resource
|
6
6
|
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :clazz,
|
8
|
+
:etag,
|
8
9
|
:session_id,
|
9
10
|
:response
|
10
11
|
|
@@ -53,10 +54,12 @@ module KillBillClient
|
|
53
54
|
record = from_json resource_class, response.body
|
54
55
|
session_id = extract_session_id(response)
|
55
56
|
record.instance_eval {
|
57
|
+
@clazz = resource_class
|
56
58
|
@etag = response['ETag']
|
57
59
|
@session_id = session_id
|
58
|
-
@
|
59
|
-
@
|
60
|
+
@pagination_max_nb_records = response['X-Killbill-Pagination-MaxNbRecords'].to_i unless response['X-Killbill-Pagination-MaxNbRecords'].nil?
|
61
|
+
@pagination_total_nb_records = response['X-Killbill-Pagination-TotalNbRecords'].to_i unless response['X-Killbill-Pagination-TotalNbRecords'].nil?
|
62
|
+
@pagination_next_page = response['X-Killbill-Pagination-NextPageUri']
|
60
63
|
@response = response
|
61
64
|
}
|
62
65
|
record
|
@@ -2,12 +2,25 @@ module KillBillClient
|
|
2
2
|
module Model
|
3
3
|
class Resources < ::Array
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
:
|
8
|
-
:
|
9
|
-
|
5
|
+
attr_reader :clazz,
|
6
|
+
:etag,
|
7
|
+
:session_id,
|
8
|
+
:pagination_max_nb_records,
|
9
|
+
:pagination_total_nb_records,
|
10
|
+
:pagination_next_page
|
11
|
+
:response
|
10
12
|
|
13
|
+
# Same as .each, but fetch remaining pages as we go
|
14
|
+
def each_in_batches(&block)
|
15
|
+
each(&block)
|
16
|
+
|
17
|
+
# Non-pagination usecase or last page reached
|
18
|
+
return if @pagination_next_page.nil?
|
19
|
+
|
20
|
+
# Query the server for the next page
|
21
|
+
resources = Resource.get(@pagination_next_page, {}, {}, @clazz)
|
22
|
+
resources.each_in_batches(&block)
|
23
|
+
end
|
11
24
|
end
|
12
25
|
end
|
13
26
|
end
|
@@ -31,6 +31,34 @@ describe KillBillClient::Model do
|
|
31
31
|
account.external_key.should == external_key
|
32
32
|
account.payment_method_id.should be_nil
|
33
33
|
|
34
|
+
# Try to retrieve it (bis repetita placent)
|
35
|
+
accounts = KillBillClient::Model::Account.find_in_batches
|
36
|
+
# Can't test equality if the remote server has extra data
|
37
|
+
accounts.pagination_total_nb_records.should >= 1
|
38
|
+
accounts.pagination_max_nb_records.should >= 1
|
39
|
+
accounts.size.should >= 1
|
40
|
+
# If the remote server has lots of data, we need to page through the results (good test!)
|
41
|
+
found = nil
|
42
|
+
accounts.each_in_batches do |account|
|
43
|
+
found = account if account.external_key == external_key
|
44
|
+
break unless found.nil?
|
45
|
+
end
|
46
|
+
found.should_not be_nil
|
47
|
+
|
48
|
+
# Try to retrieve it via the search API
|
49
|
+
accounts = KillBillClient::Model::Account.find_in_batches_by_search_key(account.name)
|
50
|
+
# Can't test equality if the remote server has extra data
|
51
|
+
accounts.pagination_total_nb_records.should >= 1
|
52
|
+
accounts.pagination_max_nb_records.should >= 1
|
53
|
+
accounts.size.should >= 1
|
54
|
+
# If the remote server has lots of data, we need to page through the results (good test!)
|
55
|
+
found = nil
|
56
|
+
accounts.each_in_batches do |account|
|
57
|
+
found = account if account.external_key == external_key
|
58
|
+
break unless found.nil?
|
59
|
+
end
|
60
|
+
found.should_not be_nil
|
61
|
+
|
34
62
|
# Add/Remove a tag
|
35
63
|
account.tags.size.should == 0
|
36
64
|
account.add_tag('TEST', 'KillBill Spec test')
|
@@ -54,6 +82,20 @@ describe KillBillClient::Model do
|
|
54
82
|
pm = KillBillClient::Model::PaymentMethod.find_by_id pm.payment_method_id, true
|
55
83
|
pm.account_id.should == account.account_id
|
56
84
|
|
85
|
+
# Try to retrieve it (bis repetita placent)
|
86
|
+
pms = KillBillClient::Model::PaymentMethod.find_in_batches
|
87
|
+
# Can't test equality if the remote server has extra data
|
88
|
+
pms.pagination_total_nb_records.should >= 1
|
89
|
+
pms.pagination_max_nb_records.should >= 1
|
90
|
+
pms.size.should >= 1
|
91
|
+
# If the remote server has lots of data, we need to page through the results (good test!)
|
92
|
+
found = nil
|
93
|
+
pms.each_in_batches do |payment_method|
|
94
|
+
found = payment_method if payment_method.payment_method_id == pm.payment_method_id
|
95
|
+
break unless found.nil?
|
96
|
+
end
|
97
|
+
found.should_not be_nil
|
98
|
+
|
57
99
|
account = KillBillClient::Model::Account.find_by_id account.account_id
|
58
100
|
account.payment_method_id.should == pm.payment_method_id
|
59
101
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KillBillClient::Model::Resources do
|
4
|
+
it 'should respect the next page url when calling the .each_in_batches method' do
|
5
|
+
stuff = KillBillClient::Model::Resources.new
|
6
|
+
1.upto(10).each { |i| stuff << i }
|
7
|
+
stuff.size.should == 10
|
8
|
+
|
9
|
+
idx = 1
|
10
|
+
stuff.each_in_batches do |i|
|
11
|
+
i.should == idx
|
12
|
+
idx += 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,64 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Killbill core team
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json
|
16
|
-
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
17
|
- - ~>
|
19
18
|
- !ruby/object:Gem::Version
|
20
19
|
version: 1.8.0
|
21
|
-
|
22
|
-
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.8.0
|
27
|
-
none: false
|
28
|
-
prerelease: false
|
29
|
-
type: :runtime
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
|
-
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
33
30
|
requirements:
|
34
31
|
- - '>='
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: 10.0.0
|
37
|
-
|
38
|
-
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
37
|
requirements:
|
40
38
|
- - '>='
|
41
39
|
- !ruby/object:Gem::Version
|
42
40
|
version: 10.0.0
|
43
|
-
none: false
|
44
|
-
prerelease: false
|
45
|
-
type: :development
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
|
-
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
49
44
|
requirements:
|
50
45
|
- - ~>
|
51
46
|
- !ruby/object:Gem::Version
|
52
47
|
version: 2.12.0
|
53
|
-
|
54
|
-
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
51
|
requirements:
|
56
52
|
- - ~>
|
57
53
|
- !ruby/object:Gem::Version
|
58
54
|
version: 2.12.0
|
59
|
-
none: false
|
60
|
-
prerelease: false
|
61
|
-
type: :development
|
62
55
|
description: An API client library for Kill Bill.
|
63
56
|
email: killbilling-users@googlegroups.com
|
64
57
|
executables: []
|
@@ -139,11 +132,13 @@ files:
|
|
139
132
|
- spec/killbill_client/model_relation_spec.rb
|
140
133
|
- spec/killbill_client/remote/api_spec.rb
|
141
134
|
- spec/killbill_client/remote/model_spec.rb
|
135
|
+
- spec/killbill_client/resources_spec.rb
|
142
136
|
- spec/spec_helper.rb
|
143
137
|
homepage: http://www.killbilling.org
|
144
138
|
licenses:
|
145
139
|
- Apache License (2.0)
|
146
|
-
|
140
|
+
metadata: {}
|
141
|
+
post_install_message:
|
147
142
|
rdoc_options:
|
148
143
|
- --exclude
|
149
144
|
- .
|
@@ -154,24 +149,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
149
|
- - '>='
|
155
150
|
- !ruby/object:Gem::Version
|
156
151
|
version: 1.8.6
|
157
|
-
none: false
|
158
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
153
|
requirements:
|
160
154
|
- - '>='
|
161
155
|
- !ruby/object:Gem::Version
|
162
|
-
segments:
|
163
|
-
- 0
|
164
156
|
version: '0'
|
165
|
-
hash: 2
|
166
|
-
none: false
|
167
157
|
requirements: []
|
168
|
-
rubyforge_project:
|
169
|
-
rubygems_version:
|
170
|
-
signing_key:
|
171
|
-
specification_version:
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.0.3
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
172
162
|
summary: Kill Bill client library.
|
173
163
|
test_files:
|
174
164
|
- spec/killbill_client/model_relation_spec.rb
|
175
165
|
- spec/killbill_client/remote/api_spec.rb
|
176
166
|
- spec/killbill_client/remote/model_spec.rb
|
167
|
+
- spec/killbill_client/resources_spec.rb
|
177
168
|
- spec/spec_helper.rb
|