Advertisement
lexquarkie

amazeruby

Oct 22nd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.12 KB | None | 0 0
  1. require 'vacuum'
  2.  
  3. ENV["AWS_ACCESS_KEY_ID"] = 'AKIAJEVNDYASNUA3CMMQ'
  4. ENV['AWS_SECRET_ACCESS_KEY'] = '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'
  5. ENV['ASSOCIATE_TAG'] = 'tag'
  6.  
  7. requestd = Vacuum.new
  8.  
  9.  
  10. search_index = 'All'
  11. keyword = 'Architecture'
  12.  
  13.  
  14. requestd.configure(
  15. aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
  16. aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
  17. associate_tag: ENV['ASSOCIATE_TAG']
  18. )
  19.  
  20. response = requestd.item_search(
  21. query: {
  22.     'SearchIndex' => search_index,
  23.     'Keywords' => keyword,
  24.     'ResponseGroup' => "ItemAttributes,Images"
  25. }
  26. )
  27.  
  28. hashed_products = response.to_h
  29.  
  30. @products = []
  31.  
  32. hashed_products['ItemSearchResponse']['Items']['Item'].each do |item|
  33.   product = OpenStruct.new
  34.   product.name = item['ItemAttributes']['Title']
  35.   product.price = item['ItemAttributes']['ListPrice']['FormattedPrice'] if item['ItemAttributes']['ListPrice']
  36.   product.url = item['DetailPageURL']
  37.   product.feature = item['ItemAttributes']['Feature']
  38.   product.image_url = item['LargeImage']['URL'] if item['LargeImage']
  39.   product.link = item['ItemLinks']['ItemLink'][5]['URL']
  40.   @products << product
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement