diff --git a/doc/README.md b/doc/README.md index ebc64840d37..d6ab57637dd 100644 --- a/doc/README.md +++ b/doc/README.md @@ -2,6 +2,7 @@ Navigation ========== APIs: +* [Applications](apps.md) * [Authorizations](authorizations.md) * [Commits](commits.md) * Current User @@ -10,7 +11,6 @@ APIs: * [Enterprise](enterprise.md) * [Gists](gists.md) * [Comments](gists/comments.md) -* [Integrations](integrations.md) * [Issues](issues.md) * [Assignees](issue/assignees.md) * [Comments](issue/comments.md) diff --git a/doc/integrations.md b/doc/apps.md similarity index 59% rename from doc/integrations.md rename to doc/apps.md index 6e7413dde1d..7cc9b45a17e 100644 --- a/doc/integrations.md +++ b/doc/apps.md @@ -1,24 +1,24 @@ -## Instegrations API +## Applications API [Back to the navigation](README.md) -Wraps [GitHub Integrations API](http://developer.github.com/v3/integrations/). +Wraps [GitHub Applications API](http://developer.github.com/v3/apps/). ### Create a new installation token For the installation id 123 use the following: ```php -$token = $client->api('integrations')->createInstallationToken(123); +$token = $client->api('apps')->createInstallationToken(123); ``` To create an access token on behalf of a user with id 456 use: ```php -$token = $client->api('integrations')->createInstallationToken(123, 456); +$token = $client->api('apps')->createInstallationToken(123, 456); ``` ### Find all installations -Find all installations for the authenticated integration. +Find all installations for the authenticated application. ```php -$installations = $client->api('integrations')->findInstallations(); +$installations = $client->api('apps')->findInstallations(); ``` ### Find installations for a user @@ -31,7 +31,7 @@ $installations = $client->api('current_user')->installations(); List repositories that are accessible to the authenticated installation. ```php -$repositories = $client->api('integrations')->listRepositories(456); +$repositories = $client->api('apps')->listRepositories(456); ``` ### List repositories for a given installation and user @@ -43,11 +43,11 @@ $repositories = $client->api('current_user')->repositoriesByInstallation(456); ### Add repository to installation Add a single repository to an installation. ```php -$client->api('integrations')->addRepository(123); +$client->api('apps')->addRepository(123); ``` ### Remove repository from installation Remove a single repository from an installation. ```php -$client->api('integrations')->removeRepository(123); +$client->api('apps')->removeRepository(123); ``` diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php new file mode 100644 index 00000000000..dc11ff0b3cf --- /dev/null +++ b/lib/Github/Api/Apps.php @@ -0,0 +1,90 @@ + + */ +class Apps extends AbstractApi +{ + /** + * Create an access token for an installation + * + * @param int $installationId An integration installation id + * @param int $userId An optional user id on behalf of whom the + * token will be requested + * + * @return array token and token metadata + */ + public function createInstallationToken($installationId, $userId = null) + { + $parameters = array(); + if ($userId) { + $parameters['user_id'] = $userId; + } + + return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); + } + + /** + * Find all installations for the authenticated application. + * + * @link https://developer.github.com/v3/apps/#find-installations + * + * @return array + */ + public function findInstallations() + { + return $this->get('/app/installations'); + } + + /** + * List repositories that are accessible to the authenticated installation. + * + * @link https://developer.github.com/v3/apps/installations/#list-repositories + * + * @param int $userId + * + * @return array + */ + public function listRepositories($userId = null) + { + $parameters = array(); + if ($userId) { + $parameters['user_id'] = $userId; + } + + return $this->get('/installation/repositories', $parameters); + } + + /** + * Add a single repository to an installation. + * + * @link https://developer.github.com/v3/apps/installations/#add-repository-to-installation + * + * @param int $installationId + * @param int $repositoryId + * + * @return array + */ + public function addRepository($installationId, $repositoryId) + { + return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); + } + + /** + * Remove a single repository from an installation. + * + * @link https://developer.github.com/v3/apps/installations/#remove-repository-from-installation + * + * @param int $installationId + * @param int $repositoryId + * + * @return array + */ + public function removeRepository($installationId, $repositoryId) + { + return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); + } +} diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php index 9cb801d699a..ef6ed557d82 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Integrations.php @@ -2,107 +2,25 @@ namespace Github\Api; -use Github\Api\AcceptHeaderTrait; +@trigger_error('The '.__NAMESPACE__.'\Integrations class is deprecated. Use the '.__NAMESPACE__.'\Apps class instead.', E_USER_DEPRECATED); /** - * @link https://developer.github.com/v3/integrations/ + * @deprecated Use the Apps class + * @link https://developer.github.com/v3/apps/ * @author Nils Adermann */ -class Integrations extends AbstractApi +class Integrations extends Apps { - use AcceptHeaderTrait; - /** - * Configure the accept header for Early Access to the integrations api + * @deprecated + * Configure the accept header for Early Access to the integrations api (DEPRECATED) * - * @see https://developer.github.com/v3/integrations/ + * @see https://developer.github.com/v3/apps/ * * @return self */ public function configure() { - $this->acceptHeaderValue = 'application/vnd.github.machine-man-preview+json'; - return $this; } - - /** - * Create an access token for an installation - * - * @param int $installationId An integration installation id - * @param int $userId An optional user id on behalf of whom the - * token will be requested - * - * @return array token and token metadata - */ - public function createInstallationToken($installationId, $userId = null) - { - $parameters = array(); - if ($userId) { - $parameters['user_id'] = $userId; - } - - return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); - } - - /** - * Find all installations for the authenticated integration. - * - * @link https://developer.github.com/v3/integrations/#find-installations - * - * @return array - */ - public function findInstallations() - { - return $this->get('/integration/installations'); - } - - /** - * List repositories that are accessible to the authenticated installation. - * - * @link https://developer.github.com/v3/integrations/installations/#list-repositories - * - * @param int $userId - * - * @return array - */ - public function listRepositories($userId = null) - { - $parameters = array(); - if ($userId) { - $parameters['user_id'] = $userId; - } - - return $this->get('/installation/repositories', $parameters); - } - - /** - * Add a single repository to an installation. - * - * @link https://developer.github.com/v3/integrations/installations/#add-repository-to-installation - * - * @param int $installationId - * @param int $repositoryId - * - * @return array - */ - public function addRepository($installationId, $repositoryId) - { - return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); - } - - /** - * Remove a single repository from an installation. - * - * @link https://developer.github.com/v3/integrations/installations/#remove-repository-from-installation - * - * @param int $installationId - * @param int $repositoryId - * - * @return array - */ - public function removeRepository($installationId, $repositoryId) - { - return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); - } } diff --git a/lib/Github/Client.php b/lib/Github/Client.php index ad282661d12..b9f6620e8a5 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -29,8 +29,9 @@ * @method Api\Gists gist() * @method Api\Gists gists() * @method Api\Miscellaneous\Gitignore gitignore() - * @method Api\Integrations integration() - * @method Api\Integrations integrations() + * @method Api\Integrations integration() (deprecated) + * @method Api\Integrations integrations() (deprecated) + * @method Api\Apps apps() * @method Api\Issue issue() * @method Api\Issue issues() * @method Api\Markdown markdown() @@ -202,6 +203,9 @@ public function api($name) case 'integrations': $api = new Api\Integrations($this); break; + case 'apps': + $api = new Api\Apps($this); + break; case 'issue': case 'issues': diff --git a/test/Github/Tests/Api/IntegrationTest.php b/test/Github/Tests/Api/AppTest.php similarity index 88% rename from test/Github/Tests/Api/IntegrationTest.php rename to test/Github/Tests/Api/AppTest.php index 2ab5dc3be62..51679175725 100644 --- a/test/Github/Tests/Api/IntegrationTest.php +++ b/test/Github/Tests/Api/AppTest.php @@ -2,19 +2,19 @@ namespace Github\Tests\Api; -class IntegrationTest extends TestCase +class AppTest extends TestCase { /** * @test */ - public function shouldFindRepositoriesForIntegration() + public function shouldFindRepositoriesForApplication() { $result = ['installation1', 'installation2']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/integration/installations') + ->with('/app/installations') ->willReturn($result); $this->assertEquals($result, $api->findInstallations()); @@ -68,6 +68,6 @@ public function shouldRemoveRepositoryToInstallation() */ protected function getApiClass() { - return \Github\Api\Integrations::class; + return \Github\Api\Apps::class; } }