Skip to content

Instantly share code, notes, and snippets.

@danbronsema
Created August 10, 2011 12:34
Show Gist options
  • Save danbronsema/1136703 to your computer and use it in GitHub Desktop.
Save danbronsema/1136703 to your computer and use it in GitHub Desktop.
Grabbing big cartel stuff in rails
******* ADDED TO GEMFILE ***********
gem 'httparty'
******* IN THE MODEL ***********
class Project < ActiveRecord::Base
include HTTParty
format :plain
def to_param
"#{name}"
end
def self.find_by_cartel(args)
response = self.get("http://api.bigcartel.com/stripe/products.js")
products = JSON.parse(response.body)
products.each do |product|
if product["name"].downcase == args.downcase
return product
end
end
end
end
************* CONTROLLER *****************
def show
@project = Project.find_by_name(params[:id])
# Find the gallery for the requsted id
@gallery = Project.find_by_cartel(params[:id])
.......
***************** VIEW *****************
<p>
<b>Name:</b>
<%= @project.name %>
</p>
<p>
<b>Gallery:</b>
<%= @gallery["name"] %><br />
<!-- Display images if they are present -->
<% if @gallery["images"].present? %>
<% @gallery["images"].each do |image| %>
<%= image_tag(image["url"], :width => 200) %>
<% end %>
<% end %>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment