From 5ed46ccfc2e9a09f50358f383e6671b6f569f072 Mon Sep 17 00:00:00 2001 From: Thomas Genin Date: Wed, 1 Jul 2020 19:12:39 -0700 Subject: [PATCH 1/4] Update User.php --- lib/Github/Api/User.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index c4414c56c75..dd86d0716ec 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -58,6 +58,21 @@ public function show($username) { return $this->get('/users/'.rawurlencode($username)); } + + /** + * Get extended information about a user by its id. + * Note: at time of writing this is an undocumented feature + * + * @link http://developer.github.com/v3/users/ + * + * @param int $id the id of the user to show + * + * @return array information about the user + */ + public function showById($id) + { + return $this->get('/user/'.rawurlencode($id)); + } /** * Get extended information about a user by its username. From 57034925e3d5da8e59db3f7a8cc14d74704a92dc Mon Sep 17 00:00:00 2001 From: Thomas Genin Date: Thu, 2 Jul 2020 22:05:48 -0700 Subject: [PATCH 2/4] Add unit test --- test/Github/Tests/Api/UserTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 0c9eea62b9d..795c48fa992 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -20,6 +20,22 @@ public function shouldShowUser() $this->assertEquals($expectedArray, $api->show('l3l0')); } + /** + * @test + */ + public function shouldShowByIdUser() + { + $expectedArray = ['id' => 1, 'username' => 'l3l0']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/user/1') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->showById(1)); + } + /** * @test */ From 62b43ab53ec6b684f2c715d64e018d30f743b460 Mon Sep 17 00:00:00 2001 From: Thomas Genin Date: Thu, 2 Jul 2020 22:09:24 -0700 Subject: [PATCH 3/4] Documentation --- doc/users.md | 7 +++++++ lib/Github/Api/User.php | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/users.md b/doc/users.md index b6c36309d70..3bc20c39bc3 100644 --- a/doc/users.md +++ b/doc/users.md @@ -36,6 +36,13 @@ $user = $client->api('user')->show('KnpLabs'); Returns an array of information about the user. + +You can also use the User ID, but it will use an undocumented Github API + +```php +$user = $client->api('user')->showById(202732); +``` + ### Update user information > Requires [authentication](security.md). diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index dd86d0716ec..058886bd837 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -58,10 +58,10 @@ public function show($username) { return $this->get('/users/'.rawurlencode($username)); } - + /** * Get extended information about a user by its id. - * Note: at time of writing this is an undocumented feature + * Note: at time of writing this is an undocumented feature but GitHub support have advised that it can be relied on. * * @link http://developer.github.com/v3/users/ * From cdaad05d68adfab5c62a160d54ca5b169e92a7ea Mon Sep 17 00:00:00 2001 From: Thomas Genin Date: Fri, 3 Jul 2020 15:51:44 -0700 Subject: [PATCH 4/4] Remove usage of rawurlencode --- lib/Github/Api/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 058886bd837..6cfcd238143 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -71,7 +71,7 @@ public function show($username) */ public function showById($id) { - return $this->get('/user/'.rawurlencode($id)); + return $this->get('/user/'.$id); } /**