Created
January 31, 2016 17:55
-
-
Save senthilsweb/f703951c5b6789b94cbb to your computer and use it in GitHub Desktop.
Search & paginate flicker photos for a given search filters and returns the collection of photos urls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Client = require('node-rest-client').Client; | |
var _ = require("underscore"); | |
var json2xls = require('json2xls'); | |
var fs = require('fs'); | |
//API Explorer : https://www.flickr.com/services/api/explore/flickr.photos.search | |
var flickr_api_endpoint = "https://api.flickr.com/services/rest/?method=flickr.photos.search&format=json&nojsoncallback=1"; | |
var flickerPhotos = []; | |
exports.handler = function (request, context) { | |
//1) Resolve input and execute REST calls | |
try { | |
var flickr_api_key = request.api_key; | |
var flickr_search_tags = request.search_tags; | |
var flickr_search_text = request.search_text; | |
var flickr_search_limit = request.search_limit; | |
var flickr_search_currentpage = request.search_currentpage; | |
flickr_api_endpoint = flickr_api_endpoint + "&api_key=" + flickr_api_key + "&tags=" + flickr_search_tags + "&text=" + flickr_search_text + "&per_page=" + flickr_search_limit + "&page=" + flickr_search_currentpage | |
console.log(flickr_api_endpoint); | |
var client = new Client(); | |
client.registerMethod("flickrSearch", flickr_api_endpoint, "GET"); | |
} | |
catch (e) { | |
context.fail("Something wrong in the input! please check. [" + e.message + "]"); | |
} | |
//2) Process REST call response and send it back to the client. | |
var args = { headers: { "Content-Type": "application/json", "Cache-Control": "no-cache" } }; | |
client.methods.flickrSearch(args,function (res, rawdata) { | |
try { | |
console.log("Length = [" + res.photos.photo.length + "]"); | |
_.each(res.photos.photo, function (item, index, list) { | |
//console.log("http://farm" + item.farm + ".staticflickr.com/" + item.server + "/" + item.id + "_" + item.secret + "_b.jpg"); | |
flickerPhotos[index] = "http://farm" + item.farm + ".staticflickr.com/" + item.server + "/" + item.id + "_" + item.secret + "_b.jpg"; | |
}); | |
context.succeed(flickerPhotos); | |
} | |
catch (e) { | |
context.fail(e.message); | |
} | |
} | |
) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment