Skip to content

Missing toggle primary email visibility api endpoint #660

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
merged 1 commit into from
Dec 12, 2017
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
1 change: 1 addition & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ v3 APIs:
* [Authorizations](authorizations.md)
* [Commits](commits.md)
* Current User
* [Emails](currentuser/emails.md)
* [Public keys](currentuser/publickeys.md)
* [Memberships](currentuser/memberships.md)
* [Enterprise](enterprise.md)
Expand Down
35 changes: 35 additions & 0 deletions doc/currentuser/emails.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Current user / Emails API
[Back to the navigation](../README.md)

Wraps [GitHub User Emails API](https://developer.github.com/v3/users/emails/#emails).

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

### List email addresses for a user

```php
$emails = $client->currentUser()->emails()->all();
```

### List public email addresses for a user

```php
$emails = $client->currentUser()->emails()->allPublic();
```

### Add email address(es)

```php
$emails = $client->currentUser()->emails()->add(['email1', 'email2']);
```
### Delete email address(es)

```php
$client->currentUser()->emails()->remove(['email1', 'email2']);
```

### Toggle primary email visibility

```php
$primaryEmail = $client->currentUser()->emails()->toggleVisibility();
```
24 changes: 24 additions & 0 deletions lib/Github/Api/CurrentUser/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ public function all()
return $this->get('/user/emails');
}

/**
* List public email addresses for a user.
*
* @link https://developer.github.com/v3/users/emails/#list-public-email-addresses-for-a-user
*
* @return array
*/
public function allPublic()
{
return $this->get('/user/public_emails');
}

/**
* Adds one or more email for the authenticated user.
*
Expand Down Expand Up @@ -66,4 +78,16 @@ public function remove($emails)

return $this->delete('/user/emails', $emails);
}

/**
* Toggle primary email visibility
*
* @link https://developer.github.com/v3/users/emails/#toggle-primary-email-visibility
*
* @return array
*/
public function toggleVisibility()
{
return $this->patch('/user/email/visibility');
}
}
16 changes: 16 additions & 0 deletions test/Github/Tests/Api/CurrentUser/EmailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ public function shouldNotAddEmailsWhenAreNotPass()
$api->add(array());
}

/**
* @test
*/
public function shouldToggleVisibility()
{
$expectedValue = array('primary email info');

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

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

/**
* @return string
*/
Expand Down