-
-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from quickliketurtle/add-rate-limit-endpoint
Add rate limit endpoint
- Loading branch information
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## Rate Limit API | ||
[Back to the navigation](README.md) | ||
|
||
Get Rate Limit | ||
Wraps [GitHub Rate Limit API](http://developer.github.com/v3/rate_limit/). | ||
|
||
#### Get All Rate Limits. | ||
|
||
```php | ||
$rateLimits = $github->api('rate_limit')->getRateLimits(); | ||
``` | ||
|
||
#### Get Core Rate Limit | ||
|
||
```php | ||
$coreLimit = $github->api('rate_limit')->getCoreLimit(); | ||
``` | ||
|
||
#### Get Search Rate Limit | ||
|
||
```php | ||
$searchLimit = $github->api('rate_limit)->getSearchLimit'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Github\Api; | ||
|
||
/** | ||
* Get rate limits | ||
* | ||
* @link https://developer.github.com/v3/rate_limit/ | ||
* @author Jeff Finley <[email protected]> | ||
*/ | ||
class RateLimit extends AbstractApi | ||
{ | ||
/** | ||
* Get rate limits | ||
* | ||
* @return array | ||
*/ | ||
public function getRateLimits() | ||
{ | ||
return $this->get('rate_limit'); | ||
} | ||
|
||
/** | ||
* Get core rate limit | ||
* | ||
* @return integer | ||
*/ | ||
public function getCoreLimit() | ||
{ | ||
$response = $this->getRateLimits(); | ||
|
||
return $response['resources']['core']['limit']; | ||
} | ||
|
||
/** | ||
* Get search rate limit | ||
* | ||
* @return integer | ||
*/ | ||
public function getSearchLimit() | ||
{ | ||
$response = $this->getRateLimits(); | ||
|
||
return $response['resources']['search']['limit']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api; | ||
|
||
class RateLimitTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldReturnRateLimitArray() | ||
{ | ||
$expectedArray = array( | ||
'resources' => array( | ||
'core' => array( | ||
'limit' => 5000, | ||
'remaining' => 4999, | ||
'reset' => 1372700873 | ||
), | ||
'search' => array( | ||
'limit' => 30, | ||
'remaining' => 18, | ||
'reset' => 1372697452 | ||
) | ||
) | ||
); | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('rate_limit') | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->getRateLimits()); | ||
} | ||
|
||
protected function getApiClass() | ||
{ | ||
return 'Github\Api\RateLimit'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Functional; | ||
|
||
/** | ||
* @group functional | ||
*/ | ||
class RateLimitTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldRetrievedRateLimits() | ||
{ | ||
$response = $this->client->api('rate_limit')->getRateLimits(); | ||
|
||
$this->assertArrayHasKey('resources', $response); | ||
$this->assertArraySubset(array('resources' => array('core' => array('limit' => 60))), $response); | ||
} | ||
} |