<?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>Software and Opinions &#187; dojo</title>
	<atom:link href="http://ianloic.com/tag/dojo/feed/" rel="self" type="application/rss+xml" />
	<link>http://ianloic.com</link>
	<description>from Ian McKellar</description>
	<lastBuildDate>Wed, 07 Sep 2011 21:48:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://ianloic.com/?pushpress=hub'/>
		<item>
		<title>Flickr for Dojo</title>
		<link>http://ianloic.com/2007/02/10/flickr_for_dojo/</link>
		<comments>http://ianloic.com/2007/02/10/flickr_for_dojo/#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>Ian McKellar</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I&#8217;ve been working on a little Dojo based application which talks to Flickr, so I put together a little library which uses Dojo to talk to Flickr using it&#8217;s rest JSON interface. Use It&#8217;s pretty simple to use, just include &#8230; <a href="http://ianloic.com/2007/02/10/flickr_for_dojo/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a little <a href="http://www.dojotoolkit.org/">Dojo</a> based application which talks to <a href="http://www.flickr.com/">Flickr</a>, so I put together a little library which uses Dojo to talk to Flickr using it&#8217;s rest <a href="http://www.json.org/">JSON</a> interface.</p>
<p><strong>Use</strong><br />
It&#8217;s pretty simple to use, just include the JavaScript file:</p>
<pre class="prettyprint">
&lt;script src="flickr.js"&gt;&lt;/script&gt;</pre>
<p>Tell the library what your <a href="http://www.flickr.com/services/api/keys/">keys</a> are:</p>
<pre class="prettyprint">
flickr.keys(API_KEY, SECRET_KEY);</pre>
<p>And you&#8217;re set to go.</p>
<p>The main entry-point is <code language="js">flickr.call</code>. As the first argument, you pass in a hash of arguments, as described in the <a href="http://www.flickr.com/services/api/">Flickr API documentation</a>. The method you&#8217;re calling is included in this hash. The second argument is optional and is a callback to be called with the response from the Flickr servers. The response will come back in JSON format so it is easy to handle it in JavaScript. The Flickr JSON response format is discussed in detail <a href="http://www.flickr.com/services/api/response.json.html">on the Flickr site</a>.</p>
<p>So what would all this look like? Something like this will load interesting photos from Flickr and add them to the current document:</p>
<pre class="prettyprint">
flickr.keys(API_KEY, SECRET_KEY);
var pagenum = 1;
function interesting () {
    flickr.call({method:'flickr.interestingness.getList',
            page: pagenum, per_page: 10}, interesting_cb);
    pagenum++;
}
function interesting_cb (response) {
    if (response.stat != 'ok') {
        var error = document.createElement('div');
        error.appendChild(document.createTextNode(response.message));
        document.body.appendChild(error);
        return;
    }
    for (var i in response.photos.photo) {
        var photo = response.photos.photo[i];
        var img = document.createElement('img');
        img.classname = 'interesting';
        img.setAttribute('src', 'http://farm'+photo.farm+
                '.static.flickr.com/'+photo.server+'/'+photo.id+
                '_'+photo.secret+'_s.jpg');
        img.setAttribute('width', '75');
        img.setAttribute('height', '75');

        var a = document.createElement('a');
        a.setAttribute('href', 'http://www.flickr.com/photos/'+
                photo.owner+'/'+photo.id);
        a.appendChild(img);

        document.body.appendChild(a)
    }
}</pre>
<p><strong>Implementation</strong><br />
I&#8217;m not actually using all that much from Dojo. The main thing I&#8217;m taking is the crypto library, specifically <a href="http://dojotoolkit.org/api/#dojo.crypto.MD5">dojo.crypto.MD5</a>. The way I&#8217;m making the actual JSON calls is by appending <code language="html"><script src="http://api.flickr.com/services/..."></script></code> elements to the page. Perhaps at some point I&#8217;ll move to using Dojo&#8217;s ScriptSrcIO but right now I&#8217;m not.</p>
<p>The current version of the code is attached: <a href="http://scratch.ianloic.com/wordpress/wp-content/uploads/2008/01/flickrjs.txt" title="flickr.js">flickr.js</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ianloic.com/2007/02/10/flickr_for_dojo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

