Skip to content

Instantly share code, notes, and snippets.

@timbeiko
Created July 9, 2015 21:56
Show Gist options
  • Save timbeiko/26122e8a328c853f90b5 to your computer and use it in GitHub Desktop.
Save timbeiko/26122e8a328c853f90b5 to your computer and use it in GitHub Desktop.
Amazon ECS issue
# amazon_api.rb
# ENV variables are configured with figaro locally and directly on Amazon Elastic Beanstalk in production
Amazon::Ecs.configure do |options|
options[:AWS_access_key_id] = ENV["AWS_ACCESS_KEY_ID"]
options[:AWS_secret_key] = ENV["AWS_SECRET_KEY"]
options[:associate_tag] = ENV["associate_tag"]
options[:version] = "2013-08-01"
end
# books_controller.rb
def search
# Amazon API
search_term = params[:book_info]
@books = Amazon::Ecs.item_search(search_term, { :search_index => 'Books', :sort => 'relevancerank' })
@covers = Amazon::Ecs.item_search(search_term, { :response_group => 'Images',
:search_index => 'Books',
:sort => 'relevancerank' })
render :new
end
# books/new.html.erb
<div class='all-books' >
<% @books.items.each_with_index do |book, n| %>
<% unless bad_image?(n) %>
<div class='col-md-2 col-sm-3 col-xs-4 book-row'>
<div class='' >
<%= form_for @book do |f| %>
<% item_attributes = book.get_element('ItemAttributes') %>
<input name="book[title]" type="hidden" value="<%= item_attributes.get('Title') %>"/>
<input name="book[authors]" type="hidden" value="<%= item_attributes.get('Author') %>"/>
<input name="book[amazon_link]" type="hidden" value="<%= book.get_element('ItemLink').get('URL') %>"/>
<input name="book[asin]" type="hidden" value="<%= @covers.items[n].get('ASIN') %>"/>
<input name="book[cover_image_link]" type="hidden" value="<%= @covers.items[n].get('LargeImage/URL') %>"/>
<input name="user_book[status]" type="hidden" value="read"/>
<%= image_submit_tag(@covers.items[n].get('LargeImage/URL'), class: 'img-responsive search-book') %>
<% end %>
</div>
</div>
<% end %>
<% end %>
<% end %>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment