Skip to content

Commit

Permalink
feature #894 Show user by ID (genintho)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.x branch.

Discussion
----------

Revamp of #372 which was abandonned, and following the example of #579


As of 2020, gettting data by ID is still undocumented. I contacted Github support to make sure it could be relied on.


> <img width="691" alt="Screen Shot 2020-07-02 at 10 12 15 PM" src="https://user-images.githubusercontent.com/664857/86434021-2d17f700-bcb1-11ea-9f19-2008ce47412d.png">


------
I have been working with an old application and I have to deal with actions made by user that have changed their login since. The old login are now used by totally different people, which can be problematic.

Commits
-------

5ed46cc Update User.php
5703492 Add unit test
62b43ab Documentation
cdaad05 Remove usage of rawurlencode
  • Loading branch information
genintho authored Jul 4, 2020
1 parent 6a80368 commit 1c16592
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
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 @@ -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.
*
Expand Down
16 changes: 16 additions & 0 deletions test/Github/Tests/Api/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 1c16592

Please sign in to comment.