File tree 6 files changed +136
-0
lines changed 6 files changed +136
-0
lines changed Original file line number Diff line number Diff line change 15
15
* [ Teams] ( organization/teams.md )
16
16
* [ Pull Requests] ( pull_requests.md )
17
17
* [ Comments] ( pull_request/comments.md )
18
+ * [ Rate Limits] ( rate_limits.md )
18
19
* [ Repositories] ( repos.md )
19
20
* [ Contents] ( repo/contents.md )
20
21
* [ 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 <quickliketurtle@gmail.com>
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 29
29
* @method Api\PullRequest pr()
30
30
* @method Api\PullRequest pullRequest()
31
31
* @method Api\PullRequest pullRequests()
32
+ * @method Api\RateLimit ratelimit()
32
33
* @method Api\Repo repo()
33
34
* @method Api\Repo repos()
34
35
* @method Api\Repo repository()
@@ -168,6 +169,11 @@ public function api($name)
168
169
$ api = new Api \PullRequest ($ this );
169
170
break ;
170
171
172
+ case 'rateLimit ' :
173
+ case 'rate_limit ' :
174
+ $ api = new Api \RateLimit ($ this );
175
+ break ;
176
+
171
177
case 'repo ' :
172
178
case 'repos ' :
173
179
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