Sha256: bdf64519613008a39bb5c43c2c857137700aa14397f501c50c3b34d1975d3b29

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zinc-api-0.0.6 lib/zinc/product.rb