module Zinc class Product < Resource # http://docs.zincapi.com/#product-details AND # http://docs.zincapi.com/#product-object attr_accessor :status, :retailer, :product_id, :timestamp, :title, :product_details, :feature_bullets, :brand, :main_image, :images, :variant_specifics, :all_variants, :categories, :authors, :product_description, :epids, :epids_map, :package_dimensions, :item_location, # AliExpress-only. :original_retail_price, # Amazon-only. :price, # Amazon-only. :review_count, # Amazon-only. :stars, # Amazon-only. :question_count, # Amazon-only. :asin, # Amazon-only. :item_number, # Costco-only. :quantity, :seller_selection_criteria def initialize(hash) super(hash, exclude: %w(seller_selection_criteria)) @seller_selection_criteria = SellerSelectionCriteria.new(hash['seller_selection_criteria']) if hash['seller_selection_criteria'] end class << self def find(id, retailer:, async: false, max_age: nil, newer_than: nil) unless Zinc::RETAILERS.include?(retailer) raise StandardError, "#{retailer} is not supported - the supported retailers are #{Zinc::RETAILERS.to_sentence}" end params = {} params['retailer'] = retailer params['async'] = true if async params['max_age'] = max_age if max_age params['newer_than'] = newer_than if newer_than get(path: "products/#{id}?#{URI.encode_www_form(params)}") end end end end