Class: Shopping::Publisher
- Inherits:
-
Object
- Object
- Shopping::Publisher
show all
- Includes:
- ApiHelper, HTTParty
- Defined in:
- lib/api_helpers/shopping.rb
Constant Summary
collapse
- MAX_OFFERS =
20
- PUTS_API_URL =
false
Instance Method Summary
collapse
Methods included from ApiHelper
#to_d_or_nil, #to_i_or_nil
Instance Method Details
#fetch_offers(product_id) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/api_helpers/shopping.rb', line 36
def fetch_offers(product_id)
query = {'numItems' => MAX_OFFERS, 'showOffersOnly' => 'true', 'productId' => product_id.strip}
call_api('/GeneralSearch', {:query => query}) do |doc|
items_node = doc.at('GeneralSearchResponse/categories/category/items')
convert_offers_collection_node(items_node)
end
end
|
#fetch_product(product_id, include_specs = false, include_offers = false) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/api_helpers/shopping.rb', line 27
def fetch_product(product_id, include_specs=false, include_offers=false)
query = {'numItems' => include_offers ? MAX_OFFERS : 1, 'productId' => product_id.strip, 'showProductSpecs' => include_specs ? 'true' : 'false'}
call_api('/GeneralSearch', {:query => query}) do |doc|
product_node = doc.at('GeneralSearchResponse/categories/category/items/product')
convert_product_node(product_node, include_offers)
end
end
|
#search_for_product(keyword, max_results = 10) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/api_helpers/shopping.rb', line 44
def search_for_product(keyword, max_results=10)
query = {'doSkipping' => 'false', 'showProductOffers' => 'false', 'numAttributes' => 0, 'numItems' => max_results, 'keyword' => keyword.strip}
call_api('/GeneralSearch', {:query => query}) do |doc|
product_nodes = doc.search('GeneralSearchResponse/categories/category/items/product')
product_nodes.collect{|product_node| convert_product_node(product_node)}
end
end
|