Skip to content

Instantly share code, notes, and snippets.

@amdavidson
Created August 1, 2011 03:05
Show Gist options
  • Save amdavidson/1117505 to your computer and use it in GitHub Desktop.
Save amdavidson/1117505 to your computer and use it in GitHub Desktop.
Flickr Feed Parsing
<% if flickr_enabled == true then
require 'open-uri'
require 'json/ext'
flickr_url = "http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&format=json&nojsoncallback=1&api_key=#{ENV['flickr_key']}&user_id=#{ENV['flickr_id']}&per_page=12"
response = open(flickr_url, 'User-agent' => 'amdavidson.com').read
photos = JSON.parse(response)["photos"]["photo"]
for p in photos[0...12] do
square = "http://farm#{p["farm"]}.static.flickr.com/#{p["server"]}/#{p["id"]}_#{p["secret"]}_t.jpg"
medium = "http://farm#{p["farm"]}.static.flickr.com/#{p["server"]}/#{p["id"]}_#{p["secret"]}.jpg"
url = "http://flickr.com/photos/#{p["owner"]}/#{p["id"]}"
%>
<a class="preview" href="<%= url %>" rel="<%= medium %>">
<img class="flickr-img" src="<%= square %>" alt="" />
</a>
<% end
end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment