Class: Tucano::ProductSearch

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

Instance Method Summary collapse

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.options = {
    :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_responseObject



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