File tree Expand file tree Collapse file tree 4 files changed +76
-0
lines changed
lib/Github/Api/CurrentUser
test/Github/Tests/Api/CurrentUser Expand file tree Collapse file tree 4 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ v3 APIs:
10
10
* [ Authorizations] ( authorizations.md )
11
11
* [ Commits] ( commits.md )
12
12
* Current User
13
+ * [ Emails] ( currentuser/emails.md )
13
14
* [ Public keys] ( currentuser/publickeys.md )
14
15
* [ Memberships] ( currentuser/memberships.md )
15
16
* [ Enterprise] ( enterprise.md )
Original file line number Diff line number Diff line change
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
+ ```
Original file line number Diff line number Diff line change @@ -23,6 +23,18 @@ public function all()
23
23
return $ this ->get ('/user/emails ' );
24
24
}
25
25
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
+
26
38
/**
27
39
* Adds one or more email for the authenticated user.
28
40
*
@@ -66,4 +78,16 @@ public function remove($emails)
66
78
67
79
return $ this ->delete ('/user/emails ' , $ emails );
68
80
}
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
+ }
69
93
}
Original file line number Diff line number Diff line change @@ -110,6 +110,22 @@ public function shouldNotAddEmailsWhenAreNotPass()
110
110
$ api ->add (array ());
111
111
}
112
112
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
+
113
129
/**
114
130
* @return string
115
131
*/
You can’t perform that action at this time.
0 commit comments