Support GitHub followers
This commit is contained in:
parent
f3238a7888
commit
5c35ef60dc
35
server.js
35
server.js
|
@ -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) {
|
||||
|
|
4
try.html
4
try.html
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user