Class: Ramazon::Product
- Inherits:
-
Object
- Object
- Ramazon::Product
- Includes:
- HappyMapper, AbstractElement
- Defined in:
- lib/ramazon/product.rb
Overview
Find and get product details with this class Currently supports the following accessors (all other elements can be accessed via nokogiri selectors and the get method)
asin-
Amazon Identifier
upc-
UPC ID
title-
Title of the product
product_group-
The category/product_group of the product
manufacturer-
The manufacturer of the product
brand-
The brand of the product
url-
The Amazon URL of the product
small_image-
The small image that Amazon provides (NOTE: Returns Ramazon::Image object)
medium_image-
The medium image that Amazon provides (NOTE: Returns Ramazon::Image object)
large_image-
The large image that Amazon provides (NOTE: Returns Ramazon::Image object)
list_price-
The list price of the item (NOTE: Returns Ramazon::Price object)
lowest_new_price-
The lowest new price from the offer summary (NOTE: Returns Ramazon::Price object)
sales_rank-
The sales rank of the product
new_count-
The quantity of new item offers
used_count-
The quantity of used item offers
collectible_count-
The quantity of collectible item offers
refurbished_count-
The quantity of refurbished item offers
release_date-
The release date of the product
original_release_date-
The original release date of the product
Instance Attribute Summary collapse
-
#xml_doc ⇒ Object
Returns the value of attribute xml_doc.
Class Method Summary collapse
-
.find(*args) ⇒ Array
Creates the worker that performs the delta indexing (ie. passing the :response_group option will be converted to “ResponseGroup”)
:item_id- the ASIN or UPC you’re looking for. -
.item_lookup(item_id, options = {}) ⇒ Object
Performs an item lookup.
- .parse(xml, options = {}) ⇒ Object
Instance Method Summary collapse
-
#category_tree ⇒ Object
returns a hash of category browse nodes from the top down.
-
#get(*args) ⇒ Object
perform a nokogiri search on the product’s XML.
-
#images ⇒ Hash
assembles the available images for the object.
Methods included from AbstractElement
Instance Attribute Details
#xml_doc ⇒ Object
Returns the value of attribute xml_doc.
125 126 127 |
# File 'lib/ramazon/product.rb', line 125 def xml_doc @xml_doc end |
Class Method Details
.find(*args) ⇒ Array
Creates the worker that performs the delta indexing (ie. passing the :response_group option will be converted to “ResponseGroup”) :item_id - the ASIN or UPC you’re looking for
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ramazon/product.rb', line 88 def self.find(*args) = args. if [:item_id] item_lookup([:item_id], ) else [:operation] ||= "ItemSearch" [:search_index] ||= "Blended" [:item_page] ||= 1 res = Ramazon::Request.new().submit Ramazon::ProductCollection.create_from_results([:item_page] || 1, 10, res) end end |
.item_lookup(item_id, options = {}) ⇒ Object
Performs an item lookup
104 105 106 107 108 109 110 |
# File 'lib/ramazon/product.rb', line 104 def self.item_lookup(item_id, = {}) req = Ramazon::Request.new({:item_id => item_id, :operation => "ItemLookup"}.merge()) res = req.submit Ramazon::ProductCollection.create_from_results(1,1,res) end |
.parse(xml, options = {}) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/ramazon/product.rb', line 126 def self.parse(xml, = {}) node = XML::Parser.string(xml.to_s).parse.root node.find("//Item").collect do |n| p = super(n.to_s) p.xml_doc = Nokogiri::XML.parse(n.to_s) p end end |
Instance Method Details
#category_tree ⇒ Object
returns a hash of category browse nodes from the top down
145 146 147 148 149 150 151 |
# File 'lib/ramazon/product.rb', line 145 def category_tree @category_tree = {} get_category_browse_nodes.each do |n| build_category_tree(n) end @category_tree end |
#get(*args) ⇒ Object
perform a nokogiri search on the product’s XML
140 141 142 |
# File 'lib/ramazon/product.rb', line 140 def get(*args) result = @xml_doc.search(args) end |
#images ⇒ Hash
assembles the available images for the object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ramazon/product.rb', line 114 def images if !@images @images = {} @images[:thumb] = self.thumb_image if self.thumb_image @images[:tiny_image] = self.tiny_image if self.tiny_image @images[:small] = self.small_image if self.small_image @images[:medium] = self.medium_image if self.medium_image @images[:large] = self.large_image if self.large_image end end |