libflickr.lzx
<library>
<node id="gGlobals">
<attribute name="SHAREDSECRET" type="string" value="b199acb45fd055e7
"/>
<attribute name="RESTSRC" type="string" value="http://api.flickr.com/services/rest/
"/>
</node>
<class name="photo" width="75" height="75">
<handler name="ondata" args="d">
if ( !d ) return;
this.showSize('s');
</handler>
<method name="getImageURL" args="suffix">
var id=datapath.p.getAttr("id");
// build URL to image
var server=datapath.p.getAttr("server");
var secret=datapath.p.getAttr("secret");
var s="http://static.flickr.com/"+server+"/"+id+"_"+secret + suffix + ".jpg";
return s;
</method>
<method name="showSize" args="sz">
var suffix = "_s";
switch (sz) {
case 's':
case 't':
case 'b':
case 'o':
suffix = "_" + sz;
break;
case 'm':
suffix = "";
}
this.setSource(this.getImageURL(suffix));
</method>
</class>
<node name="gFlickr">
<handler name="oninit">
this.errdel = new lz.Delegate( this, "dsError" );
this['errdel'].register( photods , "onerror" );
this['errdel'].register( photods , "ontimeout" );
</handler>
<method name="dsError" args="ignore=null">
this['gError'].show();
</method>
<method name="doFlickrRequest" args="ds, argobjarr, apikey">
// clear query params
ds.setQueryParams(null);
// string to start building sig
var api_sig_string=gGlobals.SHAREDSECRET;
// set source
ds.setAttribute('src', gGlobals.RESTSRC);
// add api_key
argobjarr.push({argname:"api_key", argvalue:apikey});
// alphabetize argobjs comparator
var argcomparator = function (a, b) {
if (a.argname < b.argname) return -1;
if (a.argname > b.argname) return 1;
return 0
}
argobjarr.sort(argcomparator)
// build argobject
for (var i=0;i<argobjarr.length;i++)
{
var argobj=argobjarr[i];
ds.setQueryParam(argobj.argname, argobj.argvalue);
}
// make actual request
ds.doRequest();
Debug.write('Loading URL', ds);
</method>
<method name="getRecent" args="apikey">
var argobj = [
{argname:"method",
argvalue:"flickr.photos.getRecent"},
{argname:"extras",
argvalue:"owner_name"}
]
this.doFlickrRequest(photods, argobj, apikey);
</method>
<method name="getInteresting" args="apikey">
var argobj = [
{argname:"method",
argvalue:"flickr.interestingness.getList"},
{argname:"extras",
argvalue:"owner_name"}
]
this.doFlickrRequest(photods, argobj, apikey);
</method>
<method name="searchWithTags" args="tags, apikey">
var argobj = [
{argname:"method",
argvalue:"flickr.photos.search"},
{argname:"tags",
argvalue:tags},
{argname:"extras",
argvalue:"owner_name"}
]
this.doFlickrRequest(photods, argobj, apikey);
</method>
<method name="loadDetails" args="photo_id, apikey">
var argobj = [
{argname:"method",
argvalue:"flickr.photos.getInfo"},
{argname:"photo_id",
argvalue: photo_id}
];
this.doFlickrRequest(detailsds, argobj, apikey);
</method>
</node>
<dataset name="photods" ondata="if (global['debugdata']) Debug.write('got data', this)" type="http"/>
<dataset name="detailsds" ondata="if (global['debugdata']) Debug.write('got data', this)" type="http"/>
</library>
Cross References
Classes
Named Instances