Skip to content

Instantly share code, notes, and snippets.

@dt1973
Last active August 29, 2015 14:22
Show Gist options
  • Save dt1973/bf59311d24067e3f6913 to your computer and use it in GitHub Desktop.
Save dt1973/bf59311d24067e3f6913 to your computer and use it in GitHub Desktop.

routes.rb

get "affiliate-products" => "application#affiliate_products"

application_controller.rb

def affiliate_products
  @products = AffiliateProducts.fetch
end

affiliate_products.rb

class AffiliateProducts < ActiveRecord::Base
  def self.fetch
	response = RestClient::Request.execute(
	  :method => :get,
	  :url => "http://api.shopstyle.com/api/v2/products?pid=uid7849-6112293-28&fts=women&offset=0&limit=10"
	)

	@products = JSON.parse(response)["products"].map do |product|
	  product = OpenStruct.new(product)
	end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment