Skip to content

Instantly share code, notes, and snippets.

@egardner
Last active November 21, 2016 02:11
Show Gist options
  • Save egardner/c9ee3eb33d3142c0dd072325ea3405f5 to your computer and use it in GitHub Desktop.
Save egardner/c9ee3eb33d3142c0dd072325ea3405f5 to your computer and use it in GitHub Desktop.
Working with Github API in node
// Use the Github Node library
// Optional: use the Bluebird promise library to handle responses
var GitHubApi = require('github')
var gh = new GitHubApi({
debug: true,
Promise: require('bluebird')
})
// Get a User's public repos
// Repos is a Bluebird Promise object. Traditional callback approach also works here.
// You can use the .then() chainable methods to do things with the data after the
// promise is resolved, per standard promise usage.
repos = gh.repos.getForUser({ username: "gettypubs" })
.then(function(data) { console.log(data) })
// Bluebird also allows synchronous inspection of promises once they have been resolved.
// An error will be thrown if not, so check first. promise.value() returns the data.
repos = gh.repos.getForUser({ username: "gettypubs" })
if (repos.isResolved()) {
repos.value()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment