File tree Expand file tree Collapse file tree 6 files changed +136
-0
lines changed Expand file tree Collapse file tree 6 files changed +136
-0
lines changed Original file line number Diff line number Diff line change 1515 * [ Teams] ( organization/teams.md )
1616* [ Pull Requests] ( pull_requests.md )
1717 * [ Comments] ( pull_request/comments.md )
18+ * [ Rate Limits] ( rate_limits.md )
1819* [ Repositories] ( repos.md )
1920 * [ Contents] ( repo/contents.md )
2021 * [ Releases] ( repo/releases.md )
Original file line number Diff line number Diff line change 1+ ## Rate Limit API
2+ [ Back to the navigation] ( README.md )
3+
4+ Get Rate Limit
5+ Wraps [ GitHub Rate Limit API] ( http://developer.github.com/v3/rate_limit/ ) .
6+
7+ #### Get All Rate Limits.
8+
9+ ``` php
10+ $rateLimits = $github->api('rate_limit')->getRateLimits();
11+ ```
12+
13+ #### Get Core Rate Limit
14+
15+ ``` php
16+ $coreLimit = $github->api('rate_limit')->getCoreLimit();
17+ ```
18+
19+ #### Get Search Rate Limit
20+
21+ ``` php
22+ $searchLimit = $github->api('rate_limit)->getSearchLimit');
23+ ```
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Github \Api ;
4+
5+ /**
6+ * Get rate limits
7+ *
8+ * @link https://developer.github.com/v3/rate_limit/
9+ * @author Jeff Finley <[email protected] > 10+ */
11+ class RateLimit extends AbstractApi
12+ {
13+ /**
14+ * Get rate limits
15+ *
16+ * @return array
17+ */
18+ public function getRateLimits ()
19+ {
20+ return $ this ->get ('rate_limit ' );
21+ }
22+
23+ /**
24+ * Get core rate limit
25+ *
26+ * @return integer
27+ */
28+ public function getCoreLimit ()
29+ {
30+ $ response = $ this ->getRateLimits ();
31+
32+ return $ response ['resources ' ]['core ' ]['limit ' ];
33+ }
34+
35+ /**
36+ * Get search rate limit
37+ *
38+ * @return integer
39+ */
40+ public function getSearchLimit ()
41+ {
42+ $ response = $ this ->getRateLimits ();
43+
44+ return $ response ['resources ' ]['search ' ]['limit ' ];
45+ }
46+ }
Original file line number Diff line number Diff line change 2929 * @method Api\PullRequest pr()
3030 * @method Api\PullRequest pullRequest()
3131 * @method Api\PullRequest pullRequests()
32+ * @method Api\RateLimit ratelimit()
3233 * @method Api\Repo repo()
3334 * @method Api\Repo repos()
3435 * @method Api\Repo repository()
@@ -168,6 +169,11 @@ public function api($name)
168169 $ api = new Api \PullRequest ($ this );
169170 break ;
170171
172+ case 'rateLimit ' :
173+ case 'rate_limit ' :
174+ $ api = new Api \RateLimit ($ this );
175+ break ;
176+
171177 case 'repo ' :
172178 case 'repos ' :
173179 case 'repository ' :
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Github \Tests \Api ;
4+
5+ class RateLimitTest extends TestCase
6+ {
7+ /**
8+ * @test
9+ */
10+ public function shouldReturnRateLimitArray ()
11+ {
12+ $ expectedArray = array (
13+ 'resources ' => array (
14+ 'core ' => array (
15+ 'limit ' => 5000 ,
16+ 'remaining ' => 4999 ,
17+ 'reset ' => 1372700873
18+ ),
19+ 'search ' => array (
20+ 'limit ' => 30 ,
21+ 'remaining ' => 18 ,
22+ 'reset ' => 1372697452
23+ )
24+ )
25+ );
26+
27+ $ api = $ this ->getApiMock ();
28+ $ api ->expects ($ this ->once ())
29+ ->method ('get ' )
30+ ->with ('rate_limit ' )
31+ ->will ($ this ->returnValue ($ expectedArray ));
32+
33+ $ this ->assertEquals ($ expectedArray , $ api ->getRateLimits ());
34+ }
35+
36+ protected function getApiClass ()
37+ {
38+ return 'Github\Api\RateLimit ' ;
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Github \Tests \Functional ;
4+
5+ /**
6+ * @group functional
7+ */
8+ class RateLimitTest extends TestCase
9+ {
10+ /**
11+ * @test
12+ */
13+ public function shouldRetrievedRateLimits ()
14+ {
15+ $ response = $ this ->client ->api ('rate_limit ' )->getRateLimits ();
16+
17+ $ this ->assertArrayHasKey ('resources ' , $ response );
18+ $ this ->assertArraySubset (array ('resources ' => array ('core ' => array ('limit ' => 60 ))), $ response );
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments