Skip to content

Commit 2709de9

Browse files
rasjradutopala
authored andcommitted
add keys endpoint "/keys/:id" (#162)
1 parent c3095ca commit 2709de9

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

lib/Gitlab/Api/Keys.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php namespace Gitlab\Api;
2+
3+
class Keys extends AbstractApi
4+
{
5+
/**
6+
* @param int $id
7+
* @return mixed
8+
*/
9+
public function show($id)
10+
{
11+
return $this->get('keys/'.$this->encodePath($id));
12+
}
13+
}

lib/Gitlab/Client.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* @property-read \Gitlab\Api\SystemHooks $hooks
3131
* @property-read \Gitlab\Api\SystemHooks $system_hooks
3232
* @property-read \Gitlab\Api\Users $users
33+
* @property-read \Gitlab\Api\Keys $keys
3334
*/
3435
class Client
3536
{
@@ -155,6 +156,10 @@ public function api($name)
155156
$api = new Api\Users($this);
156157
break;
157158

159+
case 'keys':
160+
$api = new Api\Keys($this);
161+
break;
162+
158163
default:
159164
throw new InvalidArgumentException('Invalid endpoint: "'.$name.'"');
160165

test/Gitlab/Tests/Api/KeysTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php namespace Gitlab\Tests\Api;
2+
3+
use Gitlab\Api\AbstractApi;
4+
5+
class KeysTest extends ApiTestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function shouldShowKey()
11+
{
12+
$expectedArray = array('id' => 1, 'title' => 'A key', 'key' => 'ssh-rsa key', 'created_at' => '2016-01-01T01:00:00.000Z');
13+
$api = $this->getApiMock();
14+
$api->expects($this->once())
15+
->method('get')
16+
->with('keys/1')
17+
->will($this->returnValue($expectedArray));
18+
19+
$this->assertEquals($expectedArray, $api->show(1));
20+
}
21+
22+
protected function getApiClass()
23+
{
24+
return 'Gitlab\Api\Keys';
25+
}
26+
}

0 commit comments

Comments
 (0)