From 57e674cf6bd653288c5bf0dc27b0319425866e42 Mon Sep 17 00:00:00 2001 From: Sean Hellwig Date: Fri, 21 Feb 2014 16:31:29 -0800 Subject: [PATCH] Update User API to include /users/:user/starred --- doc/users.md | 6 ++++++ lib/Github/Api/User.php | 15 +++++++++++++ test/Github/Tests/Functional/UserTest.php | 26 +++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/doc/users.md b/doc/users.md index b0cc072bbbf..bc3c2579b45 100644 --- a/doc/users.md +++ b/doc/users.md @@ -97,6 +97,12 @@ Returns an array of followed users. $users = $client->api('user')->watched('ornicar'); ``` +### Get repos that a specific user has starred + +```php +$users = $client->api('user')->starred('ornicar'); +``` + For authenticated user use. > Requires [authentication](security.md). diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 1681d8e5217..e832bd84710 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -72,6 +72,21 @@ public function watched($username) return $this->get('users/'.rawurlencode($username).'/watched'); } + /** + * Request starred repositories that a specific user has starred + * @link http://developer.github.com/v3/activity/starring/ + * + * @param string $username the username + * @param int $page the page number of the paginated result set + * @return array list of starred repositories + */ + public function starred($username, $page = 1) + { + return $this->get('users/'.rawurlencode($username).'/starred', array( + 'page' => $page + )); + } + /** * Request the repository that a specific user is watching * @link http://developer.github.com/v3/activity/watching/ diff --git a/test/Github/Tests/Functional/UserTest.php b/test/Github/Tests/Functional/UserTest.php index 8cef6d7a88a..3366ab96d02 100644 --- a/test/Github/Tests/Functional/UserTest.php +++ b/test/Github/Tests/Functional/UserTest.php @@ -110,4 +110,30 @@ public function shouldGetReposBeingWatched() $this->assertArrayHasKey('git_url', $repo); $this->assertArrayHasKey('svn_url', $repo); } + + /** + * @test + */ + public function shouldGetReposBeingStarred() + { + $username = 'l3l0'; + + $repos = $this->client->api('user')->starred($username); + $repo = array_pop($repos); + + $this->assertArrayHasKey('id', $repo); + $this->assertArrayHasKey('name', $repo); + $this->assertArrayHasKey('description', $repo); + $this->assertArrayHasKey('url', $repo); + $this->assertArrayHasKey('has_wiki', $repo); + $this->assertArrayHasKey('has_issues', $repo); + $this->assertArrayHasKey('forks', $repo); + $this->assertArrayHasKey('updated_at', $repo); + $this->assertArrayHasKey('created_at', $repo); + $this->assertArrayHasKey('pushed_at', $repo); + $this->assertArrayHasKey('open_issues', $repo); + $this->assertArrayHasKey('ssh_url', $repo); + $this->assertArrayHasKey('git_url', $repo); + $this->assertArrayHasKey('svn_url', $repo); + } }