From a405a26e71643a7eceb22a4e44722faf19de5af6 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 5 Mar 2017 15:44:11 +0100 Subject: [PATCH] Missing miscellaneous api endpoints --- doc/README.md | 4 ++ doc/miscellaneous/emojis.md | 8 +++ doc/miscellaneous/gitignore.md | 14 +++++ doc/miscellaneous/markdown.md | 14 +++++ lib/Github/Api/Miscellaneous/Emojis.php | 20 ++++++ lib/Github/Api/Miscellaneous/Gitignore.php | 34 +++++++++++ lib/Github/Client.php | 10 +++ .../Tests/Api/Miscellaneous/EmojisTest.php | 36 +++++++++++ .../Tests/Api/Miscellaneous/GitignoreTest.php | 61 +++++++++++++++++++ .../Api/{ => Miscellaneous}/MarkdownTest.php | 4 +- 10 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 doc/miscellaneous/emojis.md create mode 100644 doc/miscellaneous/gitignore.md create mode 100644 doc/miscellaneous/markdown.md create mode 100644 lib/Github/Api/Miscellaneous/Emojis.php create mode 100644 lib/Github/Api/Miscellaneous/Gitignore.php create mode 100644 test/Github/Tests/Api/Miscellaneous/EmojisTest.php create mode 100644 test/Github/Tests/Api/Miscellaneous/GitignoreTest.php rename test/Github/Tests/Api/{ => Miscellaneous}/MarkdownTest.php (96%) diff --git a/doc/README.md b/doc/README.md index 8cffeaaff07..04fcd7a3885 100644 --- a/doc/README.md +++ b/doc/README.md @@ -14,6 +14,10 @@ APIs: * [Issues](issues.md) * [Comments](issue/comments.md) * [Labels](issue/labels.md) +* Miscellaneous + * [Emojis](miscellaneous/emojis.md) + * [Gitignore](miscellaneous/gitignore.md) + * [Markdown](miscellaneous/markdown.md) * [Organization](organization.md) * [Members](organization/members.md) * [Teams](organization/teams.md) diff --git a/doc/miscellaneous/emojis.md b/doc/miscellaneous/emojis.md new file mode 100644 index 00000000000..0ba2045596e --- /dev/null +++ b/doc/miscellaneous/emojis.md @@ -0,0 +1,8 @@ +## Emojis API +[Back to the navigation](../README.md) + +### Lists all available emojis on GitHub. + +```php +$emojis = $client->api('emojis')->all(); +``` diff --git a/doc/miscellaneous/gitignore.md b/doc/miscellaneous/gitignore.md new file mode 100644 index 00000000000..181424f34ad --- /dev/null +++ b/doc/miscellaneous/gitignore.md @@ -0,0 +1,14 @@ +## Gitignore API +[Back to the navigation](../README.md) + +### Lists all available gitignore templates + +```php +$gitignoreTemplates = $client->api('gitignore')->all(); +``` + +### Get a single template + +```php +$gitignore = $client->api('gitignore')->show('C'); +``` diff --git a/doc/miscellaneous/markdown.md b/doc/miscellaneous/markdown.md new file mode 100644 index 00000000000..4f9ffecc179 --- /dev/null +++ b/doc/miscellaneous/markdown.md @@ -0,0 +1,14 @@ +## Markdown API +[Back to the navigation](../README.md) + +### Render an arbitrary Markdown document + +```php +$gitignoreTemplates = $client->api('markdown')->render('Hello world github/linguist#1 **cool**, and #1!', 'markdown'); +``` + +### Render a Markdown document in raw mode + +```php +$gitignore = $client->api('markdown')->renderRaw('path/to/file'); +``` diff --git a/lib/Github/Api/Miscellaneous/Emojis.php b/lib/Github/Api/Miscellaneous/Emojis.php new file mode 100644 index 00000000000..2a940f6dfb7 --- /dev/null +++ b/lib/Github/Api/Miscellaneous/Emojis.php @@ -0,0 +1,20 @@ +get('/emojis'); + } +} diff --git a/lib/Github/Api/Miscellaneous/Gitignore.php b/lib/Github/Api/Miscellaneous/Gitignore.php new file mode 100644 index 00000000000..c7306110ee5 --- /dev/null +++ b/lib/Github/Api/Miscellaneous/Gitignore.php @@ -0,0 +1,34 @@ +get('/gitignore/templates'); + } + + /** + * Get a single template. + * + * @link https://developer.github.com/v3/gitignore/#get-a-single-template + * + * @param string $template + * + * @return array + */ + public function show($template) + { + return $this->get('/gitignore/templates/' . rawurlencode($template)); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 062cf998c95..ad282661d12 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -23,10 +23,12 @@ * @method Api\CurrentUser me() * @method Api\Enterprise ent() * @method Api\Enterprise enterprise() + * @method Api\Miscellaneous\Emojis emojis() * @method Api\GitData git() * @method Api\GitData gitData() * @method Api\Gists gist() * @method Api\Gists gists() + * @method Api\Miscellaneous\Gitignore gitignore() * @method Api\Integrations integration() * @method Api\Integrations integrations() * @method Api\Issue issue() @@ -177,6 +179,10 @@ public function api($name) $api = new Api\Enterprise($this); break; + case 'emojis': + $api = new Api\Miscellaneous\Emojis($this); + break; + case 'git': case 'git_data': case 'gitData': @@ -188,6 +194,10 @@ public function api($name) $api = new Api\Gists($this); break; + case 'gitignore': + $api = new Api\Miscellaneous\Gitignore($this); + break; + case 'integration': case 'integrations': $api = new Api\Integrations($this); diff --git a/test/Github/Tests/Api/Miscellaneous/EmojisTest.php b/test/Github/Tests/Api/Miscellaneous/EmojisTest.php new file mode 100644 index 00000000000..63bac291e94 --- /dev/null +++ b/test/Github/Tests/Api/Miscellaneous/EmojisTest.php @@ -0,0 +1,36 @@ + 'https://github.global.ssl.fastly.net/images/icons/emoji/+1.png?v5', + '-1' => 'https://github.global.ssl.fastly.net/images/icons/emoji/-1.png?v5', + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/emojis') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @return string + */ + protected function getApiClass() + { + return Emojis::class; + } +} diff --git a/test/Github/Tests/Api/Miscellaneous/GitignoreTest.php b/test/Github/Tests/Api/Miscellaneous/GitignoreTest.php new file mode 100644 index 00000000000..9fbd0ef4fc4 --- /dev/null +++ b/test/Github/Tests/Api/Miscellaneous/GitignoreTest.php @@ -0,0 +1,61 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/gitignore/templates') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldGetTemplate() + { + $expectedArray = array( + 'name' => 'C', + 'source' => "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a" + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/gitignore/templates/C') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('C')); + } + + /** + * @return string + */ + protected function getApiClass() + { + return Gitignore::class; + } +} diff --git a/test/Github/Tests/Api/MarkdownTest.php b/test/Github/Tests/Api/Miscellaneous/MarkdownTest.php similarity index 96% rename from test/Github/Tests/Api/MarkdownTest.php rename to test/Github/Tests/Api/Miscellaneous/MarkdownTest.php index 296a2778575..14cb9bf439a 100644 --- a/test/Github/Tests/Api/MarkdownTest.php +++ b/test/Github/Tests/Api/Miscellaneous/MarkdownTest.php @@ -1,6 +1,8 @@