-
-
Notifications
You must be signed in to change notification settings - Fork 596
Add user memberships #283
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
cursedcoder
merged 2 commits into
KnpLabs:master
from
lucasmichot:feature/user-membership
Jul 2, 2015
Merged
Add user memberships #283
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| { | ||
| return $this->patch('user/memberships/orgs/'.rawurlencode($organization), array('state' => 'active')); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.