Support GitHub followers

This commit is contained in:
Thaddee Tyl 2015-01-25 18:44:17 +01:00
parent f3238a7888
commit 5c35ef60dc
2 changed files with 39 additions and 0 deletions

View File

@ -1929,6 +1929,41 @@ cache(function(data, match, sendBadge, request) {
});
}));
// GitHub user followers integration.
camp.route(/^\/github\/followers\/([^\/]+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var user = match[1]; // eg, qubyte
var format = match[2];
var apiUrl = 'https://api.github.com/users/' + user;
// Using our OAuth App secret grants us 5000 req/hour
// instead of the standard 60 req/hour.
if (serverSecrets) {
apiUrl += '?client_id=' + serverSecrets.gh_client_id
+ '&client_secret=' + serverSecrets.gh_client_secret;
}
var badgeData = getBadgeData('followers', data);
// A special User-Agent is required:
// http://developer.github.com/v3/#user-agent-required
request(apiUrl, { headers: githubHeaders }, function(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
}
try {
if ((+res.headers['x-ratelimit-remaining']) === 0) {
return; // Hope for the best in the cache.
}
badgeData.text[1] = JSON.parse(buffer).followers;
badgeData.colorscheme = null;
badgeData.colorB = '#4183C4';
sendBadge(format, badgeData);
} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
});
}));
// Chef cookbook integration.
camp.route(/^\/cookbook\/v\/(.*)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {

View File

@ -450,6 +450,10 @@ Pixel-perfect   Retina-ready   Fast   Consistent   Hackable
<td><img src='/github/stars/badges/shields.svg' alt=''/></td>
<td><code>https://img.shields.io/github/stars/badges/shields.svg</code></td>
</tr>
<tr><th> GitHub followers: </th>
<td><img src='/github/followers/espadrine.svg' alt=''/></td>
<td><code>https://img.shields.io/github/followers/espadrine.svg</code></td>
</tr>
<tr><th> Wordpress rating: </th>
<td><img src='/wordpress/plugin/r/akismet.svg' alt=''/></td>
<td><code>https://img.shields.io/wordpress/plugin/r/akismet.svg</code></td>