taobaorb 0.8.3 → 0.9.0

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.
@@ -0,0 +1,16 @@
1
+ class Taobao::AbstractList
2
+ include Enumerable
3
+
4
+ def initialize(opts)
5
+ @opts = opts
6
+ end
7
+
8
+ private
9
+ def cached_responce
10
+ @response ||= retrieve_response
11
+ end
12
+
13
+ def clear_response
14
+ @response = nil
15
+ end
16
+ end
data/lib/taobao/base.rb CHANGED
@@ -4,21 +4,21 @@ require 'net/http'
4
4
  require 'json'
5
5
 
6
6
  module Taobao
7
-
7
+
8
8
  API_VERSION = '2.0'
9
9
  PRODUCTION_URL = 'http://gw.api.taobao.com/router/rest'
10
-
10
+
11
11
  class << self
12
12
  attr_accessor :public_key
13
13
  attr_writer :private_key
14
14
  end
15
-
15
+
16
16
  def self.api_request(options)
17
17
  uri = URI(PRODUCTION_URL)
18
18
  response = Net::HTTP.post_form uri, self.append_required_options(options)
19
19
  parse_to_hash response
20
20
  end
21
-
21
+
22
22
  private
23
23
  def self.create_signature(options)
24
24
  values_str = options.sort.inject('') do |str, item|
@@ -27,7 +27,7 @@ module Taobao
27
27
  str = @private_key.to_s + values_str + @private_key.to_s
28
28
  Digest::MD5.hexdigest(str).upcase
29
29
  end
30
-
30
+
31
31
  def self.append_required_options(options)
32
32
  options.merge!({
33
33
  app_key: @public_key,
@@ -39,7 +39,7 @@ module Taobao
39
39
  options[:sign] = self.create_signature(options)
40
40
  options
41
41
  end
42
-
42
+
43
43
  def self.parse_to_hash(response)
44
44
  result = JSON.parse response.body, {symbolize_names: true}
45
45
  raise Taobao::ApiError.new(result) if result.key? :error_response
@@ -1,36 +1,26 @@
1
1
  class Taobao::Category
2
2
  attr_reader :id
3
-
3
+
4
4
  def initialize(category_id)
5
5
  @id = category_id.to_i
6
6
  end
7
-
7
+
8
8
  def name
9
- return @name if @name
10
- @name = category_request(cids: @id).first[:name]
9
+ @name ||= category_request(cids: @id).first[:name]
11
10
  end
12
-
11
+
13
12
  def subcategories
14
- return @subcategories if @subcategories
15
- @subcategories = category_request(parent_cid: @id)
13
+ @subcategories ||= category_request(parent_cid: @id)
16
14
  end
17
-
15
+
18
16
  def properties
19
- return @properties if @properties
20
- fields = [:pid, :name, :must, :multi, :prop_values].join ','
21
- params = {method: 'taobao.itemprops.get', fields: fields, cid: @id}
22
- result = Taobao.api_request params
23
- begin
24
- result[:itemprops_get_response][:item_props][:item_prop]
25
- rescue NoMethodError
26
- @properties = []
27
- end
17
+ @properties ||= Taobao::PropertyList.new(cid: @id)
28
18
  end
29
-
19
+
30
20
  def products
31
- Taobao::ProductList.new(cid: @id)
21
+ @products ||= Taobao::ProductList.new(cid: @id)
32
22
  end
33
-
23
+
34
24
  private
35
25
  def category_request(optional_params)
36
26
  fields = [:cid, :parent_cid, :name, :is_parent].join ','
@@ -42,5 +32,5 @@ class Taobao::Category
42
32
  raise Taobao::IncorrectCategoryId, 'Incorrect category ID'
43
33
  end
44
34
  end
45
-
35
+
46
36
  end
@@ -2,7 +2,7 @@ class Taobao::ApiError < StandardError
2
2
  def initialize(response)
3
3
  @msg = response[:error_response][:msg]
4
4
  end
5
-
5
+
6
6
  def to_s
7
7
  @msg
8
8
  end
@@ -0,0 +1,2 @@
1
+ class Taobao::IncorrectProperty < StandardError
2
+ end
@@ -22,15 +22,16 @@ class Taobao::Product
22
22
  else
23
23
  @num_iid = product_properties.to_s
24
24
  fetch_full_data
25
+ convert_data_types
25
26
  end
26
27
  end
27
28
 
28
29
  def method_missing(method_name, *args, &block)
29
- unless @properties.include? method_name
30
- super
31
- else
30
+ if @properties.include? method_name
32
31
  fetch_full_data unless @all_properties_fetched
33
32
  self.instance_variable_get "@#{method_name}"
33
+ else
34
+ super
34
35
  end
35
36
  end
36
37
 
@@ -49,4 +50,8 @@ class Taobao::Product
49
50
  hash_to_object(result[:item_get_response][:item])
50
51
  @all_properties_fetched = true
51
52
  end
53
+
54
+ def convert_data_types
55
+ @price = @price.to_f
56
+ end
52
57
  end
@@ -1,38 +1,27 @@
1
- class Taobao::ProductList
2
-
3
- include Enumerable
4
-
5
- def initialize(opts)
6
- @opts = opts
7
- end
8
-
1
+ class Taobao::ProductList < Taobao::AbstractList
2
+
9
3
  def size
10
4
  products.size
11
5
  end
12
-
13
- def total_count
14
- memoize_api_result
15
- @total_count
16
- end
17
-
6
+
18
7
  def page(num)
19
- @products = nil
8
+ clear_response
20
9
  @opts[:page_no] = num
21
10
  self
22
11
  end
23
-
12
+
24
13
  def per_page(num)
25
- @products = nil
14
+ clear_response
26
15
  @opts[:page_size] = num
27
16
  self
28
17
  end
29
-
18
+
30
19
  def order_by(field)
31
- @products = nil
20
+ clear_response
32
21
  @opts[:order_by] = field
33
22
  self
34
23
  end
35
-
24
+
36
25
  def method_missing(method_name, *args, &block)
37
26
  if (m = /^order_by_(?<field>.+)$/.match method_name)
38
27
  order_by m[:field]
@@ -40,44 +29,32 @@ class Taobao::ProductList
40
29
  super
41
30
  end
42
31
  end
43
-
32
+
44
33
  def each(&block)
45
34
  products.each{|item| block.call(item)}
46
35
  end
47
-
36
+
37
+ def total_count
38
+ cached_responce[:items_get_response][:total_results].to_i
39
+ end
40
+
48
41
  private
49
42
  def products
50
- memoize_api_result
51
- @products
52
- end
53
-
54
- def memoize_api_result
55
- return if @products
56
- response = items_get_request
57
- @total_count = retrieve_total_count(response)
58
- @products = retrieve_products(response)
59
- end
60
-
61
- def retrieve_total_count(response)
62
- response[:items_get_response][:total_results].to_i
63
- end
64
-
65
- def retrieve_products(response)
66
43
  begin
67
- products = response[:items_get_response][:items][:item]
44
+ products = cached_responce[:items_get_response][:items][:item]
68
45
  get_products_as_objects(products)
69
46
  rescue NoMethodError
70
47
  []
71
48
  end
72
49
  end
73
-
50
+
74
51
  def get_products_as_objects(products)
75
52
  products.map do |product|
76
53
  Taobao::Product.new(product)
77
54
  end
78
55
  end
79
-
80
- def items_get_request
56
+
57
+ def retrieve_response
81
58
  fields = [:num_iid, :title, :nick, :pic_url, :cid, :price, :type,
82
59
  :delist_time, :post_fee, :score, :volume].join ','
83
60
  params = {method: 'taobao.items.get', fields: fields}
@@ -0,0 +1,18 @@
1
+ class Taobao::Property
2
+ attr_reader :multi, :must, :name, :pid, :values
3
+ include Taobao::Util
4
+
5
+ def initialize(response)
6
+ @response = response
7
+ to_object response
8
+ @values = get_values
9
+ raise Taobao::IncorrectProperty, 'Incorrect property data' if @name.nil?
10
+ end
11
+
12
+ private
13
+ def get_values
14
+ @response[:prop_values][:prop_value]
15
+ rescue NoMethodError
16
+ []
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ class Taobao::PropertyList < Taobao::AbstractList
2
+
3
+ def each(&block)
4
+ properties.each{ |item| block.call(item) }
5
+ end
6
+
7
+ private
8
+ def properties
9
+ begin
10
+ props = cached_responce[:itemprops_get_response][:item_props][:item_prop]
11
+ props.map { |prop| Taobao::Property.new(prop) }
12
+ rescue NoMethodError
13
+ []
14
+ end
15
+ end
16
+
17
+ def retrieve_response
18
+ fields = [:pid, :name, :prop_values, :must, :multi, :is_color_prop,
19
+ :is_key_prop, :is_enum_prop, :is_input_prop, :is_sale_prop,
20
+ :is_item_prop].join ','
21
+ params = {method: 'taobao.itemprops.get', fields: fields}
22
+ Taobao.api_request params.merge(@opts)
23
+ end
24
+ end
@@ -0,0 +1,92 @@
1
+ require 'date'
2
+
3
+ class Taobao::User
4
+
5
+ def initialize(nickname)
6
+ @nick = nickname
7
+ end
8
+
9
+ def good_purchases_count
10
+ cached_response[:buyer_credit][:good_num].to_i
11
+ end
12
+
13
+ def buyer_level
14
+ cached_response[:buyer_credit][:level].to_i
15
+ end
16
+
17
+ def buyer_score
18
+ cached_response[:buyer_credit][:score].to_i
19
+ end
20
+
21
+ def total_purchases_count
22
+ cached_response[:buyer_credit][:total_num].to_i
23
+ end
24
+
25
+ def good_sales_count
26
+ cached_response[:seller_credit][:good_num].to_i
27
+ end
28
+
29
+ def seller_level
30
+ cached_response[:seller_credit][:level].to_i
31
+ end
32
+
33
+ def seller_score
34
+ cached_response[:seller_credit][:score].to_i
35
+ end
36
+
37
+ def total_sales_count
38
+ cached_response[:seller_credit][:total_num].to_i
39
+ end
40
+
41
+ def registration_date
42
+ DateTime.parse cached_response[:created]
43
+ end
44
+
45
+ def last_visit
46
+ DateTime.parse cached_response[:last_visit]
47
+ end
48
+
49
+ def city
50
+ cached_response[:location][:city]
51
+ end
52
+
53
+ def state
54
+ cached_response[:location][:state]
55
+ end
56
+
57
+ def sex
58
+ if cached_response.has_key? :sex
59
+ return :male if cached_response[:sex] == 'm'
60
+ return :female if cached_response[:sex] == 'f'
61
+ end
62
+ :unknown
63
+ end
64
+
65
+ def type
66
+ cached_response[:type]
67
+ end
68
+
69
+ def uid
70
+ cached_response[:uid]
71
+ end
72
+
73
+ def id
74
+ cached_response[:user_id].to_i
75
+ end
76
+
77
+ private
78
+ def cached_response
79
+ @response ||= retrieve_response[:user_get_response][:user]
80
+ @response
81
+ end
82
+
83
+ def retrieve_response
84
+ fields = [:user_id, :uid, :nick, :sex, :buyer_credit, :seller_credit,
85
+ :location, :created, :last_visit, :birthday, :type, :status, :alipay_no,
86
+ :alipay_account, :alipay_account, :email, :consumer_protection,
87
+ :alipay_bind].join ','
88
+ params = {method: 'taobao.user.get', fields: fields, nick: @nick}
89
+ Taobao.api_request params
90
+ end
91
+
92
+ end
@@ -0,0 +1,7 @@
1
+ module Taobao::Util
2
+ def to_object(hash)
3
+ hash.each do |k, v|
4
+ self.instance_variable_set "@#{k}", v
5
+ end
6
+ end
7
+ end
data/lib/taobaorb.rb CHANGED
@@ -1,7 +1,16 @@
1
1
  require 'taobao/base'
2
+ require 'taobao/util'
3
+
2
4
  require 'taobao/exceptions/api_error'
3
5
  require 'taobao/exceptions/incorrect_category_id'
6
+ require 'taobao/exceptions/incorrect_property'
7
+
4
8
  require 'taobao/category'
5
9
  require 'taobao/product'
10
+ require 'taobao/property'
11
+ require 'taobao/search'
12
+ require 'taobao/user'
13
+
14
+ require 'taobao/abstract_list'
6
15
  require 'taobao/product_list'
7
- require 'taobao/search'
16
+ require 'taobao/property_list'
@@ -0,0 +1 @@
1
+ {"error_response":{"code":50,"msg":"Remote service error","sub_code":"isv.user-not-exist:invalid-nick","sub_msg":"根据用户昵称:unknown_taobao_user查询不到对应的用户信息"}}
@@ -1 +1 @@
1
- {"itemprops_get_response":{"item_props":{"item_prop":[{"multi":true,"must":false,"name":"颜色分类","pid":1627207,"prop_values":{"prop_value":[{"name":"军绿色","vid":3232483},{"name":"天蓝色","vid":3232484},{"name":"巧克力色","vid":3232481},{"name":"桔色","vid":90554},{"name":"浅灰色","vid":28332},{"name":"浅绿色","vid":30156},{"name":"浅黄色","vid":60092},{"name":"深卡其布色","vid":3232482},{"name":"深灰色","vid":3232478},{"name":"深紫色","vid":3232479},{"name":"深蓝色","vid":28340},{"name":"白色","vid":28320},{"name":"粉红色","vid":3232480},{"name":"紫罗兰","vid":80882},{"name":"紫色","vid":28329},{"name":"红色","vid":28326},{"name":"绿色","vid":28335},{"name":"花色 ","vid":130164},{"name":"蓝色","vid":28338},{"name":"褐色","vid":132069},{"name":"透明","vid":107121},{"name":"酒红色","vid":28327},{"name":"黄色","vid":28324},{"name":"黑色","vid":28341}]}},{"multi":false,"must":true,"name":"按风扇配置","pid":34405,"prop_values":{"prop_value":[{"name":"无","vid":10010},{"name":"1个","vid":105375},{"name":"2个","vid":105376},{"name":"3个","vid":131069},{"name":"4个","vid":105377},{"name":"其它","vid":10122}]}},{"multi":false,"must":true,"name":"按散热方式","pid":34406,"prop_values":{"prop_value":[{"name":"风冷","vid":128399},{"name":"热管","vid":131070},{"name":"液冷","vid":131071},{"name":"其它","vid":10122}]}},{"multi":false,"must":false,"name":"品牌","pid":20000,"prop_values":{"prop_value":[{"is_parent":true,"name":"ACTTO","vid":8940526},{"is_parent":true,"name":"Actto\/安尚","vid":4245182},{"is_parent":true,"name":"Ajazz\/黑爵","vid":49673634},{"is_parent":true,"name":"Aoago\/安华高","vid":4465054},{"is_parent":true,"name":"Aoni\/奥尼","vid":30986},{"is_parent":true,"name":"Belkin\/贝尔金","vid":21993},{"name":"Coio","vid":68555858},{"is_parent":true,"name":"Cool Cold\/越来越酷","vid":27330734},{"is_parent":true,"name":"Cool Fan\/酷风","vid":10855809},{"is_parent":true,"name":"Cooler Master\/酷冷至尊","vid":22026},{"is_parent":true,"name":"Cooskin\/酷奇","vid":3221126},{"is_parent":true,"name":"K-Mic\/金麦克","vid":23289931},{"is_parent":true,"name":"Kensington\/肯辛通","vid":4534862},{"is_parent":true,"name":"Logitech\/罗技","vid":20802},{"is_parent":true,"name":"Morpin\/摩品","vid":66306088},{"is_parent":true,"name":"Raoopt\/锐珀","vid":72111094},{"is_parent":true,"name":"Sorung","vid":89487913},{"is_parent":true,"name":"Suntai\/星钛","vid":90657293},{"is_parent":true,"name":"Targus\/泰格斯","vid":95999},{"is_parent":true,"name":"Thermaltake","vid":29583},{"is_parent":true,"name":"Transformers","vid":3261509},{"is_parent":true,"name":"WM\/维美传奇","vid":5758392},{"is_parent":true,"name":"corecool","vid":7725273},{"is_parent":true,"name":"ermic易麦","vid":4540138},{"is_parent":true,"name":"fad","vid":3250293},{"is_parent":true,"name":"七河","vid":44338750},{"is_parent":true,"name":"乐光","vid":26078497},{"name":"依依本色","vid":26585558},{"is_parent":true,"name":"冷板凳","vid":3345590},{"is_parent":true,"name":"博奇","vid":4538123},{"is_parent":true,"name":"埃伦","vid":16605835},{"is_parent":true,"name":"奥迪嘉","vid":4393249},{"is_parent":true,"name":"帝特","vid":3626511},{"is_parent":true,"name":"广弓","vid":97578386},{"is_parent":true,"name":"捷冷","vid":29580},{"is_parent":true,"name":"智派","vid":39033078},{"is_parent":true,"name":"浩业","vid":30771625},{"is_parent":true,"name":"AIKE\/爱客","vid":3250522},{"is_parent":true,"name":"硕王","vid":73871762},{"is_parent":true,"name":"终极者","vid":6037756},{"is_parent":true,"name":"美怡","vid":3842057},{"is_parent":true,"name":"蓝蚂蚁","vid":4220099},{"is_parent":true,"name":"赛鲸","vid":86563794},{"is_parent":true,"name":"超频三","vid":29579},{"is_parent":true,"name":"金圣斯\/Kingsons","vid":17925226},{"is_parent":true,"name":"雷洛","vid":3279963},{"is_parent":true,"name":"鸿浪","vid":7896423},{"is_parent":true,"name":"劲冷","vid":30571},{"is_parent":true,"name":"Deepcool\/九州风神","vid":22024},{"is_parent":true,"name":"Zalman\/思民","vid":31049},{"is_parent":true,"name":"Idock","vid":129976},{"is_parent":true,"name":"其他品牌","vid":81443},{"is_parent":true,"name":"Ecola\/宜客莱","vid":4535418}]}}]}}}
1
+ {"itemprops_get_response":{"item_props":{"item_prop":[{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":true,"is_sale_prop":false,"multi":false,"must":true,"name":"品牌","pid":20000,"prop_values":{"prop_value":[{"is_parent":true,"name":"Acer\/宏基","vid":26691},{"is_parent":true,"name":"VIVO","vid":91621},{"is_parent":true,"name":"索爱","vid":39864706},{"is_parent":true,"name":"ACT\/安科讯","vid":74352616},{"is_parent":true,"name":"Aigo\/爱国者","vid":20796},{"is_parent":true,"name":"Alcatel\/阿尔卡特","vid":10283},{"is_parent":true,"name":"Alfa\/阿尔法","vid":7242850},{"is_parent":true,"name":"altek","vid":6832685},{"is_parent":true,"name":"Amoi\/夏新","vid":10779},{"is_parent":true,"name":"Apanda\/首派","vid":78030609},{"is_parent":true,"name":"iPhone","vid":30111},{"is_parent":true,"name":"Asus\/华硕","vid":11656},{"is_parent":true,"name":"AUX\/奥克斯","vid":21210},{"is_parent":true,"name":"AWIT","vid":16639733},{"is_parent":true,"name":"Barbie\/芭比","vid":31881},{"is_parent":true,"name":"Bayi\/贝易通","vid":15179993},{"is_parent":true,"name":"BBK\/步步高","vid":27726},{"name":"Benq\/明基","vid":21657},{"is_parent":true,"name":"BIRD\/波导","vid":10955},{"is_parent":true,"name":"BlackBerry\/黑莓","vid":47416},{"is_parent":true,"name":"Capitel\/首信","vid":10905},{"is_parent":true,"name":"Casio\/卡西欧","vid":21459},{"is_parent":true,"name":"CECT\/中电华通","vid":11057},{"is_parent":true,"name":"Changhong\/长虹","vid":30641},{"is_parent":true,"name":"Coolpad\/酷派","vid":11542},{"is_parent":true,"name":"Daxian\/大显","vid":11454},{"is_parent":true,"name":"DEC\/中恒","vid":117163},{"is_parent":true,"name":"Dell\/戴尔","vid":26683},{"is_parent":true,"name":"Desay\/德赛","vid":123840},{"is_parent":true,"name":"DIM\/迪美","vid":47622},{"is_parent":true,"name":"Disney\/迪士尼","vid":30812},{"is_parent":true,"name":"Dopod\/多普达","vid":33549},{"is_parent":true,"name":"E&middot;Xun","vid":16168852},{"is_parent":true,"name":"elitek \/埃立特","vid":51844},{"is_parent":true,"name":"EPHONE\/易丰","vid":3318426},{"is_parent":true,"name":"Fadar\/锋达通","vid":3278450},{"is_parent":true,"name":"Fujitsu\/富士通","vid":21646},{"is_parent":true,"name":"Gaoke\/高科","vid":27725},{"is_parent":true,"name":"Gigabyte\/技嘉","vid":22005},{"is_parent":true,"name":"Gionee\/金立","vid":11531},{"is_parent":true,"name":"GNET\/三巨网","vid":123851},{"is_parent":true,"name":"GREAT","vid":4146587},{"is_parent":true,"name":"GT佳通","vid":95989},{"is_parent":true,"name":"G&rsquo;FIVE","vid":44443225},{"is_parent":true,"name":"G&rsquo;HONG","vid":134542668},{"is_parent":true,"name":"Haier\/海尔","vid":11016},{"is_parent":true,"name":"七喜","vid":105216},{"is_parent":true,"name":"Hisense\/海信","vid":11599},{"is_parent":true,"name":"HKC\/惠科","vid":41263},{"is_parent":true,"name":"HONCON\/宏康","vid":51843},{"is_parent":true,"name":"HOSIN\/欧新","vid":31050551},{"is_parent":true,"name":"HP\/惠普","vid":31140},{"is_parent":true,"name":"HTC","vid":3261618},{"is_parent":true,"name":"Huawei\/华为","vid":11813},{"is_parent":true,"name":"HYUNDAI\/现代","vid":21929},{"is_parent":true,"name":"IDO\/爱度","vid":123836},{"is_parent":true,"name":"ihkc\/弘谷电","vid":80146946},{"is_parent":true,"name":"i-mate","vid":97548},{"is_parent":true,"name":"Imden\/爱摩登","vid":11983257},{"is_parent":true,"name":"IMG\/英迈","vid":4218308},{"is_parent":true,"name":"Jugate\/知己","vid":112282},{"is_parent":true,"name":"Kenuo\/科诺","vid":39592},{"is_parent":true,"name":"Konka\/康佳","vid":11161},{"is_parent":true,"name":"koobee\/酷比","vid":41993221},{"is_parent":true,"name":"KPT","vid":4031620},{"is_parent":true,"name":"K-Touch\/天语","vid":84416},{"is_parent":true,"name":"Kyocera\/京瓷","vid":10713},{"is_parent":true,"name":"Lanwea\/联维","vid":41869104},{"is_parent":true,"name":"Lenovo\/联想","vid":11119},{"is_parent":true,"name":"LEXUE","vid":6994349},{"is_parent":true,"name":"LG","vid":10428},{"is_parent":true,"name":"Lingwin\/聆韵","vid":11544887},{"is_parent":true,"name":"LOVME","vid":6641603},{"is_parent":true,"name":"Malata\/万利达","vid":11653},{"is_parent":true,"name":"MASTONE\/万事通","vid":123853},{"is_parent":true,"name":"MeiLing\/美菱","vid":30653},{"is_parent":true,"name":"Meizu\/魅族","vid":25143},{"is_parent":true,"name":"MIKI","vid":4155601},{"is_parent":true,"name":"Mio\/宇达电通","vid":33560},{"is_parent":true,"name":"Mitsubishi Electric\/三菱","vid":10459},{"is_parent":true,"name":"MIUI\/小米","vid":3506680},{"is_parent":true,"name":"Mops","vid":80332131},{"is_parent":true,"name":"Motorola\/摩托罗拉","vid":10123},{"is_parent":true,"name":"NAMO","vid":30743053},{"is_parent":true,"name":"NEC","vid":10604},{"is_parent":true,"name":"Newsmy\/纽曼","vid":60679},{"is_parent":true,"name":"Nokia\/诺基亚","vid":33564},{"is_parent":true,"name":"O2","vid":49898},{"is_parent":true,"name":"英华ok","vid":11207},{"is_parent":true,"name":"OPPO","vid":28247},{"is_parent":true,"name":"OQO","vid":112850},{"is_parent":true,"name":"Palm\/奔迈","vid":28606},{"is_parent":true,"name":"Panasonic\/松下","vid":81147},{"is_parent":true,"name":"PANDA\/熊猫","vid":3782897},{"is_parent":true,"name":"Philips\/飞利浦","vid":10246},{"is_parent":true,"name":"Postcom\/新邮通信","vid":51484920},{"is_parent":true,"name":"Rahotech\/锐合通信","vid":90515404},{"is_parent":true,"name":"Sagetel\/萨际通","vid":96358407},{"is_parent":true,"name":"Samsung\/三星","vid":81156},{"is_parent":true,"name":"Sanyo\/三洋","vid":10728},{"is_parent":true,"name":"Sharp\/夏普","vid":10590},{"is_parent":true,"name":"Shma\/硕码","vid":29634077},{"is_parent":true,"name":"simdo","vid":27889953},{"is_parent":true,"name":"SK","vid":10656},{"is_parent":true,"name":"Skyworth\/创维","vid":11841},{"is_parent":true,"name":"Soar\/索爱","vid":20887},{"is_parent":true,"name":"Soaye","vid":84938916},{"is_parent":true,"name":"Sony\/索尼","vid":10209},{"is_parent":true,"name":"SOP","vid":4116461},{"is_parent":true,"name":"Takko","vid":5761211},{"is_parent":true,"name":"TCL","vid":10858},{"is_parent":true,"name":"TEM\/泰蒙","vid":7736875},{"is_parent":true,"name":"TFNET\/泰丰","vid":3294662},{"is_parent":true,"name":"TOOKY\/京崎","vid":111586078},{"is_parent":true,"name":"Toshiba\/东芝","vid":10745},{"is_parent":true,"name":"TP-Link\/普联技术","vid":31109},{"is_parent":true,"name":"TSD\/腾盛达","vid":95981},{"is_parent":true,"name":"T-Smart\/天迈","vid":15743043},{"is_parent":true,"name":"U9","vid":123463},{"is_parent":true,"name":"UKING","vid":38798768},{"is_parent":true,"name":"Umeox","vid":27918237},{"is_parent":true,"name":"UMO\/优摩","vid":91320508},{"is_parent":true,"name":"清华紫光","vid":11659},{"is_parent":true,"name":"UNITONE\/友利通","vid":95988},{"is_parent":true,"name":"UT Starcom\/UT斯达康","vid":11372},{"is_parent":true,"name":"VEVA","vid":3283405},{"is_parent":true,"name":"VIM","vid":7815822},{"is_parent":true,"name":"VOTO","vid":36077726},{"is_parent":true,"name":"V-Spring\/语泉","vid":6959181},{"is_parent":true,"name":"V.Land\/葳朗","vid":114173336},{"is_parent":true,"name":"Well Phone 沃普丰","vid":69015717},{"is_parent":true,"name":"YAS","vid":3278664},{"is_parent":true,"name":"Yoord\/优尔得","vid":44246390},{"is_parent":true,"name":"Yusun\/语信","vid":104029268},{"is_parent":true,"name":"Zeka\/志佳","vid":86281808},{"is_parent":true,"name":"ZTE\/中兴","vid":11208},{"is_parent":true,"name":"爱贝多","vid":6094112},{"is_parent":true,"name":"爱肯","vid":95987},{"is_parent":true,"name":"爱立信","vid":10392},{"is_parent":true,"name":"艾美讯","vid":3228013},{"is_parent":true,"name":"爱易通","vid":45225208},{"is_parent":true,"name":"百迪宝","vid":3373407},{"is_parent":true,"name":"邦华","vid":123837},{"is_parent":true,"name":"宝捷讯","vid":123838},{"is_parent":true,"name":"贝尔丰","vid":3279905},{"is_parent":true,"name":"晨兴","vid":123839},{"is_parent":true,"name":"晨讯","vid":3994933},{"is_parent":true,"name":"诚基","vid":4411943},{"is_parent":true,"name":"大唐","vid":11496},{"name":"迪比特","vid":11412},{"is_parent":true,"name":"帝狼","vid":3272147},{"is_parent":true,"name":"东信","vid":11263},{"is_parent":true,"name":"都宝","vid":123841},{"is_parent":true,"name":"朵唯","vid":26487995},{"is_parent":true,"name":"泛泰","vid":10681},{"is_parent":true,"name":"福日","vid":35647},{"is_parent":true,"name":"港利通","vid":131067},{"is_parent":true,"name":"高斯贝尔","vid":123842},{"is_parent":true,"name":"高新奇","vid":96761},{"is_parent":true,"name":"关爱行","vid":98573949},{"is_parent":true,"name":"广信","vid":123843},{"is_parent":true,"name":"国乾科技","vid":28037329},{"is_parent":true,"name":"国信","vid":3216739},{"is_parent":true,"name":"汉泰","vid":123844},{"is_parent":true,"name":"和信","vid":3284119},{"is_parent":true,"name":"恒基伟业","vid":95983},{"is_parent":true,"name":"互通","vid":11842},{"is_parent":true,"name":"华立","vid":95984},{"is_parent":true,"name":"华录","vid":3794117},{"is_parent":true,"name":"华唐","vid":3276005},{"is_parent":true,"name":"华信","vid":3301892},{"is_parent":true,"name":"华禹","vid":123845},{"is_parent":true,"name":"汇讯","vid":123846},{"is_parent":true,"name":"基尔","vid":7723810},{"is_parent":true,"name":"佳域宇通","vid":55709155},{"is_parent":true,"name":"嘉源","vid":123847},{"is_parent":true,"name":"金鹏","vid":11827},{"is_parent":true,"name":"金星","vid":30650},{"is_parent":true,"name":"康力","vid":3773407},{"name":"科健","vid":11742},{"is_parent":true,"name":"科盛","vid":31868},{"is_parent":true,"name":"蓝天","vid":3260678},{"is_parent":true,"name":"朗讯","vid":10391},{"is_parent":true,"name":"乐目","vid":4023071},{"is_parent":true,"name":"联创","vid":30864},{"is_parent":true,"name":"绿力","vid":123848},{"name":"美晨","vid":10763},{"is_parent":true,"name":"盟宝","vid":3322606},{"is_parent":true,"name":"明基西门子","vid":33503},{"is_parent":true,"name":"摩西","vid":29683},{"is_parent":true,"name":"南极星","vid":123849},{"is_parent":true,"name":"欧博信","vid":6201981},{"is_parent":true,"name":"欧盛","vid":32147904},{"is_parent":true,"name":"欧信","vid":4357282},{"is_parent":true,"name":"普莱达","vid":123850},{"is_parent":true,"name":"普天","vid":11788},{"is_parent":true,"name":"琦基","vid":3217424},{"is_parent":true,"name":"齐乐","vid":3280929},{"is_parent":true,"name":"侨兴","vid":11606},{"is_parent":true,"name":"萨基姆","vid":10374},{"is_parent":true,"name":"赛洛特","vid":3858040},{"is_parent":true,"name":"三盟","vid":113338},{"is_parent":true,"name":"桑达","vid":11497},{"is_parent":true,"name":"深爱","vid":95990},{"is_parent":true,"name":"盛隆","vid":3271450},{"is_parent":true,"name":"盛泰","vid":95982},{"is_parent":true,"name":"淘宝手机","vid":44220689},{"is_parent":true,"name":"特灵通","vid":3278833},{"is_parent":true,"name":"天珑","vid":123852},{"is_parent":true,"name":"天时达","vid":11548},{"is_parent":true,"name":"唯奥","vid":123854},{"is_parent":true,"name":"唯开","vid":10657},{"is_parent":true,"name":"唯科","vid":3283984},{"is_parent":true,"name":"西门子","vid":80946},{"is_parent":true,"name":"心相随","vid":7705835},{"is_parent":true,"name":"新中桥","vid":123855},{"is_parent":true,"name":"熊猫","vid":11610},{"is_parent":true,"name":"雅讯达","vid":123856},{"is_parent":true,"name":"倚天","vid":53934},{"is_parent":true,"name":"易百年","vid":89863143},{"is_parent":true,"name":"亿城","vid":123857},{"is_parent":true,"name":"亿和源","vid":3277378},{"is_parent":true,"name":"亿和源 ","vid":7463807},{"is_parent":true,"name":"亿通","vid":95986},{"is_parent":true,"name":"优Phone","vid":132626185},{"is_parent":true,"name":"优思","vid":4110526},{"is_parent":true,"name":"友旺科技","vid":29632},{"is_parent":true,"name":"友信达","vid":123858},{"is_parent":true,"name":"语音王","vid":3316578},{"is_parent":true,"name":"兆讯达","vid":123859},{"is_parent":true,"name":"振华欧比","vid":95985},{"is_parent":true,"name":"中宝","vid":65985},{"is_parent":true,"name":"中恒","vid":21425},{"is_parent":true,"name":"中天","vid":97072},{"is_parent":true,"name":"众一","vid":123860}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"手机价格区间","pid":21514,"prop_values":{"prop_value":[{"name":"1000元以下","vid":42370},{"name":"1001-2000元","vid":38489},{"name":"2001-3000元","vid":42375},{"name":"3000-4000元","vid":125998},{"name":"4000元以上","vid":42382},{"name":"拍卖","vid":39414}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"上市时间","pid":30606,"prop_values":{"prop_value":[{"is_parent":true,"name":"2011年","vid":10285019},{"is_parent":true,"name":"2010年","vid":11397753},{"is_parent":true,"name":"2009年","vid":107066},{"is_parent":true,"name":"2008年","vid":112030},{"is_parent":true,"name":"2007年","vid":47465},{"is_parent":true,"name":"2006年","vid":28964},{"is_parent":true,"name":"2005年","vid":28963},{"is_parent":true,"name":"2004年","vid":28962},{"name":"2003年以前","vid":92331},{"is_parent":true,"name":"2012年","vid":3271031}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":true,"name":"网络类型","pid":10004,"prop_values":{"prop_value":[{"name":"GSM","vid":10022},{"name":"CDMA","vid":10023},{"name":"移动3G GSM\/TD-SCDMA(3G)","vid":3231341},{"name":"联通3G GSM\/WCDMA(3G)","vid":3231342},{"name":"电信3G CDMA\/CDMA2000(3G)","vid":3231340},{"name":"双模(GSM\/CDMA)","vid":3231343},{"name":"双模(GSM\/CDMA2000)","vid":88043696},{"name":"小灵通","vid":10026},{"name":"其它制式","vid":16325552},{"name":"其他制式","vid":16323156},{"name":"GSM\/WCDMA\/CDMA\/CDMA2000","vid":140699523}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":true,"name":"外观样式","pid":10000,"prop_values":{"prop_value":[{"name":"直板","vid":10000},{"name":"滑盖","vid":10001},{"name":"翻盖","vid":10002},{"name":"侧滑盖","vid":72728132},{"name":"旋转","vid":10003},{"name":"其它","vid":10122}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"主屏尺寸","pid":1627099,"prop_values":{"prop_value":[{"name":"1.8英寸","vid":65234},{"name":"1.9英寸","vid":3231605},{"name":"2.0英寸","vid":90615},{"name":"2.1英寸","vid":3231606},{"name":"2.2英寸","vid":90616},{"name":"2.4英寸","vid":90617},{"name":"2.5英寸","vid":65236},{"name":"2.6英寸","vid":91012},{"name":"2.8英寸","vid":90683},{"name":"2.9英寸","vid":3224791},{"name":"3.0英寸","vid":90619},{"name":"3.1英寸","vid":3263166},{"name":"3.2英寸","vid":3231607},{"name":"3.3英寸","vid":7986728},{"name":"3.4英寸","vid":7986777},{"name":"3.5英寸","vid":65235},{"name":"3.6英寸","vid":90620},{"name":"3.7英寸","vid":13451150},{"name":"3.8英寸","vid":90621},{"name":"4.0英寸","vid":90622},{"name":"4.3英寸","vid":90624},{"name":"其他尺寸","vid":32102},{"name":"4.5英寸","vid":19229459},{"name":"4.2英寸","vid":90623},{"name":"其它尺寸","vid":30025},{"name":"4.65英寸","vid":96062621},{"name":"4.7英寸","vid":76876820},{"name":"4.6英寸","vid":126148907},{"name":"5.0英寸","vid":3253104},{"name":"5.3英寸","vid":135631761},{"name":"7.0英寸","vid":80829},{"name":"7.7英寸","vid":138934665}]}},{"is_color_prop":true,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":true,"multi":true,"must":false,"name":"机身颜色","pid":1627207,"prop_values":{"prop_value":[{"name":"军绿色","vid":3232483},{"name":"天蓝色","vid":3232484},{"name":"巧克力色","vid":3232481},{"name":"桔色","vid":90554},{"name":"浅灰色","vid":28332},{"name":"浅绿色","vid":30156},{"name":"浅黄色","vid":60092},{"name":"深卡其布色","vid":3232482},{"name":"深灰色","vid":3232478},{"name":"深紫色","vid":3232479},{"name":"深蓝色","vid":28340},{"name":"白色","vid":28320},{"name":"粉红色","vid":3232480},{"name":"紫罗兰","vid":80882},{"name":"紫色","vid":28329},{"name":"红色","vid":28326},{"name":"绿色","vid":28335},{"name":"花色 ","vid":130164},{"name":"蓝色","vid":28338},{"name":"褐色","vid":132069},{"name":"透明","vid":107121},{"name":"酒红色","vid":28327},{"name":"黄色","vid":28324},{"name":"黑色","vid":28341}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":true,"multi":true,"must":false,"name":"手机套餐","pid":1630696,"prop_values":{"prop_value":[{"name":"官方标配","vid":6536025},{"name":"套餐一","vid":3266779},{"name":"套餐二","vid":3266781},{"name":"套餐三","vid":3266785},{"name":"套餐四","vid":3266786},{"name":"套餐五","vid":3266789},{"name":"套餐六","vid":3284565},{"name":"套餐七","vid":3284566},{"name":"套餐八","vid":3284567}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":true,"name":"摄像头","pid":10002,"prop_values":{"prop_value":[{"name":"无摄像头","vid":30590},{"name":"10万","vid":10011},{"name":"30万","vid":10012},{"name":"50万","vid":22062},{"name":"100万","vid":20312},{"name":"130万","vid":10013},{"name":"200万","vid":10014},{"name":"300万","vid":10015},{"name":"320万","vid":123484},{"name":"400万","vid":29816},{"name":"500万","vid":27325},{"name":"600万","vid":29771},{"name":"700万","vid":28605},{"name":"800万","vid":29772},{"name":"1200万","vid":3269331},{"name":"1400万","vid":29836},{"name":"其它像素","vid":30589},{"name":"1300万","vid":29835},{"name":"4100万","vid":137838647}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"是否智能手机","pid":20710,"prop_values":{"prop_value":[{"name":"智能手机","vid":21958},{"name":"非智能手机","vid":21959}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"操作系统","pid":20573,"prop_values":{"prop_value":[{"name":"Symbian\/塞班","vid":21589},{"name":"Linux","vid":28968},{"name":"Palm\/奔迈","vid":28606},{"name":"Windows Mobile","vid":21591},{"name":"BlackBerry\/黑莓","vid":47416},{"name":"iPhone","vid":48200},{"name":"Android\/安卓","vid":3227476},{"name":"OMS","vid":3310760},{"name":"Windows phone","vid":84256470},{"name":"meego","vid":48286703},{"name":"其它操作系统","vid":30592},{"name":"无操作系统","vid":30591},{"name":"阿里云操作系统","vid":116033771}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":true,"must":false,"name":"高级功能","pid":20574,"prop_values":{"prop_value":[{"name":"WIFI上网","vid":32517},{"name":"GPS导航","vid":20710},{"name":"电视播放","vid":3224630},{"name":"双卡双待","vid":3224633},{"name":"高清视频","vid":30212998}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":true,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":true,"name":"宝贝成色","pid":20879,"prop_values":{"prop_value":[{"name":"全新","vid":21456},{"name":"9.99成新","vid":32557},{"name":"9.5成新","vid":32558},{"name":"9成新","vid":32559},{"name":"8成新","vid":32561},{"name":"7成及7成以下","vid":51530}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":true,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":true,"name":"售后服务","pid":20930,"prop_values":{"prop_value":[{"name":"全国联保","vid":32998},{"name":"店铺三包","vid":32999},{"name":"其它售后服务","vid":33000}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"触摸屏","pid":9453082,"prop_values":{"prop_value":[{"name":"电容式触摸屏","vid":89595245},{"name":"电阻式触摸屏","vid":89595314}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"手机CPU","pid":12303956,"prop_values":{"prop_value":[{"name":"128M","vid":21484},{"name":"500M以内","vid":119805948},{"name":"512M","vid":21483},{"name":"600M","vid":60570},{"name":"680M","vid":9075757},{"name":"800M","vid":60571},{"name":"1G","vid":75367811},{"name":"1.2G","vid":51786},{"name":"1.4G","vid":43890},{"name":"1.5G","vid":43148},{"name":"1.5G以上","vid":109189776},{"name":"双核1G","vid":109189777},{"name":"双核1.2G","vid":109189778},{"name":"双核1.4G","vid":131630450},{"name":"双核1.5G","vid":109189779},{"name":"其他","vid":20213},{"name":"650M","vid":43888},{"name":"四核1.5G","vid":137963589},{"name":"1.3G","vid":6316102},{"name":"四核1.4G","vid":151473594}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"运行内存RAM","pid":12304004,"prop_values":{"prop_value":[{"name":"64M","vid":21485},{"name":"128M","vid":21484},{"name":"256M","vid":21482},{"name":"512M","vid":21483},{"name":"768M","vid":91603},{"name":"1G","vid":75367811},{"name":"2G","vid":75366757},{"name":"2G以上","vid":42836}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"机身内存ROM","pid":12304035,"prop_values":{"prop_value":[{"name":"128M","vid":21484},{"name":"256M","vid":21482},{"name":"512M","vid":21483},{"name":"768M","vid":91603},{"name":"1.5G","vid":43148},{"name":"1G","vid":75367811},{"name":"2G","vid":75366757},{"name":"4G","vid":75366283},{"name":"8g","vid":75366695},{"name":"16g","vid":48072},{"name":"32G","vid":116177},{"name":"64G","vid":3222911},{"name":"64G以上","vid":109190236}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"键盘类型","pid":10068223,"prop_values":{"prop_value":[{"name":"12键标准键盘","vid":119652018},{"name":"QWERTY全键盘","vid":15756160},{"name":"虚拟触屏键盘","vid":119652019}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"厚度","pid":34375,"prop_values":{"prop_value":[{"name":"超薄(小于9mm)","vid":119650022},{"name":"薄(9mm~1cm)","vid":119650023},{"name":"普通(大于1cm)","vid":119650024}]}},{"is_color_prop":false,"is_enum_prop":true,"is_input_prop":false,"is_item_prop":false,"is_key_prop":false,"is_sale_prop":false,"multi":false,"must":false,"name":"主屏分辨率","pid":13801175,"prop_values":{"prop_value":[{"name":"960&times;640像素","vid":119646504},{"name":"960&times;540像素","vid":119646505},{"name":"1280&times;720像素","vid":119646506},{"name":"854&times;480像素","vid":119646507},{"name":"800&times;480像素","vid":119646509},{"name":"640&times;480像素","vid":119646510},{"name":"480&times;360像素","vid":119646511},{"name":"640&times;360像素","vid":119646512},{"name":"480&times;320像素","vid":119646513},{"name":"320&times;240像素","vid":119646514},{"name":"400&times;240像素","vid":119646515},{"name":"220&times;176像素","vid":119646516},{"name":"1280&times;800像素","vid":124670536},{"name":"1024x768像素","vid":138124316},{"name":"160x128像素","vid":144968324}]}}]}}}
@@ -0,0 +1,20 @@
1
+ {
2
+ "multi":false,
3
+ "must":true,
4
+ "name":"品牌",
5
+ "pid":20000,
6
+ "prop_values": {
7
+ "prop_value": [
8
+ {
9
+ "is_parent":true,
10
+ "name":"Acer\/宏基",
11
+ "vid":26691
12
+ },
13
+ {
14
+ "is_parent":true,
15
+ "name":"CONOR\/酷诺",
16
+ "vid":141848205
17
+ }
18
+ ]
19
+ }
20
+ }
@@ -0,0 +1 @@
1
+ {"user_get_response":{"user":{"buyer_credit":{"good_num":1292,"level":8,"score":1292,"total_num":1292},"created":"2005-12-10 19:03:18","last_visit":"2012-06-29 23:28:25","location":{"city":"金华","state":"浙江"},"nick":"喜客多2008","seller_credit":{"good_num":2587208,"level":18,"score":2576453,"total_num":2624203},"sex":"f","type":"C","uid":"6cd6014f007c04426e2437fef870329a","user_id":18139021}}}
@@ -0,0 +1 @@
1
+ {"user_get_response":{"user":{"buyer_credit":{"good_num":0,"level":0,"score":0,"total_num":0},"created":"2009-01-16 11:26:54","last_visit":"2012-06-29 23:23:57","location":{"city":"广州","state":"广东"},"nick":"t400旗舰店","seller_credit":{"good_num":329528,"level":15,"score":329528,"total_num":329528},"type":"B","uid":"f640763e5f08956d425e445e704b1fc4","user_id":174145821}}}
@@ -6,7 +6,7 @@ describe Taobao::Category do
6
6
  it 'should have name' do
7
7
  category = Taobao::Category.new(28)
8
8
  category.id.should == 28
9
-
9
+
10
10
  fixture = 'category.json'.json_fixture
11
11
  args = {
12
12
  method: 'taobao.itemcats.get',
@@ -14,7 +14,6 @@ describe Taobao::Category do
14
14
  cids: 28
15
15
  }
16
16
  Taobao.stub(:api_request).with(args).and_return(fixture)
17
-
18
17
  category.name.should == 'ZIPPO/瑞士军刀/眼镜'
19
18
  end
20
19
 
@@ -28,15 +27,16 @@ describe Taobao::Category do
28
27
  }
29
28
  Taobao.stub(:api_request).with(args).and_return(fixture)
30
29
  category = Taobao::Category.new(-20)
31
- lambda {category.name}
32
- .should raise_error Taobao::IncorrectCategoryId, 'Incorrect category ID'
30
+ expect {
31
+ category.name
32
+ }.to raise_error Taobao::IncorrectCategoryId, 'Incorrect category ID'
33
33
  end
34
34
  end
35
35
 
36
36
  describe 'subcategories' do
37
37
  it 'top level category should contains a few subcategories' do
38
38
  category = Taobao::Category.new(28)
39
-
39
+
40
40
  fixture = 'subcategories.json'.json_fixture
41
41
  args = {
42
42
  method: 'taobao.itemcats.get',
@@ -44,42 +44,21 @@ describe Taobao::Category do
44
44
  parent_cid: 28
45
45
  }
46
46
  Taobao.stub(:api_request).with(args).and_return(fixture)
47
- category.subcategories.size.should be > 0
47
+ category.subcategories.should have_at_least(1).subcategory
48
48
  end
49
49
  end
50
-
50
+
51
51
  describe 'properties' do
52
52
  it 'should return empty array for top level category' do
53
53
  category = Taobao::Category.new(0)
54
- fixture = 'top_category_properties.json'.json_fixture
55
- args = {
56
- method: 'taobao.itemprops.get',
57
- fields: 'pid,name,must,multi,prop_values',
58
- cid: 0
59
- }
60
- Taobao.stub(:api_request).with(args).and_return(fixture)
61
-
62
- category.properties.should == []
63
- end
64
- it 'should return a few properties' do
65
- category = Taobao::Category.new(50005718)
66
-
67
- fixture = 'category_properties.json'.json_fixture
68
- args = {
69
- method: 'taobao.itemprops.get',
70
- fields: 'pid,name,must,multi,prop_values',
71
- cid: 50005718
72
- }
73
- Taobao.stub(:api_request).with(args).and_return(fixture)
74
-
75
- category.properties.size.should be > 0
54
+ category.properties.should be_a_kind_of(Taobao::PropertyList)
76
55
  end
77
56
  end
78
-
57
+
79
58
  describe 'products' do
80
59
  it 'should return ProductList object' do
81
60
  category = Taobao::Category.new(28)
82
- category.products.class.should == Taobao::ProductList
61
+ category.products.should be_a_kind_of(Taobao::ProductList)
83
62
  end
84
63
  end
85
- end
64
+ end
@@ -2,10 +2,10 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Taobao::ProductList do
5
-
5
+
6
6
  describe 'init with default options and category id' do
7
7
  pl = Taobao::ProductList.new(cid: 28)
8
-
8
+
9
9
  fixture = 'items.json'.json_fixture
10
10
  args = {
11
11
  method: 'taobao.items.get',
@@ -15,30 +15,23 @@ describe Taobao::ProductList do
15
15
 
16
16
  it 'should return 40 items' do
17
17
  Taobao.stub(:api_request).with(args).and_return(fixture)
18
- pl.size.should == 40
18
+ pl.should have_exactly(40).items
19
19
  end
20
20
  it 'total count should be greater than zero' do
21
21
  Taobao.stub(:api_request).with(args).and_return(fixture)
22
22
  pl.total_count.should be > 0
23
23
  end
24
24
  it 'items could be iterated' do
25
- pl.each do |item|
26
- item.cid.should be > 0
27
- item.nick.size.should be > 0
28
- item.num_iid.should be > 0
29
- item.pic_url.should match /^http:\/\//
30
- item.price.size.should be > 0
31
- item.title.size.should be > 0
32
- end
25
+ pl.each { |item| item.should be_a_kind_of(Taobao::Product) }
33
26
  end
34
27
  end
35
-
28
+
36
29
  describe 'init and use advanced options' do
37
30
  pl = Taobao::ProductList.new(cid: 28)
38
31
  .page(15)
39
32
  .per_page(10)
40
33
  .order_by_price
41
-
34
+
42
35
  fixture = 'items_page15.json'.json_fixture
43
36
  args = {
44
37
  method: 'taobao.items.get',
@@ -48,21 +41,22 @@ describe Taobao::ProductList do
48
41
  page_size: 10,
49
42
  order_by: 'price'
50
43
  }
51
-
44
+
52
45
  it 'should return 10 items' do
53
46
  Taobao.stub(:api_request).with(args).and_return(fixture)
54
- pl.size.should == 10
47
+ pl.should have_exactly(10).items
55
48
  end
56
49
  end
57
-
50
+
58
51
  describe 'unknown method' do
59
52
  it 'should raise exception' do
60
53
  pl = Taobao::ProductList.new(cid: 28)
61
- lambda { pl.undefined_method }
62
- .should raise_error NoMethodError
54
+ expect {
55
+ pl.undefined_method
56
+ }.to raise_error NoMethodError
63
57
  end
64
58
  end
65
-
59
+
66
60
  describe 'category without items' do
67
61
  it 'should return 0 items' do
68
62
  pl = Taobao::ProductList.new(cid: 283333)
@@ -74,8 +68,8 @@ describe Taobao::ProductList do
74
68
  }
75
69
  Taobao.stub(:api_request).with(args).and_return(fixture)
76
70
  pl.total_count.should == 0
77
- pl.size.should == 0
71
+ pl.should have_exactly(0).items
78
72
  end
79
73
  end
80
-
74
+
81
75
  end
@@ -15,32 +15,33 @@ describe Taobao::Product do
15
15
  'property_alias,item_img,prop_img,sku,video,outer_id,is_virtual',
16
16
  num_iid: '2997802325'
17
17
  }
18
-
18
+
19
19
  it 'should returns product' do
20
20
  Taobao.stub(:api_request).with(args).and_return(fixture)
21
- product = Taobao::Product.new(2997802325)
21
+ product = Taobao::Product.new(2997802325)
22
22
 
23
23
  product.cid.should == 1512
24
24
  product.nick.should == '奇迹shouji'
25
25
  product.num_iid.should == 2997802325
26
26
  product.pic_url.should == 'http://img03.taobaocdn.com/bao/uploaded/i3/T1YsfeXbxkXXXpZak._110941.jpg'
27
- product.price.should == '4300.00'
28
- product.title.should be == '可完美越狱 Apple/苹果 iPhone 4S 正品 装软件 未拆封 未激活'
27
+ product.price.should == 4300.00
28
+ product.title.should == '可完美越狱 Apple/苹果 iPhone 4S 正品 装软件 未拆封 未激活'
29
29
 
30
30
  product.approve_status.should == 'onsale'
31
31
  product.auction_point.should == 0
32
32
  product.delist_time.should == '2012-06-01 22:41:44'
33
33
  product.type.should == 'fixed'
34
34
  end
35
-
35
+
36
36
  describe 'get unknown product property' do
37
37
  it 'should raise an exception' do
38
38
  Taobao.stub(:api_request).with(args).and_return(fixture)
39
39
  product = Taobao::Product.new(2997802325)
40
- lambda {product.unknown_property}
41
- .should raise_error NoMethodError
40
+ expect {
41
+ product.unknown_property
42
+ }.to raise_error NoMethodError
42
43
  end
43
44
  end
44
-
45
+
45
46
  end
46
47
  end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Taobao::PropertyList do
5
+ describe 'initialize with category ID' do
6
+
7
+ it 'should returns property' do
8
+ property_list = Taobao::PropertyList.new(cid: 1512)
9
+
10
+ fixture = 'category_properties.json'.json_fixture
11
+ args = {
12
+ method: 'taobao.itemprops.get',
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',
14
+ cid: 1512
15
+ }
16
+ Taobao.stub(:api_request).with(args).and_return(fixture)
17
+ property_list.first.should be_a_kind_of(Taobao::Property)
18
+ end
19
+ end
20
+
21
+ describe 'category without properties' do
22
+
23
+ it 'should returns 0 properties' do
24
+ property_list = Taobao::PropertyList.new(cid: 0)
25
+
26
+ fixture = 'top_category_properties.json'.json_fixture
27
+ args = {
28
+ method: 'taobao.itemprops.get',
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',
30
+ cid: 0
31
+ }
32
+ Taobao.stub(:api_request).with(args).and_return(fixture)
33
+ property_list.should have(0).items
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Taobao::Property do
5
+ describe 'initialize' do
6
+ describe 'with correct data' do
7
+ it 'should create Property object' do
8
+ property_response = 'property.json'.json_fixture
9
+ property = Taobao::Property.new(property_response)
10
+
11
+ property.multi.should be_false
12
+ property.must.should be_true
13
+ property.name.should == "品牌"
14
+ property.pid.should == 20000
15
+ property.values.should be_a_kind_of Array
16
+ property.values.should have_exactly(2).items
17
+
18
+ value = property.values.first
19
+ value[:is_parent].should be_true
20
+ value[:name].should == "Acer/宏基"
21
+ value[:vid].should == 26691
22
+ end
23
+ end
24
+
25
+ describe 'with incorrect data' do
26
+ it 'should throws an exception' do
27
+ expect { Taobao::Property.new({}) }
28
+ .to raise_error(Taobao::IncorrectProperty, 'Incorrect property data')
29
+ end
30
+ end
31
+ end
32
+ end
@@ -2,10 +2,10 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Taobao do
5
-
5
+
6
6
  describe 'search method returns product list' do
7
7
  search = Taobao::search('iPhone')
8
-
8
+
9
9
  fixture = 'search.json'.json_fixture
10
10
  args = {
11
11
  method: 'taobao.items.get',
@@ -15,7 +15,7 @@ describe Taobao do
15
15
 
16
16
  it 'should return 40 items' do
17
17
  Taobao.stub(:api_request).with(args).and_return(fixture)
18
- search.size.should == 40
18
+ search.should have(40).results
19
19
  end
20
20
  it 'total count should be greater than zero' do
21
21
  Taobao.stub(:api_request).with(args).and_return(fixture)
@@ -12,7 +12,8 @@ describe Taobao do
12
12
  describe 'set the private API key' do
13
13
  it 'should be write-only' do
14
14
  Taobao.private_key = :test
15
- Taobao.method_defined?(:private_key).should == false
15
+ expect { Taobao.private_key }
16
+ .to raise_error NoMethodError
16
17
  end
17
18
  end
18
19
  describe 'API request' do
@@ -21,15 +22,15 @@ describe Taobao do
21
22
  Net::HTTP.stub(:post_form).and_return(fixture)
22
23
  result = Taobao.api_request(method: 'taobao.itemcats.get',
23
24
  fields: 'cid,parent_cid,name,is_parent', cids: 0)
24
- result.class.should == Hash
25
+ result.should be_a_kind_of(Hash)
25
26
  end
26
27
  end
27
28
  describe 'failed API request' do
28
29
  it 'should throws an exception' do
29
30
  fixture = Response.new('error.json'.str_fixture)
30
31
  Net::HTTP.stub(:post_form).and_return(fixture)
31
- lambda { Taobao.api_request({}) }
32
- .should raise_error Taobao::ApiError, 'Invalid arguments:cid'
32
+ expect { Taobao.api_request({}) }
33
+ .to raise_error(Taobao::ApiError, 'Invalid arguments:cid')
33
34
  end
34
35
  end
35
36
  end
@@ -0,0 +1,74 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Taobao::User do
5
+ describe 'getting user by valid nickname' do
6
+ it 'should returns valid user info' do
7
+ fixture = 'user.json'.json_fixture
8
+ args = {
9
+ method: 'taobao.user.get',
10
+ fields: 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,' +
11
+ 'created,last_visit,birthday,type,status,alipay_no,alipay_account,'+
12
+ 'alipay_account,email,consumer_protection,alipay_bind',
13
+ nick: '喜客多2008'
14
+ }
15
+ Taobao.stub(:api_request).with(args).and_return(fixture)
16
+
17
+ user = Taobao::User.new('喜客多2008')
18
+
19
+ user.good_purchases_count.should == 1292
20
+ user.buyer_level.should == 8
21
+ user.buyer_score.should == 1292
22
+ user.total_purchases_count.should == 1292
23
+
24
+ user.good_sales_count.should == 2587208
25
+ user.seller_level.should == 18
26
+ user.seller_score.should == 2576453
27
+ user.total_sales_count.should == 2624203
28
+
29
+ user.registration_date.should == DateTime.new(2005,12,10, 19,03,18)
30
+ user.last_visit.should == DateTime.new(2012,06,29, 23,28,25)
31
+
32
+ user.city.should == '金华'
33
+ user.state.should == '浙江'
34
+
35
+ user.sex.should == :female
36
+ user.type.should == 'C'
37
+
38
+ user.uid.should == '6cd6014f007c04426e2437fef870329a'
39
+ user.id.should == 18139021
40
+ end
41
+ end
42
+ describe 'getting user who does not specify his/her sex' do
43
+ it 'should returns :unknown value' do
44
+ fixture = 'user_unknown_sex.json'.json_fixture
45
+ args = {
46
+ method: 'taobao.user.get',
47
+ fields: 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,' +
48
+ 'created,last_visit,birthday,type,status,alipay_no,alipay_account,'+
49
+ 'alipay_account,email,consumer_protection,alipay_bind',
50
+ nick: 't400旗舰店'
51
+ }
52
+ Taobao.stub(:api_request).with(args).and_return(fixture)
53
+ user = Taobao::User.new('t400旗舰店')
54
+ user.sex.should == :unknown
55
+ end
56
+ end
57
+
58
+ describe 'getting non-existent user' do
59
+ it 'should throws an exception' do
60
+ fixture = 'absent_user.json'.json_fixture
61
+ args = {
62
+ method: 'taobao.user.get',
63
+ fields: 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,' +
64
+ 'created,last_visit,birthday,type,status,alipay_no,alipay_account,'+
65
+ 'alipay_account,email,consumer_protection,alipay_bind',
66
+ nick: 'nonexistent_user'
67
+ }
68
+ Taobao.stub(:api_request).with(args).and_return(fixture)
69
+
70
+ expect { Taobao::User.new('nonexistent_user').uid }
71
+ .to raise_error NoMethodError
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ class ToObjectTest
5
+ attr_reader :a, :b
6
+ include Taobao::Util
7
+ end
8
+
9
+ describe Taobao::Util do
10
+ describe 'to_object' do
11
+ it 'should convert some hash to object' do
12
+ obj = ToObjectTest.new
13
+ obj.to_object a: 5, b: 6
14
+ obj.a.should == 5
15
+ obj.b.should == 6
16
+ end
17
+ end
18
+ end
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,7 @@ class String
12
12
  def str_fixture
13
13
  open("spec/fixtures/#{self}").read
14
14
  end
15
-
15
+
16
16
  def json_fixture
17
17
  contents = open("spec/fixtures/#{self}").read
18
18
  JSON.parse contents, {symbolize_names: true}
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taobaorb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - m16a1
9
- - yesmeck
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-07-15 00:00:00.000000000 Z
12
+ date: 2012-07-27 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: Ruby wrapper for the Taobao API
16
15
  email: a741su@gmail.com
@@ -18,14 +17,21 @@ executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
20
+ - lib/taobao/abstract_list.rb
21
21
  - lib/taobao/base.rb
22
22
  - lib/taobao/category.rb
23
23
  - lib/taobao/exceptions/api_error.rb
24
24
  - lib/taobao/exceptions/incorrect_category_id.rb
25
+ - lib/taobao/exceptions/incorrect_property.rb
25
26
  - lib/taobao/product.rb
26
27
  - lib/taobao/product_list.rb
28
+ - lib/taobao/property.rb
29
+ - lib/taobao/property_list.rb
27
30
  - lib/taobao/search.rb
31
+ - lib/taobao/user.rb
32
+ - lib/taobao/util.rb
28
33
  - lib/taobaorb.rb
34
+ - spec/fixtures/absent_user.json
29
35
  - spec/fixtures/category.json
30
36
  - spec/fixtures/category_properties.json
31
37
  - spec/fixtures/error.json
@@ -35,14 +41,21 @@ files:
35
41
  - spec/fixtures/no_items.json
36
42
  - spec/fixtures/product.json
37
43
  - spec/fixtures/product_wo_property_alias.json
44
+ - spec/fixtures/property.json
38
45
  - spec/fixtures/search.json
39
46
  - spec/fixtures/subcategories.json
40
47
  - spec/fixtures/top_category_properties.json
48
+ - spec/fixtures/user.json
49
+ - spec/fixtures/user_unknown_sex.json
41
50
  - spec/rspec/category_spec.rb
42
51
  - spec/rspec/product_list_spec.rb
43
52
  - spec/rspec/product_spec.rb
53
+ - spec/rspec/property_list_spec.rb
54
+ - spec/rspec/property_spec.rb
44
55
  - spec/rspec/search_spec.rb
45
56
  - spec/rspec/taobao_spec.rb
57
+ - spec/rspec/user_spec.rb
58
+ - spec/rspec/util_spec.rb
46
59
  - spec/spec_helper.rb
47
60
  homepage: https://github.com/m16a1/taobaorb
48
61
  licenses: []