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
36 changes: 36 additions & 0 deletions doc/currentuser/memberships.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Current user / Memberships API
[Back to the navigation](../README.md)

Wraps [GitHub Issue Comments API](https://developer.github.com/v3/orgs/members/#get-your-organization-membership).

### List your memberships

> Requires [authentication](../security.md).

```php
$memberships = $client->user()->memberships()->all();
```

Returns an array of your memberships in all organizations you are part of.

### Show an organization membership

> Requires [authentication](../security.md).

```php
$membership = $client->user()->memberships()->organization('KnpLabs');
```
* `KnpLabs` : the organization

Returns an array of one membership in a specific organization.

### Update an organization membership

> Requires [authentication](../security.md).

```php
$membership = $client->user()->memberships()->edit('KnpLabs');
```
* `KnpLabs` : the organization

Update your membership to an organization. The only possible action is to activate your membership.
9 changes: 9 additions & 0 deletions lib/Github/Api/CurrentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Github\Api\CurrentUser\DeployKeys;
use Github\Api\CurrentUser\Emails;
use Github\Api\CurrentUser\Followers;
use Github\Api\CurrentUser\Memberships;
use Github\Api\CurrentUser\Notifications;
use Github\Api\CurrentUser\Watchers;
use Github\Api\CurrentUser\Starring;
Expand Down Expand Up @@ -78,6 +79,14 @@ public function notifications()
return new Notifications($this->client);
}

/**
* @return Memberships
*/
public function memberships()
{
return new Memberships($this->client);
}

/**
* @link http://developer.github.com/v3/orgs/#list-user-organizations
*
Expand Down
44 changes: 44 additions & 0 deletions lib/Github/Api/CurrentUser/Memberships.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Github\Api\CurrentUser;

use Github\Api\AbstractApi;

class Memberships extends AbstractApi
{
/**
* List your organization memberships.
*
* @link https://developer.github.com/v3/orgs/members/#get-your-organization-membership
*
* @return array
*/
public function all()
{
return $this->get('user/memberships/orgs');
}

/**
* Get your organization membership.
*
* @link https://developer.github.com/v3/orgs/members/#get-your-organization-membership
*
* @return array
*/
public function organization($organization)
{
return $this->get('user/memberships/orgs/'.rawurlencode($organization));
}

/**
* Edit your organization membership
*
* @link https://developer.github.com/v3/orgs/members/#edit-your-organization-membership
*
* @return array
*/
public function edit($organization)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name is weird, because this method only allows to mark the membership as active.

{
return $this->patch('user/memberships/orgs/'.rawurlencode($organization), array('state' => 'active'));
}
}
91 changes: 91 additions & 0 deletions test/Github/Tests/Api/CurrentUser/MembershipsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Github\Tests\Api;

class MembershipsTest extends TestCase
{
/**
* @test
*/
public function shouldGetMemberships()
{
$expectedValue = array(
array(
'organization' => array(
'login' => 'octocat',
'id' => 1,
),
'user' => array(
'login' => 'defunkt',
'id' => 3,
),
),
array(
'organization' => array(
'login' => 'invitocat',
'id' => 2,
),
'user' => array(
'login' => 'defunkt',
'id' => 3,
),
),
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('user/memberships/orgs')
->will($this->returnValue($expectedValue));

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

/**
* @test
*/
public function shouldGetMembershipsForOrganization()
{
$expectedValue = array(
'organization' => array(
'login' => 'invitocat',
'id' => 2,
),
'user' => array(
'login' => 'defunkt',
'id' => 3,
),
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('user/memberships/orgs/invitocat')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->organization('invitocat'));
}

/**
* @test
*/
public function shouldEditMembershipsForOrganization()
{
$expectedValue = array(
'state' => 'active',
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('patch')
->with('user/memberships/orgs/invitocat')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->edit('invitocat'));
}

protected function getApiClass()
{
return 'Github\Api\CurrentUser\Memberships';
}
}