Class: Epages::Product
- Inherits:
-
Object
- Object
- Epages::Product
- Includes:
- REST::Products, Utils
- Defined in:
- lib/epages/product.rb
Constant Summary collapse
- KEYS =
%w(product_id name short_description description product_image images price_info for_sale special_offer delivery_weight shipping_methods_restricted_to availability_text availability energy_labels_string energy_label_source_file product_data_sheet sf_url product_number manufacturer upc ean essential_features search_keywords links tax_class stocklevel watchers delivery_period visible manufacturer_product_number min_stock_level product_length product_height product_width product_variation_type product_variation_selection).collect(&:to_sym).freeze
Instance Method Summary collapse
-
#==(other) ⇒ Object
compare the product with another product.
-
#add_slideshow_image(image) ⇒ Object
add an image to the slideshow.
-
#categories ⇒ Object
returns the categories of the product.
-
#custom_attributes ⇒ Object
returns the list of custom_attributes of the product.
-
#delete_slideshow_image(image) ⇒ Object
remove the image passed from the slideshow and return the new slideshow.
-
#host ⇒ Object
returns the host of the shop that belongs to the product.
-
#initialize(data) ⇒ Product
constructor
A new instance of Product.
-
#link?(name) ⇒ Boolean
returns true if [name] is included in the list of links.
-
#links_title ⇒ Object
returns the list of links.
-
#lowest_price ⇒ Object
returns the lowest price of all the variations of the product.
-
#shop_name ⇒ Object
returns the name of the shop that belongs the product.
-
#slideshow ⇒ Object
returns the list of slides of the product.
-
#slideshow_sequence ⇒ Object
returns an array containing the slideshow sequence.
-
#to_line_item(quantity = 1) ⇒ Object
return a hash with productId and quantity.
-
#update_slideshow_sequence(data) ⇒ Object
updates the order of the sequence with the data passed as parameter.
-
#variations ⇒ Object
returns the list of variations of the product.
Methods included from REST::Products
#assign_categories, #create_product, #delete_from_categories, #export_products, #product, #product_add_slideshow_image, #product_custom_attributes, #product_delete_slideshow_image, #product_lowest_price, #product_slideshow, #product_slideshow_sequence, #product_update_slideshow_sequence, #product_variations, #products, #update_product, #updated_products_by_property, #watched_products
Methods included from REST::Utils
#epages_id, #format_date, #format_dates_options, #parse_legal_info, #parse_links, #parse_price_info, #parse_product_lowest_price, #parse_product_variations, #parse_suggestions_to_products, #parse_variation_object, #parse_variations, #perform_delete_request, #perform_delete_with_object, #perform_get_request, #perform_get_with_key_and_objects, #perform_get_with_object, #perform_get_with_objects, #perform_multipart_post_with_objects, #perform_patch_with_object, #perform_post_request, #perform_post_with_key_and_objects, #perform_post_with_object, #perform_post_with_objects, #perform_put_request, #perform_put_with_object, #perform_request, #perform_request_with_key_and_objects, #perform_request_with_object, #perform_request_with_objects, #process_thread
Methods included from Utils
build_shop_from, camelize_keys, camelize_words, options_to_multipart_request, options_to_patch_request, parse_attribute_as, parse_attribute_as_array_of, parse_attributes, symbolize_keys!, to_query_options, underscorize_keys
Constructor Details
#initialize(data) ⇒ Product
Returns a new instance of Product.
17 18 19 20 21 22 |
# File 'lib/epages/product.rb', line 17 def initialize(data) parse_attribute_as_array_of(:images, data.delete(:images), Epages::Image) parse_attribute_as_array_of(:links, data.delete(:links), Epages::Link) parse_attribute_as(:price_info, data.delete(:priceInfo), Epages::PriceInfo) parse_attributes(data) end |
Instance Method Details
#==(other) ⇒ Object
compare the product with another product. 2 products are considered equals if both has the same id, the same name and the same product_number
26 27 28 29 |
# File 'lib/epages/product.rb', line 26 def ==(other) return false unless other.is_a? Epages::Product product_id == other.product_id && name == other.name && product_number == other.product_number end |
#add_slideshow_image(image) ⇒ Object
add an image to the slideshow
59 60 61 |
# File 'lib/epages/product.rb', line 59 def (image) (self, image) end |
#categories ⇒ Object
returns the categories of the product
93 94 95 |
# File 'lib/epages/product.rb', line 93 def categories product_categories(self) if link?('categories') end |
#custom_attributes ⇒ Object
returns the list of custom_attributes of the product
88 89 90 |
# File 'lib/epages/product.rb', line 88 def custom_attributes product_custom_attributes(self) if link?('custom-attributes') end |
#delete_slideshow_image(image) ⇒ Object
remove the image passed from the slideshow and return the new slideshow
66 67 68 |
# File 'lib/epages/product.rb', line 66 def (image) (self, image) end |
#host ⇒ Object
returns the host of the shop that belongs to the product
37 38 39 |
# File 'lib/epages/product.rb', line 37 def host URI.parse(sf_url).host end |
#link?(name) ⇒ Boolean
returns true if [name] is included in the list of links
47 48 49 |
# File 'lib/epages/product.rb', line 47 def link?(name) links_title.include? name end |
#links_title ⇒ Object
returns the list of links
42 43 44 |
# File 'lib/epages/product.rb', line 42 def links_title links.collect(&:rel) end |
#lowest_price ⇒ Object
returns the lowest price of all the variations of the product
98 99 100 |
# File 'lib/epages/product.rb', line 98 def lowest_price product_lowest_price(self) if link?('lowest-price') end |
#shop_name ⇒ Object
returns the name of the shop that belongs the product
32 33 34 |
# File 'lib/epages/product.rb', line 32 def shop_name sf_url[%r{epages\/(\w+)}, 1] end |
#slideshow ⇒ Object
returns the list of slides of the product
52 53 54 |
# File 'lib/epages/product.rb', line 52 def (self) if link?('slideshow') end |
#slideshow_sequence ⇒ Object
returns an array containing the slideshow sequence
71 72 73 |
# File 'lib/epages/product.rb', line 71 def (self) end |
#to_line_item(quantity = 1) ⇒ Object
return a hash with productId and quantity. This format is used for the line_items of Cart
103 104 105 |
# File 'lib/epages/product.rb', line 103 def to_line_item(quantity = 1) {productId: product_id, quantity: quantity} end |
#update_slideshow_sequence(data) ⇒ Object
updates the order of the sequence with the data passed as parameter
78 79 80 |
# File 'lib/epages/product.rb', line 78 def (data) (self, data) end |
#variations ⇒ Object
returns the list of variations of the product
83 84 85 |
# File 'lib/epages/product.rb', line 83 def variations product_variations(self) if link?('variations') end |