Skip to content

Commit 76c7dc7

Browse files
List all GitHub users.
1 parent 7192587 commit 76c7dc7

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

doc/users.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ $users = $client->api('user')->find('KnpLabs');
1212

1313
Returns an array of found users.
1414

15+
### Lists all users, in the order they signed up, since the last user you've seen
16+
17+
```php
18+
$users = $client->api('user')->all(135);
19+
```
20+
21+
Returns an array of all users that registered after the user whose ID is 135.
22+
23+
### Lists all users, in the order they signed up
24+
25+
```php
26+
$users = $client->api('user')->all();
27+
```
28+
29+
Returns an array of all users.
30+
1531
### Get information about a user
1632

1733
```php

lib/Github/Api/User.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ public function find($keyword)
2424
return $this->get('legacy/user/search/'.rawurlencode($keyword));
2525
}
2626

27+
/**
28+
* Request all users:
29+
* @link https://developer.github.com/v3/users/#get-all-users
30+
*
31+
* @param integer|null $id ID of the last user that you've seen
32+
* @return array list of users found
33+
*/
34+
public function all($id = null)
35+
{
36+
if (!is_integer($id)) {
37+
return $this->get('users');
38+
}
39+
return $this->get('users?since=' . rawurldecode($id));
40+
}
41+
2742
/**
2843
* Get extended information about a user by its username
2944
* @link http://developer.github.com/v3/users/

test/Github/Tests/Api/UserTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ public function shouldShowUser()
2020
$this->assertEquals($expectedArray, $api->show('l3l0'));
2121
}
2222

23+
/**
24+
* @test
25+
*/
26+
public function shouldGetAllUsers()
27+
{
28+
$expectedArray = array(
29+
array('id' => 1, 'username' => 'l3l0'),
30+
array('id' => 2, 'username' => 'l3l0test')
31+
);
32+
33+
$api = $this->getApiMock();
34+
$api->expects($this->once())
35+
->method('get')
36+
->with('users')
37+
->will($this->returnValue($expectedArray));
38+
39+
$this->assertEquals($expectedArray, $api->all());
40+
}
41+
2342
/**
2443
* @test
2544
*/

0 commit comments

Comments
 (0)