-
-
Notifications
You must be signed in to change notification settings - Fork 599
Add rate limit endpoint #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cursedcoder
merged 9 commits into
KnpLabs:master
from
quickliketurtle:add-rate-limit-endpoint
Oct 11, 2015
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9ee0672
Added rate limit endpoint and tests
quickliketurtle cf0a6d4
added documentation
quickliketurtle 8733443
style updates from styleci check
quickliketurtle 177e5f9
Style updates from Styleci check
quickliketurtle de6142b
code style updates
quickliketurtle fd76633
updated docblock
quickliketurtle a07bce5
remove extra line
quickliketurtle 8775cb2
Added link to rate_limits.md
quickliketurtle eca9e8c
Add blank line before return statements.
quickliketurtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please separate return statement with 1 blank line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cursedcoder
You should use
symfony
preset on your StyleCI config file or at least, add thereturn
fixer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #323.