diff --git a/doc/users.md b/doc/users.md index b0cc072bbbf..57a7ff43178 100644 --- a/doc/users.md +++ b/doc/users.md @@ -12,6 +12,22 @@ $users = $client->api('user')->find('KnpLabs'); Returns an array of found users. +### Lists all users, in the order they signed up, since the last user you've seen + +```php +$users = $client->api('user')->all(135); +``` + +Returns an array of all users that registered after the user whose ID is 135. + +### Lists all users, in the order they signed up + +```php +$users = $client->api('user')->all(); +``` + +Returns an array of all users. + ### Get information about a user ```php diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 1681d8e5217..59940481ef5 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -24,6 +24,21 @@ public function find($keyword) return $this->get('legacy/user/search/'.rawurlencode($keyword)); } + /** + * Request all users: + * @link https://developer.github.com/v3/users/#get-all-users + * + * @param integer|null $id ID of the last user that you've seen + * @return array list of users found + */ + public function all($id = null) + { + if (!is_integer($id)) { + return $this->get('users'); + } + return $this->get('users?since=' . rawurldecode($id)); + } + /** * Get extended information about a user by its username * @link http://developer.github.com/v3/users/ diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 95dcb542e5f..05eb7061b0d 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -20,6 +20,25 @@ public function shouldShowUser() $this->assertEquals($expectedArray, $api->show('l3l0')); } + /** + * @test + */ + public function shouldGetAllUsers() + { + $expectedArray = array( + array('id' => 1, 'username' => 'l3l0'), + array('id' => 2, 'username' => 'l3l0test') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all()); + } + /** * @test */