Skip to content

Instantly share code, notes, and snippets.

@bernsno
Created November 11, 2009 21:31
Show Gist options
  • Save bernsno/232322 to your computer and use it in GitHub Desktop.
Save bernsno/232322 to your computer and use it in GitHub Desktop.
class ShopifyCollection
require 'feedzirra'
require 'hpricot'
BASE_URI = "http://shop.thepostfamily.com/collections/"
def initialize(url)
@feed = Feedzirra::Feed.fetch_and_parse(BASE_URI + url + ".atom")
@entries = @feed.entries
end
def links_and_images(limit=5)
@entries[0..limit.to_i].map do |entry|
link = entry.links[1]
image = Hpricot.parse(entry.inspect).search('//img[@src]').map { |image| image['src'].gsub(/[\\"]/, '') }[0]
collection = [image,link]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment