Skip to content

Commit adf8914

Browse files
acrobatNyholm
authored andcommitted
Missing miscellaneous api endpoints (KnpLabs#534)
1 parent 38301cc commit adf8914

File tree

10 files changed

+204
-1
lines changed

10 files changed

+204
-1
lines changed

doc/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ APIs:
1414
* [Issues](issues.md)
1515
* [Comments](issue/comments.md)
1616
* [Labels](issue/labels.md)
17+
* Miscellaneous
18+
* [Emojis](miscellaneous/emojis.md)
19+
* [Gitignore](miscellaneous/gitignore.md)
20+
* [Markdown](miscellaneous/markdown.md)
1721
* [Organization](organization.md)
1822
* [Members](organization/members.md)
1923
* [Teams](organization/teams.md)

doc/miscellaneous/emojis.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Emojis API
2+
[Back to the navigation](../README.md)
3+
4+
### Lists all available emojis on GitHub.
5+
6+
```php
7+
$emojis = $client->api('emojis')->all();
8+
```

doc/miscellaneous/gitignore.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Gitignore API
2+
[Back to the navigation](../README.md)
3+
4+
### Lists all available gitignore templates
5+
6+
```php
7+
$gitignoreTemplates = $client->api('gitignore')->all();
8+
```
9+
10+
### Get a single template
11+
12+
```php
13+
$gitignore = $client->api('gitignore')->show('C');
14+
```

doc/miscellaneous/markdown.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Markdown API
2+
[Back to the navigation](../README.md)
3+
4+
### Render an arbitrary Markdown document
5+
6+
```php
7+
$gitignoreTemplates = $client->api('markdown')->render('Hello world github/linguist#1 **cool**, and #1!', 'markdown');
8+
```
9+
10+
### Render a Markdown document in raw mode
11+
12+
```php
13+
$gitignore = $client->api('markdown')->renderRaw('path/to/file');
14+
```
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Github\Api\Miscellaneous;
4+
5+
use Github\Api\AbstractApi;
6+
7+
class Emojis extends AbstractApi
8+
{
9+
/**
10+
* Lists all the emojis available to use on GitHub.
11+
*
12+
* @link https://developer.github.com/v3/emojis/
13+
*
14+
* @return array
15+
*/
16+
public function all()
17+
{
18+
return $this->get('/emojis');
19+
}
20+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Github\Api\Miscellaneous;
4+
5+
use Github\Api\AbstractApi;
6+
7+
class Gitignore extends AbstractApi
8+
{
9+
/**
10+
* List all templates available to pass as an option when creating a repository.
11+
*
12+
* @link https://developer.github.com/v3/gitignore/#listing-available-templates
13+
*
14+
* @return array
15+
*/
16+
public function all()
17+
{
18+
return $this->get('/gitignore/templates');
19+
}
20+
21+
/**
22+
* Get a single template.
23+
*
24+
* @link https://developer.github.com/v3/gitignore/#get-a-single-template
25+
*
26+
* @param string $template
27+
*
28+
* @return array
29+
*/
30+
public function show($template)
31+
{
32+
return $this->get('/gitignore/templates/' . rawurlencode($template));
33+
}
34+
}

lib/Github/Client.php

+10
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
* @method Api\CurrentUser me()
2424
* @method Api\Enterprise ent()
2525
* @method Api\Enterprise enterprise()
26+
* @method Api\Miscellaneous\Emojis emojis()
2627
* @method Api\GitData git()
2728
* @method Api\GitData gitData()
2829
* @method Api\Gists gist()
2930
* @method Api\Gists gists()
31+
* @method Api\Miscellaneous\Gitignore gitignore()
3032
* @method Api\Integrations integration()
3133
* @method Api\Integrations integrations()
3234
* @method Api\Issue issue()
@@ -177,6 +179,10 @@ public function api($name)
177179
$api = new Api\Enterprise($this);
178180
break;
179181

182+
case 'emojis':
183+
$api = new Api\Miscellaneous\Emojis($this);
184+
break;
185+
180186
case 'git':
181187
case 'git_data':
182188
case 'gitData':
@@ -188,6 +194,10 @@ public function api($name)
188194
$api = new Api\Gists($this);
189195
break;
190196

197+
case 'gitignore':
198+
$api = new Api\Miscellaneous\Gitignore($this);
199+
break;
200+
191201
case 'integration':
192202
case 'integrations':
193203
$api = new Api\Integrations($this);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Miscellaneous;
4+
5+
use Github\Api\Miscellaneous\Emojis;
6+
use Github\Tests\Api\TestCase;
7+
8+
class EmojisTest extends TestCase
9+
{
10+
/**
11+
* @test
12+
*/
13+
public function shouldGetAllEmojis()
14+
{
15+
$expectedArray = array(
16+
'+1' => 'https://github.global.ssl.fastly.net/images/icons/emoji/+1.png?v5',
17+
'-1' => 'https://github.global.ssl.fastly.net/images/icons/emoji/-1.png?v5',
18+
);
19+
20+
$api = $this->getApiMock();
21+
$api->expects($this->once())
22+
->method('get')
23+
->with('/emojis')
24+
->will($this->returnValue($expectedArray));
25+
26+
$this->assertEquals($expectedArray, $api->all());
27+
}
28+
29+
/**
30+
* @return string
31+
*/
32+
protected function getApiClass()
33+
{
34+
return Emojis::class;
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Miscellaneous;
4+
5+
use Github\Api\Miscellaneous\Emojis;
6+
use Github\Api\Miscellaneous\Gitignore;
7+
use Github\Tests\Api\TestCase;
8+
9+
class GitignoreTest extends TestCase
10+
{
11+
/**
12+
* @test
13+
*/
14+
public function shouldGetAllTemplates()
15+
{
16+
$expectedArray = array(
17+
'Actionscript',
18+
'Android',
19+
'AppceleratorTitanium',
20+
'Autotools',
21+
'Bancha',
22+
'C',
23+
'C++'
24+
);
25+
26+
$api = $this->getApiMock();
27+
$api->expects($this->once())
28+
->method('get')
29+
->with('/gitignore/templates')
30+
->will($this->returnValue($expectedArray));
31+
32+
$this->assertEquals($expectedArray, $api->all());
33+
}
34+
35+
/**
36+
* @test
37+
*/
38+
public function shouldGetTemplate()
39+
{
40+
$expectedArray = array(
41+
'name' => 'C',
42+
'source' => "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a"
43+
);
44+
45+
$api = $this->getApiMock();
46+
$api->expects($this->once())
47+
->method('get')
48+
->with('/gitignore/templates/C')
49+
->will($this->returnValue($expectedArray));
50+
51+
$this->assertEquals($expectedArray, $api->show('C'));
52+
}
53+
54+
/**
55+
* @return string
56+
*/
57+
protected function getApiClass()
58+
{
59+
return Gitignore::class;
60+
}
61+
}

test/Github/Tests/Api/MarkdownTest.php renamed to test/Github/Tests/Api/Miscellaneous/MarkdownTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Github\Tests\Api;
3+
namespace Github\Tests\Api\Miscellaneous;
4+
5+
use Github\Tests\Api\TestCase;
46

57
class MarkdownTest extends TestCase
68
{

0 commit comments

Comments
 (0)