Class: Tucano::ProductSearch
- Inherits:
-
Object
- Object
- Tucano::ProductSearch
- Defined in:
- lib/tucano.rb
Instance Method Summary collapse
- #convert_to_product(item) ⇒ Object
-
#initialize(key, secret, associate_tag) ⇒ ProductSearch
constructor
A new instance of ProductSearch.
- #parse_response ⇒ Object
- #search(query) ⇒ Object
Constructor Details
#initialize(key, secret, associate_tag) ⇒ ProductSearch
Returns a new instance of ProductSearch.
9 10 11 12 13 14 15 |
# File 'lib/tucano.rb', line 9 def initialize(key, secret, associate_tag) Amazon::Ecs. = { :associate_tag => associate_tag, :AWS_access_key_id => key, :AWS_secret_key => secret } end |
Instance Method Details
#convert_to_product(item) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tucano.rb', line 17 def convert_to_product(item) i = Item.new i.name = item.get_hash("ItemAttributes")["Title"] i.category = item.get_hash("ItemAttributes")["ProductGroup"] i.price = item.get_hash("ItemAttributes/ListPrice")["Amount"] i.currency = item.get_hash("ItemAttributes/ListPrice")["CurrencyCode"] i.description = item.get_hash("EditorialReviews/EditorialReview")["Content"] i.image = item.get_hash("LargeImage")["URL"] return i end |
#parse_response ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/tucano.rb', line 28 def parse_response products = [] @response.items.each do |item| product = convert_to_product(item) products << product end products end |
#search(query) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/tucano.rb', line 37 def search(query) @response = Amazon::Ecs.item_search(query, :search_index => "All", :response_group => "Medium") products = [] products = parse_response products end |