shopkit 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/shopkit/client/products.rb +3 -1
- data/lib/shopkit/configuration.rb +2 -0
- data/lib/shopkit/traversal.rb +3 -1
- data/lib/shopkit/version.rb +1 -1
- data/shopkit.gemspec +1 -1
- data/spec/shopkit/client/orders_spec.rb +1 -1
- data/spec/shopkit/client/products_spec.rb +1 -1
- data/spec/shopkit/shopkit_spec.rb +5 -5
- metadata +2 -2
data/README.md
CHANGED
@@ -18,6 +18,7 @@ module Shopkit
|
|
18
18
|
DEFAULT_API_VERSION = 1
|
19
19
|
DEFAULT_USER_AGENT = "Shopkit Ruby Gem #{Shopkit::VERSION}".freeze
|
20
20
|
DEFAULT_AUTO_TRAVERSAL = false
|
21
|
+
DEFAULT_PER_PAGE = 30
|
21
22
|
|
22
23
|
attr_accessor(*VALID_OPTIONS_KEYS)
|
23
24
|
|
@@ -41,6 +42,7 @@ module Shopkit
|
|
41
42
|
self.password = nil
|
42
43
|
self.user_agent = DEFAULT_USER_AGENT
|
43
44
|
self.auto_traversal = DEFAULT_AUTO_TRAVERSAL
|
45
|
+
self.per_page = DEFAULT_PER_PAGE
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
data/lib/shopkit/traversal.rb
CHANGED
@@ -2,9 +2,11 @@ module Shopkit
|
|
2
2
|
module Traversal
|
3
3
|
|
4
4
|
def traversal(options) # 遍历所有页面
|
5
|
+
options[:page] ||= 1
|
6
|
+
options[:per_page] ||= per_page
|
7
|
+
options[:per_page] = 100 if auto_traversal
|
5
8
|
list = yield(options)
|
6
9
|
if auto_traversal and !list.empty?
|
7
|
-
options[:page] ||= 1
|
8
10
|
options[:page] += 1
|
9
11
|
list += traversal(options) do
|
10
12
|
yield(options)
|
data/lib/shopkit/version.rb
CHANGED
data/shopkit.gemspec
CHANGED
@@ -3,11 +3,11 @@ require 'spec_helper'
|
|
3
3
|
describe Shopkit do
|
4
4
|
|
5
5
|
before do
|
6
|
-
fake_web "orders", query: {per_page: 1, page: 1}
|
7
|
-
fake_web "orders", query: {per_page: 1, page: 2}, json_file: "orders_page_2"
|
8
|
-
fake_web "orders", query: {per_page: 1, page: 3}, json_file: "orders_page_3"
|
9
|
-
fake_web "orders", query: {per_page: 1, page: 4}, json_file: "orders_empty"
|
10
6
|
Shopkit.auto_traversal = true
|
7
|
+
fake_web "orders", query: {per_page: 100, page: 1}
|
8
|
+
fake_web "orders", query: {per_page: 100, page: 2}, json_file: "orders_page_2"
|
9
|
+
fake_web "orders", query: {per_page: 100, page: 3}, json_file: "orders_page_3"
|
10
|
+
fake_web "orders", query: {per_page: 100, page: 4}, json_file: "orders_empty"
|
11
11
|
end
|
12
12
|
|
13
13
|
after do
|
@@ -15,7 +15,7 @@ describe Shopkit do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should be auto_traversal' do
|
18
|
-
Shopkit.orders(
|
18
|
+
Shopkit.orders(page: 1).size.should eql 3
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -200,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
200
|
version: '0'
|
201
201
|
segments:
|
202
202
|
- 0
|
203
|
-
hash:
|
203
|
+
hash: -1020168515
|
204
204
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
205
|
none: false
|
206
206
|
requirements:
|