taobaorb 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rails/taobao-railtie.rb +0 -1
- data/lib/taobao/category.rb +2 -2
- data/lib/taobao/product.rb +4 -0
- data/lib/taobao/product_list.rb +4 -6
- data/lib/taobao/property_list.rb +4 -6
- data/lib/taobao/user.rb +1 -1
- data/lib/taobao/version.rb +1 -1
- data/spec/fixtures/category_without_subcategories.json +1 -0
- data/spec/fixtures/incorrect_category.json +1 -1
- data/spec/rspec/category_spec.rb +15 -20
- data/spec/rspec/product_list_spec.rb +3 -3
- data/spec/rspec/product_spec.rb +22 -18
- data/spec/rspec/property_list_spec.rb +2 -2
- data/spec/rspec/property_spec.rb +1 -1
- data/spec/rspec/search_spec.rb +1 -1
- data/spec/rspec/taobao_spec.rb +2 -6
- data/spec/rspec/user_spec.rb +4 -3
- data/spec/spec_helper.rb +10 -4
- metadata +5 -4
data/lib/rails/taobao-railtie.rb
CHANGED
@@ -7,7 +7,6 @@ module Taobao
|
|
7
7
|
config = YAML.load_file(Rails.root.join('config', 'taobaorb.yml'))[Rails.env]
|
8
8
|
Taobao.public_key = config['public_key']
|
9
9
|
Taobao.private_key = config['private_key']
|
10
|
-
p Taobao.public_key
|
11
10
|
rescue Errno::ENOENT
|
12
11
|
puts 'Taobao config not found.'
|
13
12
|
puts 'To generate one run: rails g taobao:config'
|
data/lib/taobao/category.rb
CHANGED
@@ -16,7 +16,7 @@ class Taobao::Category
|
|
16
16
|
def subcategories
|
17
17
|
return @subcategories if @subcategories
|
18
18
|
@subcategories = category_request(parent_cid: @id).map do |cat|
|
19
|
-
category = self.class.new cat[:
|
19
|
+
category = self.class.new cat[:cid]
|
20
20
|
category.to_object(cat)
|
21
21
|
category
|
22
22
|
end
|
@@ -40,7 +40,7 @@ class Taobao::Category
|
|
40
40
|
begin
|
41
41
|
result[:itemcats_get_response][:item_cats][:item_cat]
|
42
42
|
rescue NoMethodError
|
43
|
-
|
43
|
+
[]
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
data/lib/taobao/product.rb
CHANGED
data/lib/taobao/product_list.rb
CHANGED
@@ -40,12 +40,10 @@ class Taobao::ProductList < Taobao::AbstractList
|
|
40
40
|
|
41
41
|
private
|
42
42
|
def products
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
[]
|
48
|
-
end
|
43
|
+
products = cached_responce[:items_get_response][:items][:item]
|
44
|
+
get_products_as_objects(products)
|
45
|
+
rescue NoMethodError
|
46
|
+
[]
|
49
47
|
end
|
50
48
|
|
51
49
|
def get_products_as_objects(products)
|
data/lib/taobao/property_list.rb
CHANGED
@@ -6,12 +6,10 @@ class Taobao::PropertyList < Taobao::AbstractList
|
|
6
6
|
|
7
7
|
private
|
8
8
|
def properties
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
[]
|
14
|
-
end
|
9
|
+
props = cached_responce[:itemprops_get_response][:item_props][:item_prop]
|
10
|
+
props.map { |prop| Taobao::Property.new(prop) }
|
11
|
+
rescue NoMethodError
|
12
|
+
[]
|
15
13
|
end
|
16
14
|
|
17
15
|
def retrieve_response
|
data/lib/taobao/user.rb
CHANGED
data/lib/taobao/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"itemcats_get_response":{}}
|
@@ -1 +1 @@
|
|
1
|
-
{"
|
1
|
+
{"error_response":{"code":41,"msg":"Invalid arguments:cids"}}
|
data/spec/rspec/category_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe Taobao::Category do
|
|
11
11
|
describe '#name' do
|
12
12
|
it 'should returns the name of the category' do
|
13
13
|
category = Taobao::Category.new(28)
|
14
|
-
fixture = 'category
|
14
|
+
fixture = 'category'.json_fixture
|
15
15
|
args = {
|
16
16
|
method: 'taobao.itemcats.get',
|
17
17
|
fields: 'cid,parent_cid,name,is_parent',
|
@@ -21,35 +21,30 @@ describe Taobao::Category do
|
|
21
21
|
category.name.should == 'ZIPPO/瑞士军刀/眼镜'
|
22
22
|
end
|
23
23
|
it 'should throws an exception if the category ID is incorrect' do
|
24
|
-
|
25
|
-
args = {
|
26
|
-
method: 'taobao.itemcats.get',
|
27
|
-
fields: 'cid,parent_cid,name,is_parent',
|
28
|
-
cids: -20
|
29
|
-
}
|
30
|
-
Taobao.stub(:api_request).with(args).and_return(fixture)
|
24
|
+
Net::HTTP.stub(:post_form).and_return 'incorrect_category'.to_response
|
31
25
|
category = Taobao::Category.new(-20)
|
32
26
|
expect {
|
33
27
|
category.name
|
34
|
-
}.to raise_error Taobao::
|
28
|
+
}.to raise_error Taobao::ApiError, 'Invalid arguments:cids'
|
35
29
|
end
|
36
30
|
end
|
37
31
|
|
38
32
|
describe '#subcategories' do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
method: 'taobao.itemcats.get',
|
43
|
-
fields: 'cid,parent_cid,name,is_parent',
|
44
|
-
parent_cid: 28
|
45
|
-
}
|
33
|
+
before :each do
|
34
|
+
@category = Taobao::Category.new(28)
|
35
|
+
end
|
46
36
|
it 'should returns subcategories if they are exists' do
|
47
|
-
Taobao.stub(:api_request).
|
48
|
-
category.subcategories.should have_at_least(1).subcategory
|
37
|
+
Taobao.stub(:api_request).and_return 'subcategories'.json_fixture
|
38
|
+
@category.subcategories.should have_at_least(1).subcategory
|
39
|
+
end
|
40
|
+
it 'should returns empty array if subcategories do not exist' do
|
41
|
+
Taobao.stub(:api_request).and_return 'category_without_subcategories'.json_fixture
|
42
|
+
@category.subcategories.should be_empty
|
49
43
|
end
|
50
44
|
it 'each subcategory should be an object of Taobao::Category class' do
|
51
|
-
Taobao.stub(:api_request).
|
52
|
-
category.subcategories[0].should be_a_kind_of(Taobao::Category)
|
45
|
+
Taobao.stub(:api_request).and_return 'subcategories'.json_fixture
|
46
|
+
@category.subcategories[0].should be_a_kind_of(Taobao::Category)
|
47
|
+
@category.subcategories[0].id.should be > 0
|
53
48
|
end
|
54
49
|
end
|
55
50
|
|
@@ -6,7 +6,7 @@ describe Taobao::ProductList do
|
|
6
6
|
describe 'init with default options and category id' do
|
7
7
|
pl = Taobao::ProductList.new(cid: 28)
|
8
8
|
|
9
|
-
fixture = 'items
|
9
|
+
fixture = 'items'.json_fixture
|
10
10
|
args = {
|
11
11
|
method: 'taobao.items.get',
|
12
12
|
fields: 'num_iid,title,nick,pic_url,cid,price,type,delist_time,post_fee,score,volume',
|
@@ -32,7 +32,7 @@ describe Taobao::ProductList do
|
|
32
32
|
.per_page(10)
|
33
33
|
.order_by_price
|
34
34
|
|
35
|
-
fixture = 'items_page15
|
35
|
+
fixture = 'items_page15'.json_fixture
|
36
36
|
args = {
|
37
37
|
method: 'taobao.items.get',
|
38
38
|
fields: 'num_iid,title,nick,pic_url,cid,price,type,delist_time,post_fee,score,volume',
|
@@ -60,7 +60,7 @@ describe Taobao::ProductList do
|
|
60
60
|
describe 'category without items' do
|
61
61
|
it 'should return 0 items' do
|
62
62
|
pl = Taobao::ProductList.new(cid: 283333)
|
63
|
-
fixture = 'no_items
|
63
|
+
fixture = 'no_items'.json_fixture
|
64
64
|
args = {
|
65
65
|
method: 'taobao.items.get',
|
66
66
|
fields: 'num_iid,title,nick,pic_url,cid,price,type,delist_time,post_fee,score,volume',
|
data/spec/rspec/product_spec.rb
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Taobao::Product do
|
5
|
-
|
6
|
-
fixture = 'product.json'.json_fixture
|
5
|
+
before(:each) do
|
7
6
|
args = {
|
8
7
|
method: 'taobao.item.get',
|
9
8
|
fields: 'cid,num_iid,title,nick,price,pic_url,type,score,delist_time,' +
|
@@ -15,33 +14,38 @@ describe Taobao::Product do
|
|
15
14
|
'property_alias,item_img,prop_img,sku,video,outer_id,is_virtual',
|
16
15
|
num_iid: '2997802325'
|
17
16
|
}
|
17
|
+
fixture = 'product'.json_fixture
|
18
|
+
Taobao.stub(:api_request).with(args).and_return(fixture)
|
19
|
+
@product = Taobao::Product.new(2997802325)
|
20
|
+
end
|
18
21
|
|
22
|
+
describe 'initialize with id' do
|
19
23
|
it 'should returns product' do
|
20
|
-
|
21
|
-
product
|
24
|
+
@product.cid.should == 1512
|
25
|
+
@product.nick.should == '奇迹shouji'
|
26
|
+
@product.num_iid.should == 2997802325
|
27
|
+
@product.pic_url.should == 'http://img03.taobaocdn.com/bao/uploaded/i3/T1YsfeXbxkXXXpZak._110941.jpg'
|
28
|
+
@product.price.should == 4300.00
|
29
|
+
@product.title.should == '可完美越狱 Apple/苹果 iPhone 4S 正品 装软件 未拆封 未激活'
|
22
30
|
|
23
|
-
product.
|
24
|
-
product.
|
25
|
-
product.
|
26
|
-
product.
|
27
|
-
product.price.should == 4300.00
|
28
|
-
product.title.should == '可完美越狱 Apple/苹果 iPhone 4S 正品 装软件 未拆封 未激活'
|
29
|
-
|
30
|
-
product.approve_status.should == 'onsale'
|
31
|
-
product.auction_point.should == 0
|
32
|
-
product.delist_time.should == '2012-06-01 22:41:44'
|
33
|
-
product.type.should == 'fixed'
|
31
|
+
@product.approve_status.should == 'onsale'
|
32
|
+
@product.auction_point.should == 0
|
33
|
+
@product.delist_time.should == '2012-06-01 22:41:44'
|
34
|
+
@product.type.should == 'fixed'
|
34
35
|
end
|
35
36
|
|
36
37
|
describe 'get unknown product property' do
|
37
38
|
it 'should raise an exception' do
|
38
|
-
Taobao.stub(:api_request).with(args).and_return(fixture)
|
39
|
-
product = Taobao::Product.new(2997802325)
|
40
39
|
expect {
|
41
|
-
product.unknown_property
|
40
|
+
@product.unknown_property
|
42
41
|
}.to raise_error NoMethodError
|
43
42
|
end
|
44
43
|
end
|
44
|
+
end
|
45
45
|
|
46
|
+
describe '#user' do
|
47
|
+
it 'should returns Taobao::User object' do
|
48
|
+
@product.user.should be_a_kind_of Taobao::User
|
49
|
+
end
|
46
50
|
end
|
47
51
|
end
|
@@ -7,7 +7,7 @@ describe Taobao::PropertyList do
|
|
7
7
|
it 'should returns property' do
|
8
8
|
property_list = Taobao::PropertyList.new(cid: 1512)
|
9
9
|
|
10
|
-
fixture = 'category_properties
|
10
|
+
fixture = 'category_properties'.json_fixture
|
11
11
|
args = {
|
12
12
|
method: 'taobao.itemprops.get',
|
13
13
|
fields: 'pid,name,prop_values,must,multi,is_color_prop,is_key_prop,is_enum_prop,is_input_prop,is_sale_prop,is_item_prop',
|
@@ -23,7 +23,7 @@ describe Taobao::PropertyList do
|
|
23
23
|
it 'should returns 0 properties' do
|
24
24
|
property_list = Taobao::PropertyList.new(cid: 0)
|
25
25
|
|
26
|
-
fixture = 'top_category_properties
|
26
|
+
fixture = 'top_category_properties'.json_fixture
|
27
27
|
args = {
|
28
28
|
method: 'taobao.itemprops.get',
|
29
29
|
fields: 'pid,name,prop_values,must,multi,is_color_prop,is_key_prop,is_enum_prop,is_input_prop,is_sale_prop,is_item_prop',
|
data/spec/rspec/property_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Taobao::Property do
|
|
5
5
|
describe 'initialize' do
|
6
6
|
describe 'with correct data' do
|
7
7
|
it 'should create Property object' do
|
8
|
-
property_response = 'property
|
8
|
+
property_response = 'property'.json_fixture
|
9
9
|
property = Taobao::Property.new(property_response)
|
10
10
|
|
11
11
|
property.multi.should be_false
|
data/spec/rspec/search_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Taobao do
|
|
6
6
|
describe 'search method returns product list' do
|
7
7
|
search = Taobao::search('iPhone')
|
8
8
|
|
9
|
-
fixture = 'search
|
9
|
+
fixture = 'search'.json_fixture
|
10
10
|
args = {
|
11
11
|
method: 'taobao.items.get',
|
12
12
|
fields: 'num_iid,title,nick,pic_url,cid,price,type,delist_time,post_fee,score,volume',
|
data/spec/rspec/taobao_spec.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
Response = Struct.new('Responce', :body)
|
4
|
-
|
5
3
|
describe Taobao do
|
6
4
|
describe 'set the public API key' do
|
7
5
|
it 'should have rw access' do
|
@@ -18,8 +16,7 @@ describe Taobao do
|
|
18
16
|
end
|
19
17
|
describe 'API request' do
|
20
18
|
it 'should always return a Hash object' do
|
21
|
-
|
22
|
-
Net::HTTP.stub(:post_form).and_return(fixture)
|
19
|
+
Net::HTTP.stub(:post_form).and_return 'category'.to_response
|
23
20
|
result = Taobao.api_request(method: 'taobao.itemcats.get',
|
24
21
|
fields: 'cid,parent_cid,name,is_parent', cids: 0)
|
25
22
|
result.should be_a_kind_of(Hash)
|
@@ -27,8 +24,7 @@ describe Taobao do
|
|
27
24
|
end
|
28
25
|
describe 'failed API request' do
|
29
26
|
it 'should throws an exception' do
|
30
|
-
|
31
|
-
Net::HTTP.stub(:post_form).and_return(fixture)
|
27
|
+
Net::HTTP.stub(:post_form).and_return 'error'.to_response
|
32
28
|
expect { Taobao.api_request({}) }
|
33
29
|
.to raise_error(Taobao::ApiError, 'Invalid arguments:cid')
|
34
30
|
end
|
data/spec/rspec/user_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
describe Taobao::User do
|
5
5
|
describe 'getting user by valid nickname' do
|
6
6
|
it 'should returns valid user info' do
|
7
|
-
fixture = 'user
|
7
|
+
fixture = 'user'.json_fixture
|
8
8
|
args = {
|
9
9
|
method: 'taobao.user.get',
|
10
10
|
fields: 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,' +
|
@@ -16,6 +16,7 @@ describe Taobao::User do
|
|
16
16
|
|
17
17
|
user = Taobao::User.new('喜客多2008')
|
18
18
|
|
19
|
+
user.nick.should == '喜客多2008'
|
19
20
|
user.good_purchases_count.should == 1292
|
20
21
|
user.buyer_level.should == 8
|
21
22
|
user.buyer_score.should == 1292
|
@@ -41,7 +42,7 @@ describe Taobao::User do
|
|
41
42
|
end
|
42
43
|
describe 'getting user who does not specify his/her sex' do
|
43
44
|
it 'should returns :unknown value' do
|
44
|
-
fixture = 'user_unknown_sex
|
45
|
+
fixture = 'user_unknown_sex'.json_fixture
|
45
46
|
args = {
|
46
47
|
method: 'taobao.user.get',
|
47
48
|
fields: 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,' +
|
@@ -57,7 +58,7 @@ describe Taobao::User do
|
|
57
58
|
|
58
59
|
describe 'getting non-existent user' do
|
59
60
|
it 'should throws an exception' do
|
60
|
-
fixture = 'absent_user
|
61
|
+
fixture = 'absent_user'.json_fixture
|
61
62
|
args = {
|
62
63
|
method: 'taobao.user.get',
|
63
64
|
fields: 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,' +
|
data/spec/spec_helper.rb
CHANGED
@@ -8,13 +8,19 @@ end
|
|
8
8
|
|
9
9
|
require 'taobaorb'
|
10
10
|
|
11
|
+
Response = Struct.new('Responce', :body)
|
12
|
+
|
11
13
|
class String
|
12
|
-
def
|
13
|
-
|
14
|
+
def to_response
|
15
|
+
Response.new get_fixture_as_text
|
14
16
|
end
|
15
17
|
|
16
18
|
def json_fixture
|
17
|
-
|
18
|
-
|
19
|
+
JSON.parse get_fixture_as_text, {symbolize_names: true}
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def get_fixture_as_text
|
24
|
+
open("spec/fixtures/#{self}.json").read
|
19
25
|
end
|
20
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taobaorb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby wrapper for the Taobao API
|
15
15
|
email: a741su@gmail.com
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- spec/fixtures/absent_user.json
|
39
39
|
- spec/fixtures/category.json
|
40
40
|
- spec/fixtures/category_properties.json
|
41
|
+
- spec/fixtures/category_without_subcategories.json
|
41
42
|
- spec/fixtures/error.json
|
42
43
|
- spec/fixtures/incorrect_category.json
|
43
44
|
- spec/fixtures/items.json
|
@@ -75,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
76
|
version: '0'
|
76
77
|
segments:
|
77
78
|
- 0
|
78
|
-
hash:
|
79
|
+
hash: -1342558535374082704
|
79
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
81
|
none: false
|
81
82
|
requirements:
|
@@ -84,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
85
|
version: '0'
|
85
86
|
segments:
|
86
87
|
- 0
|
87
|
-
hash:
|
88
|
+
hash: -1342558535374082704
|
88
89
|
requirements: []
|
89
90
|
rubyforge_project:
|
90
91
|
rubygems_version: 1.8.24
|