<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Perplexed Labs &#187; flickr</title>
	<atom:link href="http://blog.perplexedlabs.com/tag/flickr/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.perplexedlabs.com</link>
	<description>web development war stories from the frontlines to the backend</description>
	<lastBuildDate>Mon, 16 May 2011 14:19:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Flickr, RSS, and Ruby</title>
		<link>http://blog.perplexedlabs.com/2008/02/26/flickr-rss-and-ruby/</link>
		<comments>http://blog.perplexedlabs.com/2008/02/26/flickr-rss-and-ruby/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 13:31:30 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[flickr]]></category>

		<guid isPermaLink="false">http://www.perplexedlabs.com/2008/02/26/flickr-rss-and-ruby/</guid>
		<description><![CDATA[Flickr is one of my favorite web applications. Often times, instead of building a photo uploading utility for small web sites I am working on, I will simply integrate the clients' Flickr account into their website, using RSS and the Flickr API. Here's how I do it. Get the RSS Feed require 'rss' require 'net/http' [...]


Related posts:<ol><li><a href='http://blog.perplexedlabs.com/2010/04/28/formstack-api-call-over-ssl-with-ruby/' rel='bookmark' title='Permanent Link: FormStack API Call Over SSL With Ruby'>FormStack API Call Over SSL With Ruby</a></li>
<li><a href='http://blog.perplexedlabs.com/2009/07/31/twitter-and-sd-news/' rel='bookmark' title='Permanent Link: Twitter and SD News'>Twitter and SD News</a></li>
<li><a href='http://blog.perplexedlabs.com/2009/01/13/installing-ruby-enterprise-edition-with-phusion-passenger/' rel='bookmark' title='Permanent Link: Installing Ruby Enterprise Edition with Phusion Passenger'>Installing Ruby Enterprise Edition with Phusion Passenger</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Flickr is one of my favorite web applications.  Often times, instead of building a photo uploading utility for small web sites I am working on, I will simply integrate the clients' Flickr account into their website, using RSS and the Flickr API.  Here's how I do it.</p>
<p><strong>Get the RSS Feed<br />
</strong>
<pre class="brush: ruby; title: ;">
require 'rss'
require 'net/http'
require 'rexml/document'

@flickr_rss = RSS::Parser.parse(open('http://api.flickr.com/services/feeds/photos_public.gne?id=24034605@N04&amp;lang=en-us&amp;format=rss_200').read, false)
</pre>
<p>Next, I initialize an array that will hold hashes with the values I need for rendering the images in the view.  This will make sense in a minute.</p>
<pre class="brush: ruby; title: ;">
@flickr = Array.new
</pre>
<p><strong>Use Flickr API to get the URL to the thumbnails<br />
</strong>
<pre class="brush: ruby; title: ;">
@flickr_rss.items.each do |i|
photo_id = flickr_photo_id(i.link)
url = &quot;http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&amp;api_key=#{your_api_key}&amp;photo_id=#{photo_id}&quot;
flickr_response = REXML::Document.new(Net::HTTP.get_response(URI.parse(url)).body)
flickr_response.elements.each('rsp/sizes/size') do |e|
@flickr &lt;&lt; {&quot;title&quot; =&gt; i.title, &quot;src&quot; =&gt; e.attribute(&quot;source&quot;), &quot;link&quot; =&gt; i.link} if e.attribute(&quot;label&quot;).value == &quot;Thumbnail&quot;
end
end

def flickr_photo_id(url)
url.split('/').last
end
</pre>
<p>So now I have an array of hashes with links to the Thumbnails of each Flickr photo in the RSS feed.  You can modify the above code very easily to get the Small, Medium, Large etc. sizes.</p>
<p><strong>Render the View</strong></p>
<pre class="brush: ruby; title: ;">
&lt;% @flickr.each_with_index do |f, i| -%&gt;
&lt;div align=&quot;center&quot;&gt;&lt;a href=&quot;&lt;%= f['link'] -%&gt;&quot;&gt;&lt;img class=&quot;img_border&quot; src=&quot;&lt;%= f['src'] -%&gt;&quot; border=&quot;0&quot; title=&quot;&lt;%= f['title'] -%&gt;&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
&lt;% end -%&gt;
</pre>
<p>Check it out <a href="http://www.110collegeandcareer.com/grow/">in action</a>.</p>


<p>Related posts:<ol><li><a href='http://blog.perplexedlabs.com/2010/04/28/formstack-api-call-over-ssl-with-ruby/' rel='bookmark' title='Permanent Link: FormStack API Call Over SSL With Ruby'>FormStack API Call Over SSL With Ruby</a></li>
<li><a href='http://blog.perplexedlabs.com/2009/07/31/twitter-and-sd-news/' rel='bookmark' title='Permanent Link: Twitter and SD News'>Twitter and SD News</a></li>
<li><a href='http://blog.perplexedlabs.com/2009/01/13/installing-ruby-enterprise-edition-with-phusion-passenger/' rel='bookmark' title='Permanent Link: Installing Ruby Enterprise Edition with Phusion Passenger'>Installing Ruby Enterprise Edition with Phusion Passenger</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.perplexedlabs.com/2008/02/26/flickr-rss-and-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

