diff --git a/doc/repos.md b/doc/repos.md index e8f35b9e586..c85366b0824 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -148,16 +148,18 @@ $client->api('repo')->collaborators()->remove('username', 'reponame', 'KnpLabs') Remove the 'username' collaborator from the 'reponame' repository. -### Watch and unwatch a repository +### Subscribe to and unsubscribe from a repository > Requires [authentication](security.md). ```php -$client->api('current_user')->watchers()->watch('ornicar', 'php-github-api'); -$client->api('current_user')->watchers()->unwatch('ornicar', 'php-github-api'); +$client->api('current_user')->watchers()->subscribe('ornicar', 'php-github-api'); +$client->api('current_user')->watchers()->unsubscribe('ornicar', 'php-github-api'); ``` -Watches or unwatches the 'php-github-api' repository owned by 'ornicar' and returns the repository. +Subscribes to, or unsubscribes from, the 'php-github-api' repository owned by 'ornicar' and returns the repository. + +These methods were previously called watch() and unwatch(); those methods are deprecated, but are still present in the library, and perform exactly as subscribe() and unsubscribe(), respectively. ### Fork a repository diff --git a/lib/Github/Api/CurrentUser/Watchers.php b/lib/Github/Api/CurrentUser/Watchers.php index 398ac58536a..4f99b705047 100644 --- a/lib/Github/Api/CurrentUser/Watchers.php +++ b/lib/Github/Api/CurrentUser/Watchers.php @@ -5,28 +5,28 @@ use Github\Api\AbstractApi; /** - * @link http://developer.github.com/v3/repos/watching/ + * @link https://developer.github.com/v3/activity/watching/ * @author Joseph Bielawski */ 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 @@ -34,12 +34,13 @@ public function all($page = 1) */ 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/ + * @deprecated use subscribe() + * @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 @@ -47,12 +48,13 @@ public function check($username, $repository) */ public function watch($username, $repository) { - return $this->put('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->subscribe($username, $repository); } /** * Make the authenticated user unwatch a repository - * @link http://developer.github.com/v3/repos/watching/ + * @deprecated use unsubscribe() + * @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 @@ -60,6 +62,32 @@ public function watch($username, $repository) */ public function unwatch($username, $repository) { - return $this->delete('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->unsubscribe($username, $repository); + } + + /** + * Make the authenticated user subscribe to a repository + * @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 subscribe($username, $repository) + { + return $this->put('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); + } + + /** + * Make the authenticated user unsubscribe from a repository + * @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 unsubscribe($username, $repository) + { + return $this->delete('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); } } diff --git a/test/Github/Tests/Api/CurrentUser/WatchersTest.php b/test/Github/Tests/Api/CurrentUser/WatchersTest.php index 15e009f6a08..f3e4582e8c2 100644 --- a/test/Github/Tests/Api/CurrentUser/WatchersTest.php +++ b/test/Github/Tests/Api/CurrentUser/WatchersTest.php @@ -19,7 +19,7 @@ public function shouldGetWatchers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/watched') + ->with('user/subscriptions') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all()); @@ -33,7 +33,7 @@ public function shouldCheckWatcher() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/watched/l3l0/test') + ->with('user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->check('l3l0', 'test')); @@ -47,7 +47,7 @@ public function shouldWatchUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('user/watched/l3l0/test') + ->with('user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->watch('l3l0', 'test')); @@ -61,12 +61,40 @@ public function shouldUnwatchUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('user/watched/l3l0/test') + ->with('user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->unwatch('l3l0', 'test')); } + /** + * @test + */ + public function shouldSubscribeUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('user/subscriptions/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->subscribe('l3l0', 'test')); + } + + /** + * @test + */ + public function shouldUnsubscribeUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('user/subscriptions/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->unsubscribe('l3l0', 'test')); + } + protected function getApiClass() { return 'Github\Api\CurrentUser\Watchers';