diff options
| author | mo khan <mo@mokhan.ca> | 2014-10-13 11:44:34 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-10-13 11:44:34 -0600 |
| commit | dd53c55a98cbb965fd5947e288e5e10f96843101 (patch) | |
| tree | 51815a74f8dd9ab5f867c01b10440e1b3a56ad9b | |
| parent | a8f0c11dd54ca68c3059bc908e61da3b9a83fe74 (diff) | |
add tools page to admin section to search the Amazon Product API.
| -rw-r--r-- | app/controllers/admin/tools_controller.rb | 15 | ||||
| -rw-r--r-- | app/views/admin/tools/index.html.erb | 33 | ||||
| -rw-r--r-- | app/views/my/shared/_my_nav.html.erb | 1 | ||||
| -rw-r--r-- | config/initializers/asin.rb | 2 | ||||
| -rw-r--r-- | config/routes.rb | 1 |
5 files changed, 52 insertions, 0 deletions
diff --git a/app/controllers/admin/tools_controller.rb b/app/controllers/admin/tools_controller.rb new file mode 100644 index 00000000..0bae31ad --- /dev/null +++ b/app/controllers/admin/tools_controller.rb @@ -0,0 +1,15 @@ +module Admin + class ToolsController < AdminController + def index + @tools = search_for_tools(params[:q]) + end + + private + + def search_for_tools(query) + return [] if query.blank? + client = ASIN::Client.instance + client.search(Keywords: query, SearchIndex: :Kitchen, Sort: :salesrank) + end + end +end diff --git a/app/views/admin/tools/index.html.erb b/app/views/admin/tools/index.html.erb new file mode 100644 index 00000000..47306084 --- /dev/null +++ b/app/views/admin/tools/index.html.erb @@ -0,0 +1,33 @@ +<div class="row-fluid"> + <div class="span2"> + <%= render partial: "my/shared/my_nav" %> + </div> + <div class="span10"> + <h1>Tools</h1> + <%= form_tag admin_tools_path, method: :get, name: 'search', class: 'form-horizontal' do %> + <%= text_field_tag :q, params[:q], class: "search-query", placeholder: "Search" %> + <%= submit_tag 'Search', class: 'btn btn-primary' %> + <% end %> + + <table class="table table-striped"> + <tbody> + <% @tools.each do |tool| %> + <tr> + <td><%= link_to tool.asin, tool.detail_page_url %></td> + <td> + <%= link_to tool.item_attributes.title, tool.detail_page_url %> is made by <%= tool.item_attributes.manufacturer %> in category <%= tool.item_attributes.product_group %> + </td> + <td> + <ul> + <% tool.item_links.item_link.each do |link| %> + <li><%= link_to link.description, link.url %></li> + <% end %> + </ul> + </td> + </tr> + <% end %> + </tbody> + </table> + </div> +</div> + diff --git a/app/views/my/shared/_my_nav.html.erb b/app/views/my/shared/_my_nav.html.erb index 981142a1..564c7e01 100644 --- a/app/views/my/shared/_my_nav.html.erb +++ b/app/views/my/shared/_my_nav.html.erb @@ -34,6 +34,7 @@ <li><%= link_to "<i class='fa fa-photo'></i> Photos".html_safe, admin_photos_path %></li> <li><%= link_to "Blobs", admin_blobs_path %></li> <li><%= link_to "Sessions", admin_sessions_path %></li> + <li><%= link_to "Tools", admin_tools_path %></li> <% end %> <li class="nav-header">Other</li> <li><%= link_to t('.logout'), logout_path, method: :delete %></li> diff --git a/config/initializers/asin.rb b/config/initializers/asin.rb index 33b3aaec..8cac414c 100644 --- a/config/initializers/asin.rb +++ b/config/initializers/asin.rb @@ -3,3 +3,5 @@ ASIN::Configuration.configure do |config| config.secret = ENV.fetch('AWS_PRODUCT_SECRET') config.associate_tag = ENV.fetch('AWS_PRODUCT_ASSOCIATE_ID') end +HTTPI.adapter = :curb +HTTPI.logger = Rails.logger diff --git a/config/routes.rb b/config/routes.rb index 0e7a30c5..8f33ea61 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -84,6 +84,7 @@ Cake::Application.routes.draw do resources :blobs, only: [:index, :show] resources :errors, only: [:index, :create] resources :sessions, only: [:index, :destroy] + resources :tools, only: [:index] end namespace :my do |
