diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 32eba7d2d87..46dd975ca0a 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -4,6 +4,7 @@ use Github\Api\Organization\Hooks; use Github\Api\Organization\Members; +use Github\Api\Organization\OutsideCollaborators; use Github\Api\Organization\Teams; /** @@ -100,6 +101,14 @@ public function teams() return new Teams($this->client); } + /** + * @return OutsideCollaborators + */ + public function outsideCollaborators() + { + return new OutsideCollaborators($this->client); + } + /** * @link http://developer.github.com/v3/issues/#list-issues * diff --git a/lib/Github/Api/Organization/OutsideCollaborators.php b/lib/Github/Api/Organization/OutsideCollaborators.php new file mode 100644 index 00000000000..958100a56ee --- /dev/null +++ b/lib/Github/Api/Organization/OutsideCollaborators.php @@ -0,0 +1,52 @@ + + */ +class OutsideCollaborators extends AbstractApi +{ + /** + * @link https://developer.github.com/v3/orgs/outside_collaborators/#list-outside-collaborators-for-an-organization + * + * @param string $organization the organization + * @param array $params + * + * @return array the organizations + */ + public function all($organization, array $params = []) + { + return $this->get('/orgs/'.rawurlencode($organization).'/outside_collaborators', $params); + } + + /** + * @link https://developer.github.com/v3/orgs/outside_collaborators/#convert-an-organization-member-to-outside-collaborator + * + * @param string $organization the organization + * @param string $username the github username + * + * @return array + */ + public function convert($organization, $username) + { + return $this->put('/orgs/'.rawurlencode($organization).'/outside_collaborators/'.rawurldecode($username)); + } + + /** + * @link https://developer.github.com/v3/orgs/outside_collaborators/#remove-outside-collaborator-from-an-organization + * + * @param string $organization the organization + * @param string $username the username + * + * @return array + */ + public function remove($organization, $username) + { + return $this->delete('/orgs/'.rawurlencode($organization).'/outside_collaborators/'.rawurldecode($username)); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 86ed95c19d8..a6170570032 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -19,49 +19,50 @@ /** * Simple yet very cool PHP GitHub client. * - * @method Api\CurrentUser currentUser() - * @method Api\CurrentUser me() - * @method Api\Enterprise ent() - * @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() - * @method Api\Gists gists() - * @method Api\Miscellaneous\Gitignore gitignore() - * @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() - * @method Api\Notification notification() - * @method Api\Notification notifications() - * @method Api\Organization organization() - * @method Api\Organization organizations() - * @method Api\Organization\Projects orgProject() - * @method Api\Organization\Projects orgProjects() - * @method Api\Organization\Projects organizationProject() - * @method Api\Organization\Projects organizationProjects() - * @method Api\PullRequest pr() - * @method Api\PullRequest pullRequest() - * @method Api\PullRequest pullRequests() - * @method Api\RateLimit rateLimit() - * @method Api\Repo repo() - * @method Api\Repo repos() - * @method Api\Repo repository() - * @method Api\Repo repositories() - * @method Api\Search search() - * @method Api\Organization\Teams team() - * @method Api\Organization\Teams teams() - * @method Api\User user() - * @method Api\User users() - * @method Api\Authorizations authorization() - * @method Api\Authorizations authorizations() - * @method Api\Meta meta() - * @method Api\GraphQL graphql() + * @method Api\CurrentUser currentUser() + * @method Api\CurrentUser me() + * @method Api\Enterprise ent() + * @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() + * @method Api\Gists gists() + * @method Api\Miscellaneous\Gitignore gitignore() + * @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() + * @method Api\Notification notification() + * @method Api\Notification notifications() + * @method Api\Organization organization() + * @method Api\Organization organizations() + * @method Api\Organization\Projects orgProject() + * @method Api\Organization\Projects orgProjects() + * @method Api\Organization\Projects organizationProject() + * @method Api\Organization\Projects organizationProjects() + * @method Api\Organization\OutsideCollaborators outsideCollaborators() + * @method Api\PullRequest pr() + * @method Api\PullRequest pullRequest() + * @method Api\PullRequest pullRequests() + * @method Api\RateLimit rateLimit() + * @method Api\Repo repo() + * @method Api\Repo repos() + * @method Api\Repo repository() + * @method Api\Repo repositories() + * @method Api\Search search() + * @method Api\Organization\Teams team() + * @method Api\Organization\Teams teams() + * @method Api\User user() + * @method Api\User users() + * @method Api\Authorizations authorization() + * @method Api\Authorizations authorizations() + * @method Api\Meta meta() + * @method Api\GraphQL graphql() * * @author Joseph Bielawski * @@ -318,6 +319,11 @@ public function api($name) $api = new Api\GraphQL($this); break; + case 'outsideCollaborators': + case 'outside_collaborators': + $api = new Api\Organization\OutsideCollaborators($this); + break; + default: throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); } diff --git a/test/Github/Tests/Api/Organization/OutsideCollaboratorsTest.php b/test/Github/Tests/Api/Organization/OutsideCollaboratorsTest.php new file mode 100644 index 00000000000..eb74b266c09 --- /dev/null +++ b/test/Github/Tests/Api/Organization/OutsideCollaboratorsTest.php @@ -0,0 +1,66 @@ + 'KnpLabs']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/outside_collaborators') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs')); + } + + /** + * @test + */ + public function shouldConvertAnOrganizationMemberToOutsideCollaborator() + { + $expectedValue = 'expectedResponse'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/outside_collaborators/username') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->convert('KnpLabs', 'username')); + } + + /** + * @test + */ + public function shouldRemoveAnOutsideCollaboratorFromAnOrganization() + { + $expectedValue = 'expectedResponse'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/orgs/KnpLabs/outside_collaborators/username') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'username')); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Organization\OutsideCollaborators::class; + } +} diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 550bc8169f6..25b559329da 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -209,6 +209,9 @@ public function getApiClassesProvider() ['authorizations', Api\Authorizations::class], ['meta', Api\Meta::class], + + ['outsideCollaborators', Api\Organization\OutsideCollaborators::class], + ['outside_collaborators', Api\Organization\OutsideCollaborators::class], ]; }