From 76c7dc744b2f2796bdbcd9a0328123c4c5d3814c Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 16 May 2014 00:36:35 -0400 Subject: [PATCH 1/4] List all GitHub users. --- doc/users.md | 16 ++++++++++++++++ lib/Github/Api/User.php | 15 +++++++++++++++ test/Github/Tests/Api/UserTest.php | 19 +++++++++++++++++++ 3 files changed, 50 insertions(+) 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 */ From 50800ab03fda62270c64d978a7b6542439f7de12 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 16 May 2014 09:06:39 -0400 Subject: [PATCH 2/4] Changed the URL so I can use my fork while they review my latest pull request --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 2ef7ee247d3..821614f2aa1 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "knplabs/github-api", + "name": "guillermoandrae/php-github-api", "type": "library", "description": "GitHub API v3 client", - "homepage": "https://github.com/KnpLabs/php-github-api", + "homepage": "https://github.com/guillermoandrae/php-github-api", "keywords": ["github", "gh", "api", "gist"], "license": "MIT", "authors": [ From 4124067c5478189e2f167b901243a92f8e4a9f06 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Sun, 18 May 2014 21:10:19 -0400 Subject: [PATCH 3/4] Fixed composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 821614f2aa1..3bd0f08715a 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "guillermoandrae/php-github-api", + "name": "knplabs/github-api", "type": "library", "description": "GitHub API v3 client", "homepage": "https://github.com/guillermoandrae/php-github-api", From b8072320d7b8cbef39de333d69a2a81c4b65b677 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Sun, 18 May 2014 21:14:43 -0400 Subject: [PATCH 4/4] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3bd0f08715a..2ef7ee247d3 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "knplabs/github-api", "type": "library", "description": "GitHub API v3 client", - "homepage": "https://github.com/guillermoandrae/php-github-api", + "homepage": "https://github.com/KnpLabs/php-github-api", "keywords": ["github", "gh", "api", "gist"], "license": "MIT", "authors": [