May 13th 2011 × mootools flickr api class via Request.JSONP
updated for mootools 1.3.2
I needed to bring some images into a thumbnail/gallery and decided to use flickr’s API for easy access. The result is a mini-api which allows you to control your options and parse the images that flickr sends back.
// the class
Request.flickr = new Class({
Extends: Request.JSONP,
options: {
callbackKey: "jsoncallback",
url: "http://www.flickr.com/services/rest/?",
log: true
},
initialize: function(params, options) {
this.parent(options);
this.options.url = this.options.url + Object.toQueryString(params);
},
success: function(data, script) {
this.parent(data, script);
},
imageURL: function(obj) {
return "http://farm{farm}.static.flickr.com/{server}/{id}_{secret}.jpg".substitute(obj);
}
});
// how to use
new Request.flickr({
format: 'json',
api_key: "e7df6c74d2545f55414423463bf99723", // your api here
per_page: 4,
tags: "mountains",
method: "flickr.photos.search"
}, {
onSuccess: function(data) {
target = $("action");
var self = this;
data.photos.photo.each(function(el) {
new Asset.image(self.imageURL(el), {
onload: function() {
this.inject(target);
}
});
});
}
}).send();
Want to see it in action? Here’s an embedded jsfiddle:
no
no




