File tree Expand file tree Collapse file tree 4 files changed +115
-0
lines changed Expand file tree Collapse file tree 4 files changed +115
-0
lines changed 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+ /**
15+ * Get rate limits
16+ *
17+ * @return \Guzzle\Http\EntityBodyInterface|mixed|string
18+ */
19+ public function getRateLimits ()
20+ {
21+ return $ this ->get ('rate_limit ' );
22+ }
23+
24+ /**
25+ * Get core rate limit
26+ *
27+ * @return integer
28+ */
29+ public function getCoreLimit ()
30+ {
31+ $ response = $ this ->getRateLimits ();
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+ return $ response ['resources ' ]['search ' ]['limit ' ];
44+ }
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+ /**
9+ * @test
10+ */
11+ public function shouldReturnRateLimitArray ()
12+ {
13+ $ expectedArray = [
14+ 'resources ' => [
15+ 'core ' => [
16+ 'limit ' => 5000 ,
17+ 'remaining ' => 4999 ,
18+ 'reset ' => 1372700873
19+ ],
20+ 'search ' => [
21+ 'limit ' => 30 ,
22+ 'remaining ' => 18 ,
23+ 'reset ' => 1372697452
24+ ]
25+ ]
26+ ];
27+
28+ $ api = $ this ->getApiMock ();
29+ $ api ->expects ($ this ->once ())
30+ ->method ('get ' )
31+ ->with ('rate_limit ' )
32+ ->will ($ this ->returnValue ($ expectedArray ));
33+
34+ $ this ->assertEquals ($ expectedArray , $ api ->getRateLimits ());
35+ }
36+
37+ protected function getApiClass ()
38+ {
39+ return 'Github\Api\RateLimit ' ;
40+ }
41+ }
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 (['resources ' => ['core ' => ['limit ' => 60 ]]], $ response );
19+
20+ }
21+
22+ }
You can’t perform that action at this time.
0 commit comments