Method: Zanox::Product#initialize

Defined in:
lib/zanox/resources/product.rb

#initialize(data) ⇒ Product

  • pid (String) Product ID

  • name (String) The name of the product

  • program (Hash) Hash containing the id and the name of the shop which sells this product (e.g. EuronicsIT)

  • description (HTML) The description of the product

  • excerpt (String) A short description of the product

  • manufacturer (String) The manufacturer of the product (e.g. Apple)

  • images (String[]) A collection of images representing the product in different sizes

  • currency (String) The currency used to calculate the price

  • price (Float) The price of the product calculated with the relative currency

  • shipping_costs (Float) The price of the shipping

  • delivery_time (Integer) The number of the days required by the shop to deliver the product

  • tracking_link (String ) The link that redirects to the advertiser’s shop



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/zanox/resources/product.rb', line 45

def initialize(data)
  @pid            = data['@id']
  @name           = data['name']
  @program        = {
    id:   data['program']['@id'].to_i,
    name: data['program']['$']
  }
  @description    = strip_cdata(data['descriptionLong'])
  @excerpt        = data['description']
  @manufacturer   = data['manufacturer']
  @category       = data['merchantCategory']
  @images         = {
    small:  data['image'].try { |i| i['small']  },
    medium: data['image'].try { |i| i['medium'] },
    large:  data['image'].try { |i| i['large']  },
  }
  @currency       = data['currency']
  @price          = data['price'].to_f
  @price_old      = data['priceOld'].to_f
  @shipping_costs = data['shippingCosts'].try(:to_f)
  @delivery_time  = only_numbers(data['deliveryTime'])
  @tracking_link  = data['trackingLinks'].try { |d| d['trackingLink'] }.try { |d| d[0] }.try { |d| d['ppc'] }
end