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 c4414c56c75..6cfcd238143 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -59,6 +59,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 but GitHub support have advised that it can be relied on. + * + * @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/'.$id); + } + /** * Get extended information about a user by its username. * 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 */