File tree Expand file tree Collapse file tree 5 files changed +75
-1
lines changed Expand file tree Collapse file tree 5 files changed +75
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,13 @@ $activity = $client->api('current_user')->starring()->all();
3131```
3232Returns an array of starred repos.
3333
34+ ### Get list of private and public events for an authenticated user for all repos
35+
36+ ``` php
37+ $activity = $client->api('user')->events('ornicar');
38+ ```
39+ Returns an array of private and public events created for all repos related to the user.
40+
3441### Get repos that a authenticated user has starred with creation date
3542
3643Support for getting the star creation timestamp in the response, using the custom ` Accept: application/vnd.github.v3.star+json ` header.
@@ -100,4 +107,4 @@ $owner = "KnpLabs";
100107$repo = "php-github-api";
101108$activity = $client->api('current_user')->watchers()->unwatch($owner, $repo);
102109```
103- Throws an Exception in case of failure or NULL in case of success.
110+ Throws an Exception in case of failure or NULL in case of success.
Original file line number Diff line number Diff line change @@ -148,6 +148,17 @@ $users = $client->api('current_user')->starring()->all();
148148
149149Returns an array of starred repos.
150150
151+ ### Get the authenticated user activity
152+
153+ > Requires [ authentication] ( security.md ) .
154+
155+ ``` php
156+ $activity = $client->api('user')->events('ornicar');
157+ ```
158+
159+ Returns an array of private and public events created for all repos related to the user.
160+ > See [ more] ( activity.md ) .
161+
151162### Get the authenticated user emails
152163
153164> Requires [ authentication] ( security.md ) .
Original file line number Diff line number Diff line change @@ -234,4 +234,16 @@ public function publicEvents($username)
234234 {
235235 return $ this ->get ('/users/ ' .rawurlencode ($ username ).'/events/public ' );
236236 }
237+
238+ /**
239+ * List events performed by an authenticated user.
240+ *
241+ * @link https://docs.github.com/en/rest/reference/activity#list-events-for-the-authenticated-user
242+ *
243+ * @return array
244+ */
245+ public function events (string $ username )
246+ {
247+ return $ this ->get ('/users/ ' .rawurlencode ($ username ).'/events ' );
248+ }
237249}
Original file line number Diff line number Diff line change @@ -228,6 +228,29 @@ public function shouldGetUserGists()
228228 $ this ->assertEquals ($ expectedArray , $ api ->gists ('l3l0 ' ));
229229 }
230230
231+ /**
232+ * @test
233+ */
234+ public function shouldGetAuthorizedUserEvents ()
235+ {
236+ $ expectedArray = [
237+ [
238+ 'id ' => 1 ,
239+ 'actor ' => [
240+ 'id ' => 1 ,
241+ 'login ' => 'l3l0 ' ,
242+ ],
243+ ],
244+ ];
245+ $ api = $ this ->getApiMock ();
246+ $ api ->expects ($ this ->once ())
247+ ->method ('get ' )
248+ ->with ('/users/l3l0/events ' )
249+ ->will ($ this ->returnValue ($ expectedArray ));
250+
251+ $ this ->assertEquals ($ expectedArray , $ api ->events ('l3l0 ' ));
252+ }
253+
231254 /**
232255 * @return string
233256 */
Original file line number Diff line number Diff line change @@ -138,4 +138,25 @@ public function shouldGetReposBeingStarred()
138138 $ this ->assertArrayHasKey ('git_url ' , $ repo );
139139 $ this ->assertArrayHasKey ('svn_url ' , $ repo );
140140 }
141+
142+ /**
143+ * @test
144+ */
145+ public function shouldGetEventsForAuthenticatedUserBeignWatched ()
146+ {
147+ $ username = 'l3l0 ' ;
148+
149+ $ events = $ this ->client ->api ('user ' )->events ($ username );
150+ $ event = array_pop ($ events );
151+
152+ $ this ->assertArrayHasKey ('id ' , $ event );
153+ $ this ->assertArrayHasKey ('type ' , $ event );
154+ $ this ->assertArrayHasKey ('actor ' , $ event );
155+ $ this ->assertArrayHasKey ('login ' , $ event ['actor ' ]);
156+ $ this ->assertArrayHasKey ('repo ' , $ event );
157+ $ this ->assertArrayHasKey ('name ' , $ event ['repo ' ]);
158+ $ this ->assertArrayHasKey ('payload ' , $ event );
159+ $ this ->assertArrayHasKey ('public ' , $ event );
160+ $ this ->assertArrayHasKey ('created_at ' , $ event );
161+ }
141162}
You can’t perform that action at this time.
0 commit comments