Commit 585c2faf
Changed files (2)
app
services
infrastructure
views
admin
products
app/services/infrastructure/amazon_api.rb
@@ -11,38 +11,6 @@ class AmazonAPI
def search(query)
return [] if query.blank?
- results = client.search(Keywords: query, SearchIndex: :Kitchen, Sort: :salesrank, Availability: :Available, MerchantId: :Amazon)
- results.map { |x| AmazonProduct.new(x) }
- end
-end
-
-class AmazonProduct
- attr_reader :item
- delegate :asin, :detail_page_url, :item_attributes, :item_links, to: :item
-
- def initialize(item)
- @item = item
- end
-
- def title
- item.item_attributes.title
- end
-
- def url
- item.detail_page_url
- end
-
- def manufacturer
- item.item_attributes.manufacturer
- end
-
- def category
- item.item_attributes.product_group
- end
-
- def links
- item.item_links.item_link.map do |link|
- OpenStruct.new(description: link.description, url: link.url)
- end
+ client.search(Keywords: query, SearchIndex: :Kitchen, Sort: :salesrank, Availability: :Available, MerchantId: :Amazon)
end
end
app/views/admin/products/_index.html.erb
@@ -4,7 +4,7 @@
<tr>
<td><%= link_to product.asin, admin_product_path(product.asin) %></td>
<td>
- <%= link_to product.title, product.url %> is made by <%= product.manufacturer %> in category <%= product.category %>
+ <%= link_to product.item_attributes.title, product.detail_page_url %> is made by <%= product.item_attributes.manufacturer %> in category <%= product.item_attributes.product_group %>
</td>
</tr>
<% end %>