Skip to content

Missing miscellaneous api endpoints #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions doc/miscellaneous/emojis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Emojis API
[Back to the navigation](../README.md)

### Lists all available emojis on GitHub.

```php
$emojis = $client->api('emojis')->all();
```
14 changes: 14 additions & 0 deletions doc/miscellaneous/gitignore.md
Original file line number Diff line number Diff line change
@@ -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');
```
14 changes: 14 additions & 0 deletions doc/miscellaneous/markdown.md
Original file line number Diff line number Diff line change
@@ -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');
```
20 changes: 20 additions & 0 deletions lib/Github/Api/Miscellaneous/Emojis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Github\Api\Miscellaneous;

use Github\Api\AbstractApi;

class Emojis extends AbstractApi
{
/**
* Lists all the emojis available to use on GitHub.
*
* @link https://developer.github.com/v3/emojis/
*
* @return array
*/
public function all()
{
return $this->get('/emojis');
}
}
34 changes: 34 additions & 0 deletions lib/Github/Api/Miscellaneous/Gitignore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Github\Api\Miscellaneous;

use Github\Api\AbstractApi;

class Gitignore extends AbstractApi
{
/**
* List all templates available to pass as an option when creating a repository.
*
* @link https://developer.github.com/v3/gitignore/#listing-available-templates
*
* @return array
*/
public function all()
{
return $this->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));
}
}
10 changes: 10 additions & 0 deletions lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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':
Expand All @@ -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);
Expand Down
36 changes: 36 additions & 0 deletions test/Github/Tests/Api/Miscellaneous/EmojisTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Github\Tests\Api\Miscellaneous;

use Github\Api\Miscellaneous\Emojis;
use Github\Tests\Api\TestCase;

class EmojisTest extends TestCase
{
/**
* @test
*/
public function shouldGetAllEmojis()
{
$expectedArray = array(
'+1' => '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;
}
}
61 changes: 61 additions & 0 deletions test/Github/Tests/Api/Miscellaneous/GitignoreTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Github\Tests\Api\Miscellaneous;

use Github\Api\Miscellaneous\Emojis;
use Github\Api\Miscellaneous\Gitignore;
use Github\Tests\Api\TestCase;

class GitignoreTest extends TestCase
{
/**
* @test
*/
public function shouldGetAllTemplates()
{
$expectedArray = array(
'Actionscript',
'Android',
'AppceleratorTitanium',
'Autotools',
'Bancha',
'C',
'C++'
);

$api = $this->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;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Github\Tests\Api;
namespace Github\Tests\Api\Miscellaneous;

use Github\Tests\Api\TestCase;

class MarkdownTest extends TestCase
{
Expand Down