Skip to content

Instantly share code, notes, and snippets.

@theycallmeswift
Created June 20, 2013 23:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theycallmeswift/5827624 to your computer and use it in GitHub Desktop.
Save theycallmeswift/5827624 to your computer and use it in GitHub Desktop.
Get random Tumblr Images from Programmer Ryan Gosling
module.exports = function getImage(cb) {
var request = require('request')
, callback = cb || function() {}
, tumblr_key = process.env.TUMBLR_KEY
, post = Math.floor((Math.random()*96))
, url = "http://api.tumblr.com/v2/blog/programmerryangosling.tumblr.com/posts?api_key=" + tumblr_key + "&type=photo&limit=1&offset=" + post;
request(url, function(err, res, body) {
try {
var image = JSON.parse(body).response.posts[0].photos[0].original_size.url;
callback(err, "<img src='" + image + "' width='50%' />");
} catch(e) {
callback(e);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment