Module: AmazonProduct::Operations
- Included in:
- Request
- Defined in:
- lib/amazon_product/operations.rb
Overview
Some shorthand notation for available operations.
Instance Method Summary collapse
-
#add_to_cart(params) ⇒ Object
Cart operations.
- #clear_cart(params) ⇒ Object
- #create_cart(params) ⇒ Object
-
#find(*item_ids) ⇒ Object
Given up to ten item ids, returns some or all of the item attributes, depending on the response group specified in the request.
-
#find_browse_node(browse_node_id, params = {}) ⇒ Object
Given a browse node ID, returns the specified browse node’s name, children, and ancestors.
-
#find_similar(*item_ids) ⇒ Object
Given up to ten item ids, returns up to ten products per page that are similar to those items.
- #get_cart(params) ⇒ Object
- #modify_cart(params) ⇒ Object
-
#search(search_index = nil, params = nil) ⇒ Object
Returns up to ten items that satisfy the search criteria, including one or more search indices.
Instance Method Details
#add_to_cart(params) ⇒ Object
Cart operations.
5 6 7 |
# File 'lib/amazon_product/operations.rb', line 5 def add_to_cart(params) cart 'Add', params end |
#clear_cart(params) ⇒ Object
9 10 11 |
# File 'lib/amazon_product/operations.rb', line 9 def clear_cart(params) cart 'Clear', params end |
#create_cart(params) ⇒ Object
13 14 15 |
# File 'lib/amazon_product/operations.rb', line 13 def create_cart(params) cart 'Create', params end |
#find(*item_ids) ⇒ Object
Given up to ten item ids, returns some or all of the item attributes, depending on the response group specified in the request.
Id Type defaults to ASIN.
Assuming you have a request object, the following returns some basic information for the ASIN 0679753354:
request.find('0679753354')
The following request returns cover art for the same ASIN:
req.find('0679753354', :response_group => 'Images')
39 40 41 42 43 44 45 |
# File 'lib/amazon_product/operations.rb', line 39 def find(*item_ids) reset params = item_ids.last.is_a?(Hash) ? item_ids.pop : {} self.<<({ 'Operation' => 'ItemLookup', 'ItemId' => item_ids }.merge(params)) get end |
#find_browse_node(browse_node_id, params = {}) ⇒ Object
Given a browse node ID, returns the specified browse node’s name, children, and ancestors.
49 50 51 52 53 54 |
# File 'lib/amazon_product/operations.rb', line 49 def find_browse_node(browse_node_id, params = {}) reset self.<<({ 'Operation' => 'BrowseNodeLookup', 'BrowseNodeId' => browse_node_id }.merge(params)) get end |
#find_similar(*item_ids) ⇒ Object
Given up to ten item ids, returns up to ten products per page that are similar to those items.
58 59 60 61 62 63 64 |
# File 'lib/amazon_product/operations.rb', line 58 def find_similar(*item_ids) reset params = item_ids.last.is_a?(Hash) ? item_ids.pop : {} self.<<({ 'Operation' => 'SimilarityLookup', 'ItemId' => item_ids }.merge(params)) get end |
#get_cart(params) ⇒ Object
17 18 19 |
# File 'lib/amazon_product/operations.rb', line 17 def get_cart(params) cart 'Get', params end |
#modify_cart(params) ⇒ Object
21 22 23 |
# File 'lib/amazon_product/operations.rb', line 21 def modify_cart(params) cart 'Modify', params end |
#search(search_index = nil, params = nil) ⇒ Object
Returns up to ten items that satisfy the search criteria, including one or more search indices.
Assuming you have a request object, the following searches the entire Amazon catalog for the keyword ‘book’:
request.search('book')
The following searches the books search index for the keyword ‘lacan’:
request.search('Books', 'lacan')
The following runs a power search on the books search index for non- fiction titles authored by Lacan and sorts results by Amazon’s relevance ranking:
request.search('Books', :power => 'author:lacan and not fiction',
:sort => 'relevancerank')
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/amazon_product/operations.rb', line 85 def search(search_index = nil, params = nil) reset if params.nil? params = { 'Keywords' => search_index } search_index = 'All' end if params.is_a? String params = { 'Keywords' => params } end self.<<({ 'Operation' => 'ItemSearch', 'SearchIndex' => search_index }.merge(params)) get end |