Created
August 31, 2014 13:19
-
-
Save magdiel01/4e826a5545a48965c01d to your computer and use it in GitHub Desktop.
GitHub repos by user
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
var https = require('https'); | |
var getRepos = function(username, callback) { | |
var options = { | |
host: 'api.github.com', | |
path: '/users/' + username + '/repos', | |
method: 'GET', | |
headers: { | |
'user-agent': 'nodejs' | |
} | |
}; | |
var request = https.request(options, function(response) { | |
var body = ''; | |
response.on('data', function(chunk) { | |
body+= chunk.toString('utf8'); | |
}); | |
response.on('end', function() { | |
var repos = []; | |
var json = JSON.parse(body); | |
json.forEach(function(repo) { | |
repos.push({ | |
name: repo.name, | |
description: repo.description | |
}); | |
}); | |
callback(repos); | |
}); | |
}); | |
request.end(); | |
}; | |
getRepos('henryreyes', function(repos) { | |
console.log('Henry has ' + repos.length + ' repos'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment