Last active
November 21, 2016 02:11
-
-
Save egardner/c9ee3eb33d3142c0dd072325ea3405f5 to your computer and use it in GitHub Desktop.
Working with Github API in node
This file contains hidden or 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
// 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