Class: Taobao::Product

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/taobao/product.rb

Constant Summary collapse

BASIC_PROPERTIES =
[:cid, :num_iid, :title, :nick, :price, :pic_url, :type,
:score, :delist_time, :post_fee, :volume]
OTHER_PROPERTIES =
[:detail_url, :seller_cids, :props, :input_pids,
:input_str, :desc, :num, :valid_thru, :list_time, :stuff_status,
:location, :express_fee, :ems_fee, :has_discount, :freight_payer,
:has_invoice, :has_warranty, :has_showcase, :modified, :increment,
:approve_status, :postage_id, :product_id, :auction_point,
:property_alias, :item_img, :prop_img, :sku, :video, :outer_id,
:is_virtual, :sell_promise, :second_kill, :auto_fill, :props_name]

Instance Method Summary collapse

Methods included from Util

#to_object

Constructor Details

#initialize(product_properties) ⇒ Product

Returns a new instance of Product.



19
20
21
22
23
24
25
26
27
28
# File 'lib/taobao/product.rb', line 19

def initialize(product_properties)
  if Hash === product_properties
    to_object product_properties
    @all_properties_fetched = false
    convert_types
  else
    @num_iid = product_properties.to_s
    fetch_full_data
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/taobao/product.rb', line 34

def method_missing(method_name, *args, &block)
  if instance_variable_defined? "@#{method_name}"
    fetch_full_data unless @all_properties_fetched
    self.instance_variable_get "@#{method_name}"
  else
    super
  end
end

Instance Method Details

#userObject



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

def user
  Taobao::User.new @nick
end