Class: Taobao::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/taobao/category.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



2
3
4
# File 'lib/taobao/category.rb', line 2

def id
  @id
end

Instance Method Details

#nameObject



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

#productsObject



30
31
32
# File 'lib/taobao/category.rb', line 30

def products
  Taobao::ProductList.new(cid: @id)
end

#propertiesObject



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

#subcategoriesObject



13
14
15
16
# File 'lib/taobao/category.rb', line 13

def subcategories
  return @subcategories if @subcategories
  @subcategories = category_request(parent_cid: @id)
end