Skip to content

Commit 4ffb1d3

Browse files
acrobatNyholm
authored andcommitted
Missing toggle primary email visibility api endpoint (#660)
1 parent 3667cee commit 4ffb1d3

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

doc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ v3 APIs:
1010
* [Authorizations](authorizations.md)
1111
* [Commits](commits.md)
1212
* Current User
13+
* [Emails](currentuser/emails.md)
1314
* [Public keys](currentuser/publickeys.md)
1415
* [Memberships](currentuser/memberships.md)
1516
* [Enterprise](enterprise.md)

doc/currentuser/emails.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Current user / Emails API
2+
[Back to the navigation](../README.md)
3+
4+
Wraps [GitHub User Emails API](https://developer.github.com/v3/users/emails/#emails).
5+
6+
> Requires [authentication](../security.md).
7+
8+
### List email addresses for a user
9+
10+
```php
11+
$emails = $client->currentUser()->emails()->all();
12+
```
13+
14+
### List public email addresses for a user
15+
16+
```php
17+
$emails = $client->currentUser()->emails()->allPublic();
18+
```
19+
20+
### Add email address(es)
21+
22+
```php
23+
$emails = $client->currentUser()->emails()->add(['email1', 'email2']);
24+
```
25+
### Delete email address(es)
26+
27+
```php
28+
$client->currentUser()->emails()->remove(['email1', 'email2']);
29+
```
30+
31+
### Toggle primary email visibility
32+
33+
```php
34+
$primaryEmail = $client->currentUser()->emails()->toggleVisibility();
35+
```

lib/Github/Api/CurrentUser/Emails.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ public function all()
2323
return $this->get('/user/emails');
2424
}
2525

26+
/**
27+
* List public email addresses for a user.
28+
*
29+
* @link https://developer.github.com/v3/users/emails/#list-public-email-addresses-for-a-user
30+
*
31+
* @return array
32+
*/
33+
public function allPublic()
34+
{
35+
return $this->get('/user/public_emails');
36+
}
37+
2638
/**
2739
* Adds one or more email for the authenticated user.
2840
*
@@ -66,4 +78,16 @@ public function remove($emails)
6678

6779
return $this->delete('/user/emails', $emails);
6880
}
81+
82+
/**
83+
* Toggle primary email visibility
84+
*
85+
* @link https://developer.github.com/v3/users/emails/#toggle-primary-email-visibility
86+
*
87+
* @return array
88+
*/
89+
public function toggleVisibility()
90+
{
91+
return $this->patch('/user/email/visibility');
92+
}
6993
}

test/Github/Tests/Api/CurrentUser/EmailsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ public function shouldNotAddEmailsWhenAreNotPass()
110110
$api->add(array());
111111
}
112112

113+
/**
114+
* @test
115+
*/
116+
public function shouldToggleVisibility()
117+
{
118+
$expectedValue = array('primary email info');
119+
120+
$api = $this->getApiMock();
121+
$api->expects($this->once())
122+
->method('patch')
123+
->with('/user/email/visibility')
124+
->will($this->returnValue($expectedValue));
125+
126+
$this->assertEquals($expectedValue, $api->toggleVisibility());
127+
}
128+
113129
/**
114130
* @return string
115131
*/

0 commit comments

Comments
 (0)