2016-02-29 10:45:19 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-02-15 21:25:32 +00:00
|
|
|
var pify = require('pify');
|
|
|
|
var request = pify(require('request'));
|
2016-02-29 10:45:19 +00:00
|
|
|
|
2017-02-15 21:25:32 +00:00
|
|
|
module.exports = function getUserInfo(username) {
|
|
|
|
return request.get({
|
2016-02-29 10:45:19 +00:00
|
|
|
url: 'https://api.github.com/users/' + username,
|
|
|
|
headers: {
|
|
|
|
'User-Agent': 'request'
|
|
|
|
}
|
2017-02-15 21:25:32 +00:00
|
|
|
})
|
|
|
|
.then(res => {
|
2016-03-06 18:37:26 +00:00
|
|
|
var body = JSON.parse(res.body);
|
2017-02-23 19:02:55 +00:00
|
|
|
var profile = body.blog || body.html_url;
|
|
|
|
profile = profile.startsWith('http') ? profile : 'http://' + profile;
|
|
|
|
|
2017-02-15 21:25:32 +00:00
|
|
|
return {
|
2016-03-06 18:37:26 +00:00
|
|
|
login: body.login,
|
2016-06-28 09:29:23 +00:00
|
|
|
name: body.name || username,
|
2016-03-06 18:37:26 +00:00
|
|
|
avatar_url: body.avatar_url,
|
2017-02-23 19:02:55 +00:00
|
|
|
profile
|
2016-03-06 18:37:26 +00:00
|
|
|
};
|
2016-02-29 10:45:19 +00:00
|
|
|
});
|
2016-03-06 23:20:24 +00:00
|
|
|
};
|