Skip to content

Added support for Miscellaneous Licenses #744

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 2 commits into from
Sep 16, 2018
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
1 change: 1 addition & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ v3 APIs:
* [Code of conduct](miscellaneous/codeofconduct.md)
* [Emojis](miscellaneous/emojis.md)
* [Gitignore](miscellaneous/gitignore.md)
* [Licenses](miscellaneous/licenses.md)
* [Markdown](miscellaneous/markdown.md)
* [Organization](organization.md)
* [Members](organization/members.md)
Expand Down
14 changes: 14 additions & 0 deletions doc/miscellaneous/licenses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Licenses API
[Back to the navigation](../README.md)

### Lists all licenses.

```php
$licenses = $client->api('licenses')->all();
```

### Get a license.

```php
$license = $client->api('licenses')->show('gpl-2.0');
```
34 changes: 34 additions & 0 deletions lib/Github/Api/Miscellaneous/Licenses.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 Licenses extends AbstractApi
{
/**
* Lists all the licenses available on GitHub.
*
* @link https://developer.github.com/v3/licenses/
*
* @return array
*/
public function all()
{
return $this->get('/licenses');
}

/**
* Get an individual license by its license key.
*
* @link https://developer.github.com/v3/licenses/#get-an-individual-license
*
* @param string $license
*
* @return array
*/
public function show($license)
{
return $this->get('/licenses/'.rawurlencode($license));
}
}
5 changes: 5 additions & 0 deletions lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @method Api\Enterprise enterprise()
* @method Api\Miscellaneous\CodeOfConduct codeOfConduct()
* @method Api\Miscellaneous\Emojis emojis()
* @method Api\Miscellaneous\Licenses licenses()
* @method Api\GitData git()
* @method Api\GitData gitData()
* @method Api\Gists gist()
Expand Down Expand Up @@ -221,6 +222,10 @@ public function api($name)
$api = new Api\Markdown($this);
break;

case 'licenses':
$api = new Api\Miscellaneous\Licenses($this);
break;

case 'notification':
case 'notifications':
$api = new Api\Notification($this);
Expand Down
54 changes: 54 additions & 0 deletions test/Github/Tests/Api/Miscellaneous/LicensesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Github\Tests\Api\Miscellaneous;

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

class LicensesTest extends TestCase
{
/**
* @test
*/
public function shouldGetAllLicenses()
{
$expectedArray = [
['key' => 'mit'],
['key' => 'apache-2.0'],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/licenses')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->all());
}

/**
* @test
*/
public function shouldGetSingleLicenses()
{
$expectedArray = [
'key' => 'gpl-2.0',
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/licenses/gpl-2.0')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->show('gpl-2.0'));
}

/**
* @return string
*/
protected function getApiClass()
{
return Licenses::class;
}
}