Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit 045d8b7

Browse files
committed
Added Rate Limit API
1 parent cb27c48 commit 045d8b7

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,17 @@ search.users(options, function (err, users) {});
426426

427427
Here, we’re looking at users with the name Tom. We’re only interested in those with more than 42 repositories, and only if they have over 1,000 followers.
428428

429+
## Rate Limit API
430+
431+
```js
432+
var rateLimit = github.getRateLimit();
433+
```
434+
435+
Get the rate limit.
436+
437+
```js
438+
rateLimit.getRateLimit(function (err, rateInfo) {});
439+
```
429440

430441
## Change Log
431442

src/github.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,15 @@
990990
};
991991
};
992992

993+
// Rate Limit API
994+
// ==========
995+
996+
Github.RateLimit = function() {
997+
this.getRateLimit = function(cb) {
998+
_request('GET', '/rate_limit', null, cb);
999+
};
1000+
}
1001+
9931002
return Github;
9941003
};
9951004

@@ -1032,5 +1041,9 @@
10321041
});
10331042
};
10341043

1044+
Github.getRateLimit = function() {
1045+
return new Github.RateLimit();
1046+
};
1047+
10351048
return Github;
10361049
}));

test/test.rate-limit.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
var Github = require('../src/github.js');
4+
var testUser = require('./user.json');
5+
var github, rateLimit;
6+
7+
describe('Github.RateLimit', function() {
8+
before(function() {
9+
github = new Github({
10+
username: testUser.USERNAME,
11+
password: testUser.PASSWORD,
12+
auth: 'basic'
13+
});
14+
15+
rateLimit = github.getRateLimit();
16+
});
17+
18+
it('should get rate limit', function(done) {
19+
rateLimit.getRateLimit(function(err, rateInfo) {
20+
should.not.exist(err);
21+
rateInfo.should.be.an('object');
22+
rateInfo.should.have.deep.property('rate.limit');
23+
rateInfo.rate.limit.should.be.a('number');
24+
rateInfo.should.have.deep.property('rate.remaining');
25+
rateInfo.rate.remaining.should.be.a('number');
26+
rateInfo.rate.remaining.should.be.at.most(rateInfo.rate.limit);
27+
done();
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)