Class: Taobao::Category
- Inherits:
-
Object
- Object
- Taobao::Category
- Defined in:
- lib/taobao/category.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#initialize(category_id) ⇒ Category
constructor
A new instance of Category.
- #name ⇒ Object
- #products ⇒ Object
- #properties ⇒ Object
- #subcategories ⇒ Object
Constructor Details
#initialize(category_id) ⇒ Category
Returns a new instance of Category.
4 5 6 |
# File 'lib/taobao/category.rb', line 4 def initialize(category_id) @id = category_id.to_i end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
2 3 4 |
# File 'lib/taobao/category.rb', line 2 def id @id end |
Instance Method Details
#name ⇒ Object
8 9 10 11 |
# File 'lib/taobao/category.rb', line 8 def name return @name if @name @name = category_request(cids: @id).first[:name] end |
#products ⇒ Object
30 31 32 |
# File 'lib/taobao/category.rb', line 30 def products Taobao::ProductList.new(cid: @id) end |
#properties ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/taobao/category.rb', line 18 def properties return @properties if @properties fields = [:pid, :name, :must, :multi, :prop_values].join ',' params = {method: 'taobao.itemprops.get', fields: fields, cid: @id} result = Taobao.api_request params begin result[:itemprops_get_response][:item_props][:item_prop] rescue NoMethodError @properties = [] end end |
#subcategories ⇒ Object
13 14 15 16 |
# File 'lib/taobao/category.rb', line 13 def subcategories return @subcategories if @subcategories @subcategories = category_request(parent_cid: @id) end |