Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions lib/Github/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
19 changes: 19 additions & 0 deletions test/Github/Tests/Api/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down