Created
June 20, 2013 23:17
-
-
Save theycallmeswift/5827624 to your computer and use it in GitHub Desktop.
Get random Tumblr Images from Programmer Ryan Gosling
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
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