Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Created December 23, 2015 19:32
Show Gist options
  • Save dhigginbotham/c707e3674cec4464fe05 to your computer and use it in GitHub Desktop.
Save dhigginbotham/c707e3674cec4464fe05 to your computer and use it in GitHub Desktop.
...
var request = require('request'),
util = require('util');
function handleRequest(err, data) {
if (err) throw new Error(err);
if (data.statusCode == 200 ||
data.statusCode == 304) {
var json = JSON.parse(data.body);
return json.map(translateReq);
} else {
throw new Error(data.body);
}
}
var hasLoggedAStar = true;
function translateReq(star) {
if (!hasLoggedAStar) {
hasLoggedAStar = true;
console.log(star);
}
var output = {
name: star.name,
author: star.owner.login,
desc: star.description,
url: star.html_url,
api: star.url,
lang: star.language,
size: star.size
};
console.log(output);
return output;
}
function initializeStars(user, done) {
var opts = {
url: util.format('https://api.github.com/users/%s/starred', user),
headers: {'User-Agent': 'starseer'}
};
request.get(opts, handleRequest);
}
initializeStars('dhigginbotham');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment