Class: Zanox::Product

Inherits:
Item
  • Object
show all
Defined in:
lib/zanox/resources/product.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hashable

#to_hash

Constructor Details

#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

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def category
  @category
end

#currencyObject (readonly)

Returns the value of attribute currency.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def currency
  @currency
end

#delivery_timeObject (readonly)

Returns the value of attribute delivery_time.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def delivery_time
  @delivery_time
end

#descriptionObject (readonly)

Returns the value of attribute description.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def description
  @description
end

#excerptObject (readonly)

Returns the value of attribute excerpt.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def excerpt
  @excerpt
end

#imagesObject (readonly)

Returns the value of attribute images.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def images
  @images
end

#manufacturerObject (readonly)

Returns the value of attribute manufacturer.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def manufacturer
  @manufacturer
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def name
  @name
end

#paginationObject

Returns the value of attribute pagination.



29
30
31
# File 'lib/zanox/resources/product.rb', line 29

def pagination
  @pagination
end

#pidObject (readonly)

Returns the value of attribute pid.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def pid
  @pid
end

#priceObject (readonly)

Returns the value of attribute price.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def price
  @price
end

#price_oldObject (readonly)

Returns the value of attribute price_old.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def price_old
  @price_old
end

#programObject (readonly)

Returns the value of attribute program.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def program
  @program
end

#shipping_costsObject (readonly)

Returns the value of attribute shipping_costs.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def shipping_costs
  @shipping_costs
end

Returns the value of attribute tracking_link.



27
28
29
# File 'lib/zanox/resources/product.rb', line 27

def tracking_link
  @tracking_link
end

Class Method Details

.find(keyword, args = {}) ⇒ Object



70
71
72
73
74
# File 'lib/zanox/resources/product.rb', line 70

def find(keyword, args = {})
  args.merge!({ q: keyword })
  response = API.request(:products, args)
  from_product_items(response)
end

.from_id(product_id, args = {}) ⇒ Object



82
83
84
85
# File 'lib/zanox/resources/product.rb', line 82

def from_id(product_id, args = {})
  response = API.request("products/product/#{product_id}", args)
  new(response.product_item.first)
end

.from_shop(shop_id, args = {}) ⇒ Object



76
77
78
79
80
# File 'lib/zanox/resources/product.rb', line 76

def from_shop(shop_id, args = {})
  args.merge!({ programs: shop_id })
  response = API.request(:products, args)
  from_product_items(response)
end