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 CHANGED
@@ -52,4 +52,4 @@ $ gem install shopkit
52
52
 
53
53
  ERROR: Using beta/unreleased version of rubygems. Not pushing
54
54
 
55
- 请尝试使用 VPN 连接网络,推荐 vpncup(免费)
55
+ 请尝试使用 VPN 连接网络,推荐 [vpncup](http://vcup.in/Ecz)
@@ -3,7 +3,9 @@ module Shopkit
3
3
  module Products
4
4
 
5
5
  def products(options={})
6
- get('/products', options)['products']
6
+ traversal(options) do
7
+ get('/products', options)['products']
8
+ end
7
9
  end
8
10
 
9
11
  def product(id, options={})
@@ -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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Shopkit
2
- VERSION = "0.1.4" unless defined?(Shopkit::VERSION)
2
+ VERSION = "0.1.5" unless defined?(Shopkit::VERSION)
3
3
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "shopkit"
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["saberma"]
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Shopkit::Client::Orders do
4
4
 
5
5
  it 'should get orders' do
6
- fake_web "orders"
6
+ fake_web "orders", query: {per_page: 30, page: 1}
7
7
  Shopkit.orders.size.should_not eql 0
8
8
  end
9
9
 
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Shopkit::Client::Products do
4
4
 
5
5
  before do
6
- fake_web "products"
6
+ fake_web "products", query: {per_page: 30, page: 1}
7
7
  end
8
8
 
9
9
  it 'should get products' do
@@ -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(per_page: 1, page: 1).size.should eql 3
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
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: 474065761
203
+ hash: -1020168515
204
204
  required_rubygems_version: !ruby/object:Gem::Requirement
205
205
  none: false
206
206
  requirements: