Skip to content
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
21 changes: 20 additions & 1 deletion doc/enterprise.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Provides information about a GitHub Enterprise installation. Wraps [GitHub Enterprise API](http://developer.github.com/v3/enterprise/).

### Configuration
In order to configure the client to point to a GitHub Enterprise installation, do the following:

```php
Expand All @@ -20,5 +21,23 @@ $client->setEnterpriseUrl('https://ghe.host');
$repositories = $client->api('user')->repositories('ornicar');
```

To use the Stats and License APIs, you will need to authenticate using a GitHub Enterprise site admin account.
### Authentication
The Admin Stats, License, and User Administration API endpoints are only accessible to GitHub Enterprise site administrators. The Management Console API endpoints are only accessible via the Management Console password.

### User Administration

#### Suspend a user (Enterprise only)

> Requires [authentication](security.md).

```php
$client->api('enterprise')->userAdmin()->suspend('ornicar');
```

#### Unsuspend a user (Enterprise only)

> Requires [authentication](security.md).

```php
$client->api('enterprise')->userAdmin()->unsuspend('ornicar');
```
9 changes: 9 additions & 0 deletions lib/Github/Api/Enterprise.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Github\Api\Enterprise\ManagementConsole;
use Github\Api\Enterprise\Stats;
use Github\Api\Enterprise\License;
use Github\Api\Enterprise\UserAdmin;

/**
* Getting information about a GitHub Enterprise instance.
Expand Down Expand Up @@ -38,4 +39,12 @@ public function console()
{
return new ManagementConsole($this->client);
}

/**
* @return UserAdmin
*/
public function userAdmin()
{
return new UserAdmin($this->client);
}
}
36 changes: 36 additions & 0 deletions lib/Github/Api/Enterprise/UserAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Github\Api\Enterprise;

use Github\Api\AbstractApi;

class UserAdmin extends AbstractApi
{
/**
* Suspend a user
*
* @link https://developer.github.com/v3/users/administration/#suspend-a-user
*
* @param string $username
*
* @return array
*/
public function suspend($username)
{
return $this->put('users/'.rawurldecode($username).'/suspended', array('Content-Length' => 0));
}

/**
* Unsuspend a user
*
* @link https://developer.github.com/v3/users/administration/#unsuspend-a-user
*
* @param string $username
*
* @return array
*/
public function unsuspend($username)
{
return $this->delete('users/'.rawurldecode($username).'/suspended');
}
}
43 changes: 43 additions & 0 deletions test/Github/Tests/Api/Enterprise/UserAdminTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace Github\Tests\Api\Enterprise;

use Github\Tests\Api\TestCase;

class UserAdminTest extends TestCase
{
/**
* @test
*/
public function shouldSuspendUser()
{
$expectedArray = array();

$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('users/l3l0/suspended')
->will($this->returnValue($expectedArray));
$this->assertEquals($expectedArray, $api->suspend('l3l0'));
}

/**
* @test
*/
public function shouldUnsuspendUser()
{
$expectedArray = array();

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('users/l3l0/suspended')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->unsuspend('l3l0'));
}

protected function getApiClass()
{
return 'Github\Api\Enterprise\UserAdmin';
}
}
10 changes: 10 additions & 0 deletions test/Github/Tests/Api/EnterpriseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public function shouldGetEnterpriseManagementConsoleApiObject()
$this->assertInstanceOf('Github\Api\Enterprise\ManagementConsole', $api->console());
}

/**
* @test
*/
public function shouldGetEnterpriseUserAdminApiObject()
{
$api = $this->getApiMock();

$this->assertInstanceOf('Github\Api\Enterprise\UserAdmin', $api->userAdmin());
}

protected function getApiClass()
{
return 'Github\Api\Enterprise';
Expand Down