-
-
Notifications
You must be signed in to change notification settings - Fork 599
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
Changes from 9 commits
fb54d8a
784a087
3bf25e8
4af5314
59bdcf7
af276bc
ab0752a
2ed99b2
3fdd771
3eec9e7
65894c4
6acfc0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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')->starred()->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')->starred()->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')->starred()->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')->starred()->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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,12 @@ | |
use Github\Api\CurrentUser\Followers; | ||
use Github\Api\CurrentUser\Notifications; | ||
use Github\Api\CurrentUser\Watchers; | ||
use Github\Api\CurrentUser\Starred; | ||
|
||
/** | ||
* @link http://developer.github.com/v3/users/ | ||
* @author Joseph Bielawski <[email protected]> | ||
* @revised Felipe Valtl de Mello <[email protected]> | ||
*/ | ||
class CurrentUser extends AbstractApi | ||
{ | ||
|
@@ -111,21 +113,22 @@ public function watchers() | |
{ | ||
return new Watchers($this->client); | ||
} | ||
|
||
|
||
/** | ||
* @Deprecated | ||
*/ | ||
public function watched($page = 1) | ||
{ | ||
return $this->get('user/watched', array( | ||
'page' => $page | ||
)); | ||
} | ||
|
||
/** | ||
* @link http://developer.github.com/changes/2012-9-5-watcher-api/ | ||
/** | ||
* @return Starred | ||
*/ | ||
public function starred($page = 1) | ||
public function starred() | ||
{ | ||
return $this->get('user/starred', array( | ||
'page' => $page | ||
)); | ||
return new Starred($this->client); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing the return value of an existing method is a BC break There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true, i will fix this |
||
} | ||
} |
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 <[email protected]> | ||
*/ | ||
class Starred extends AbstractApi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like this class is not used anymore as you named it Starring |
||
{ | ||
/** | ||
* 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)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,61 +5,62 @@ | |
use Github\Api\AbstractApi; | ||
|
||
/** | ||
* @link http://developer.github.com/v3/repos/watching/ | ||
* @link https://developer.github.com/v3/activity/watching/ | ||
* @author Joseph Bielawski <[email protected]> | ||
* @revised Felipe Valtl de Mello <[email protected]> | ||
*/ | ||
class Watchers extends AbstractApi | ||
{ | ||
/** | ||
* List repositories watched by the authenticated user | ||
* @link http://developer.github.com/v3/repos/watching/ | ||
* @link https://developer.github.com/v3/activity/watching/ | ||
* | ||
* @param integer $page | ||
* @return array | ||
*/ | ||
public function all($page = 1) | ||
{ | ||
return $this->get('user/watched', array( | ||
return $this->get('user/subscriptions', array( | ||
'page' => $page | ||
)); | ||
} | ||
|
||
/** | ||
* Check that the authenticated user watches a repository | ||
* @link http://developer.github.com/v3/repos/watching/ | ||
* @link https://developer.github.com/v3/activity/watching/ | ||
* | ||
* @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/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); | ||
return $this->get('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); | ||
} | ||
|
||
/** | ||
* Make the authenticated user watch a repository | ||
* @link http://developer.github.com/v3/repos/watching/ | ||
* @link https://developer.github.com/v3/activity/watching/ | ||
* | ||
* @param string $username the user who owns the repo | ||
* @param string $repository the name of the repo | ||
* @return array | ||
*/ | ||
public function watch($username, $repository) | ||
{ | ||
return $this->put('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); | ||
return $this->put('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); | ||
} | ||
|
||
/** | ||
* Make the authenticated user unwatch a repository | ||
* @link http://developer.github.com/v3/repos/watching/ | ||
* @link https://developer.github.com/v3/activity/watching/ | ||
* | ||
* @param string $username the user who owns the repo | ||
* @param string $repository the name of the repo | ||
* @return array | ||
*/ | ||
public function unwatch($username, $repository) | ||
{ | ||
return $this->delete('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); | ||
return $this->delete('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); | ||
} | ||
} |
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 StarredTest 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\Starred'; | ||
} | ||
} |
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.
you should write it as
@deprecated Use watchers() instead