From 3c0ad60503a5d285a7547fde6bd79498f056c3f5 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 10 Dec 2017 19:26:01 +0100 Subject: [PATCH] Missing toggle primary email visibility api endpoint --- doc/README.md | 1 + doc/currentuser/emails.md | 35 +++++++++++++++++++ lib/Github/Api/CurrentUser/Emails.php | 24 +++++++++++++ .../Tests/Api/CurrentUser/EmailsTest.php | 16 +++++++++ 4 files changed, 76 insertions(+) create mode 100644 doc/currentuser/emails.md diff --git a/doc/README.md b/doc/README.md index 00faee5a846..f4e1d3421cb 100644 --- a/doc/README.md +++ b/doc/README.md @@ -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) diff --git a/doc/currentuser/emails.md b/doc/currentuser/emails.md new file mode 100644 index 00000000000..ef099f468d5 --- /dev/null +++ b/doc/currentuser/emails.md @@ -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(); +``` diff --git a/lib/Github/Api/CurrentUser/Emails.php b/lib/Github/Api/CurrentUser/Emails.php index 8155301ed5d..98dae634efb 100644 --- a/lib/Github/Api/CurrentUser/Emails.php +++ b/lib/Github/Api/CurrentUser/Emails.php @@ -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. * @@ -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'); + } } diff --git a/test/Github/Tests/Api/CurrentUser/EmailsTest.php b/test/Github/Tests/Api/CurrentUser/EmailsTest.php index cba52d12be3..cd15eb2c2ee 100644 --- a/test/Github/Tests/Api/CurrentUser/EmailsTest.php +++ b/test/Github/Tests/Api/CurrentUser/EmailsTest.php @@ -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 */