Class: InvisibleHand::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/invisiblehand/product.rb

Constant Summary collapse

FIELDS =

Array of fields that exist on a product returned from the InvisibleHand API.

[
  :pages,
  :ebay_pages,
  :best_page,
  :id,
  :title,
  :resource,
  :upcs,
  :eans,
  :mpns,
  :isbns,
  :asins,
  :brands,
  :models,
  :categories,
  :image_url,
  :number_of_pages,
]

Instance Method Summary collapse

Constructor Details

#initialize(raw, api) ⇒ Product

Returns a new instance of Product.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/invisiblehand/product.rb', line 26

def initialize raw, api
  @api = api
  @raw = raw
  FIELDS.each { |key| self.send("#{key}=", @raw[key.to_s]) }

  if @raw["pages"]
    self.pages = @raw["pages"].map { |json| Page.new(json, @api) }
  end

  if @raw["ebay_pages"]
    self.ebay_pages = @raw["ebay_pages"].map { |json| Page.new(json, @api) }
  end

  if @raw["best_page"]
    self.best_page = Page.new(@raw["best_page"], @api)
  end
end