Skip to content

Commit 1c16592

Browse files
authored
feature KnpLabs#894 Show user by ID (genintho)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Revamp of KnpLabs#372 which was abandonned, and following the example of KnpLabs#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
1 parent 6a80368 commit 1c16592

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

doc/users.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ $user = $client->api('user')->show('KnpLabs');
3636

3737
Returns an array of information about the user.
3838

39+
40+
You can also use the User ID, but it will use an undocumented Github API
41+
42+
```php
43+
$user = $client->api('user')->showById(202732);
44+
```
45+
3946
### Update user information
4047

4148
> Requires [authentication](security.md).

lib/Github/Api/User.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ public function show($username)
5959
return $this->get('/users/'.rawurlencode($username));
6060
}
6161

62+
/**
63+
* Get extended information about a user by its id.
64+
* Note: at time of writing this is an undocumented feature but GitHub support have advised that it can be relied on.
65+
*
66+
* @link http://developer.github.com/v3/users/
67+
*
68+
* @param int $id the id of the user to show
69+
*
70+
* @return array information about the user
71+
*/
72+
public function showById($id)
73+
{
74+
return $this->get('/user/'.$id);
75+
}
76+
6277
/**
6378
* Get extended information about a user by its username.
6479
*

test/Github/Tests/Api/UserTest.php

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

23+
/**
24+
* @test
25+
*/
26+
public function shouldShowByIdUser()
27+
{
28+
$expectedArray = ['id' => 1, 'username' => 'l3l0'];
29+
30+
$api = $this->getApiMock();
31+
$api->expects($this->once())
32+
->method('get')
33+
->with('/user/1')
34+
->will($this->returnValue($expectedArray));
35+
36+
$this->assertEquals($expectedArray, $api->showById(1));
37+
}
38+
2339
/**
2440
* @test
2541
*/

0 commit comments

Comments
 (0)