Skip to content

Instantly share code, notes, and snippets.

@j-mcnally
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-mcnally/b2a5655938d299f7f478 to your computer and use it in GitHub Desktop.
Save j-mcnally/b2a5655938d299f7f478 to your computer and use it in GitHub Desktop.
class MainController < ApplicationController
def index
client = Shopsense::API.new('partner_id' => 'uid0000-00000000-00')
response = client.search("New")
raw_products = JSON.parse(response)["products"]
@products = raw_products.map! do |product|
# image = product["images"].select { |i| i["sizeName"] == 'Large' }.pop
product = OpenStruct.new(product)
image = product.images.select { |i| i["sizeName"] == 'Large' }
product.image = OpenStruct.new(image)
product
end
end
end
<div class="custom_widget">
<% if @products.any? %>
<% @products.each do |product| %>
<div class="product">
<%= image_tag product.image.url %>
<p><%= product.name%></p>
</div>
<% end %>
<% end %>
</div>
# Doesn't follow standard Ruby naming conventions, load manually
gem 'shopsense-ruby', require: 'shopsense'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment