-
-
Notifications
You must be signed in to change notification settings - Fork 598
Add Starred API, revised Watchers API and Improved Docs #197
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fb54d8a
added starring api
valtlfelipe 784a087
updated documentation
valtlfelipe 3bf25e8
added tests for Starred API
valtlfelipe 4af5314
Merge branch 'master' of https://github.com/valtlfelipe/php-github-api
valtlfelipe 59bdcf7
improved documentation
valtlfelipe af276bc
changed documentation and watch repo api endpoint
valtlfelipe ab0752a
changed current_user watch repo method
valtlfelipe 2ed99b2
revised comments
valtlfelipe 3fdd771
corrected watchers test
valtlfelipe 3eec9e7
fix current version break
valtlfelipe 65894c4
removed unused class and changed docblock
valtlfelipe 6acfc0f
removed test
valtlfelipe 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
## Activity API (incomplete) | ||
[Back to the navigation](index.md) | ||
|
||
Access to Starring and Watching a Repository for [non] authenticated users. | ||
Wrap [GitHub Activity API](https://developer.github.com/v3/activity/). | ||
|
||
> *** No authentication required. *** | ||
|
||
### Get repos that a specific user has starred | ||
|
||
```php | ||
$users = $client->api('user')->starred('ornicar'); | ||
``` | ||
|
||
Returns an array of starred repos. | ||
|
||
### Get repos that a specific user is watching | ||
|
||
```php | ||
$users = $client->api('user')->watched('ornicar'); | ||
``` | ||
|
||
Returns an array of watched repos. | ||
|
||
> *** Requires [authentication](security.md). *** | ||
|
||
### Get repos that a authenticated user has starred | ||
|
||
```php | ||
$activity = $client->api('current_user')->starring()->all(); | ||
``` | ||
Returns an array of starred repos. | ||
|
||
### Check if authenticated user has starred a specific repo | ||
|
||
```php | ||
$owner = "KnpLabs"; | ||
$repo = "php-github-api"; | ||
$activity = $client->api('current_user')->starring()->check($owner, $repo); | ||
``` | ||
Throws an Exception with code 404 in case that the repo is not starred by the authenticated user or NULL in case that it is starred by the authenticated user. | ||
|
||
### Star a specific repo for authenticated user | ||
|
||
```php | ||
$owner = "KnpLabs"; | ||
$repo = "php-github-api"; | ||
$activity = $client->api('current_user')->starring()->star($owner, $repo); | ||
``` | ||
Throws an Exception in case of failure or NULL in case of success. | ||
|
||
### Unstar a specific repo for authenticated user | ||
|
||
```php | ||
$owner = "KnpLabs"; | ||
$repo = "php-github-api"; | ||
$activity = $client->api('current_user')->starring()->unstar($owner, $repo); | ||
``` | ||
Throws an Exception in case of failure or NULL in case of success. | ||
|
||
|
||
### Get repos that a authenticated user is watching | ||
|
||
```php | ||
$activity = $client->api('current_user')->watchers()->all(); | ||
``` | ||
Returns an array of watched repos. | ||
|
||
### Check if authenticated user is watching a specific repo | ||
|
||
```php | ||
$owner = "KnpLabs"; | ||
$repo = "php-github-api"; | ||
$activity = $client->api('current_user')->watchers()->check($owner, $repo); | ||
``` | ||
Throws an Exception with code 404 in case that the repo is not beeing watched by the authenticated user or NULL in case that it is beeing watched by the authenticated user. | ||
|
||
### Watch a specific repo for authenticated user | ||
|
||
```php | ||
$owner = "KnpLabs"; | ||
$repo = "php-github-api"; | ||
$activity = $client->api('current_user')->watchers()->watch($owner, $repo); | ||
``` | ||
Throws an Exception in case of failure or NULL in case of success. | ||
|
||
### Stop watching a specific repo for authenticated user | ||
|
||
```php | ||
$owner = "KnpLabs"; | ||
$repo = "php-github-api"; | ||
$activity = $client->api('current_user')->watchers()->unwatch($owner, $repo); | ||
``` | ||
Throws an Exception in case of failure or NULL in case of success. |
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
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,65 @@ | ||
<?php | ||
|
||
namespace Github\Api\CurrentUser; | ||
|
||
use Github\Api\AbstractApi; | ||
|
||
/** | ||
* @link https://developer.github.com/v3/activity/starring/ | ||
* @author Felipe Valtl de Mello <eu@felipe.im> | ||
*/ | ||
class Starring extends AbstractApi | ||
{ | ||
/** | ||
* List repositories starred by the authenticated user | ||
* @link https://developer.github.com/v3/activity/starring/ | ||
* | ||
* @param integer $page | ||
* @return array | ||
*/ | ||
public function all($page = 1) | ||
{ | ||
return $this->get('user/starred', array( | ||
'page' => $page | ||
)); | ||
} | ||
|
||
/** | ||
* Check that the authenticated user starres a repository | ||
* @link https://developer.github.com/v3/activity/starring/ | ||
* | ||
* @param string $username the user who owns the repo | ||
* @param string $repository the name of the repo | ||
* @return array | ||
*/ | ||
public function check($username, $repository) | ||
{ | ||
return $this->get('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); | ||
} | ||
|
||
/** | ||
* Make the authenticated user star a repository | ||
* @link https://developer.github.com/v3/activity/starring/ | ||
* | ||
* @param string $username the user who owns the repo | ||
* @param string $repository the name of the repo | ||
* @return array | ||
*/ | ||
public function star($username, $repository) | ||
{ | ||
return $this->put('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); | ||
} | ||
|
||
/** | ||
* Make the authenticated user unstar a repository | ||
* @link https://developer.github.com/v3/activity/starring | ||
* | ||
* @param string $username the user who owns the repo | ||
* @param string $repository the name of the repo | ||
* @return array | ||
*/ | ||
public function unstar($username, $repository) | ||
{ | ||
return $this->delete('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api; | ||
|
||
use Github\Tests\Api\TestCase; | ||
|
||
class StarringTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldGetStarred() | ||
{ | ||
$expectedValue = array( | ||
array('name' => 'l3l0/test'), | ||
array('name' => 'cordoval/test') | ||
); | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('user/starred') | ||
->will($this->returnValue($expectedValue)); | ||
|
||
$this->assertEquals($expectedValue, $api->all()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldCheckStar() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('user/starred/l3l0/test') | ||
->will($this->returnValue(null)); | ||
|
||
$this->assertNull($api->check('l3l0', 'test')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldStarUser() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('put') | ||
->with('user/starred/l3l0/test') | ||
->will($this->returnValue(null)); | ||
|
||
$this->assertNull($api->star('l3l0', 'test')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldUnstarUser() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('delete') | ||
->with('user/starred/l3l0/test') | ||
->will($this->returnValue(null)); | ||
|
||
$this->assertNull($api->unstar('l3l0', 'test')); | ||
} | ||
|
||
protected function getApiClass() | ||
{ | ||
return 'Github\Api\CurrentUser\Starring'; | ||
} | ||
} |
Oops, something went wrong.
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.
could you use same lowercase as other docblocks?
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.
yeah, sorry about this. I saw you already fixed it! Thanks ;)