Skip to content

Commit 265a427

Browse files
committed
Introduce user Notifications API
1 parent 0a14df1 commit 265a427

File tree

3 files changed

+147
-9
lines changed

3 files changed

+147
-9
lines changed

lib/Github/Api/CurrentUser.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Github\Api\CurrentUser\DeployKeys;
66
use Github\Api\CurrentUser\Emails;
77
use Github\Api\CurrentUser\Followers;
8+
use Github\Api\CurrentUser\Notifications;
89
use Github\Api\CurrentUser\Watchers;
910

1011
/**
@@ -23,14 +24,6 @@ public function update(array $params)
2324
return $this->patch('user', $params);
2425
}
2526

26-
/**
27-
* @return DeployKeys
28-
*/
29-
public function keys()
30-
{
31-
return new DeployKeys($this->client);
32-
}
33-
3427
/**
3528
* @return Emails
3629
*/
@@ -67,6 +60,22 @@ public function issues(array $params = array(), $includeOrgIssues = true)
6760
return $this->get($includeOrgIssues ? 'issues' : 'user/issues', array_merge(array('page' => 1), $params));
6861
}
6962

63+
/**
64+
* @return DeployKeys
65+
*/
66+
public function keys()
67+
{
68+
return new DeployKeys($this->client);
69+
}
70+
71+
/**
72+
* @return Notifications
73+
*/
74+
public function notifications()
75+
{
76+
return new Notifications($this->client);
77+
}
78+
7079
/**
7180
* @link http://developer.github.com/v3/repos/#list-your-repositories
7281
*
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
namespace Github\Api\CurrentUser;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
* @link http://developer.github.com/v3/activity/notifications/
9+
* @author Joseph Bielawski <stloyd@gmail.com>
10+
*/
11+
class Notifications extends AbstractApi
12+
{
13+
/**
14+
* List all notifications for the authenticated user
15+
* @link http://developer.github.com/v3/activity/notifications/#list-your-notifications
16+
*
17+
* @param array $params
18+
* @return array
19+
*/
20+
public function all(array $params = array())
21+
{
22+
return $this->get('notifications', $params);
23+
}
24+
25+
/**
26+
* List all notifications for the authenticated user in selected repository
27+
* @link http://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository
28+
*
29+
* @param string $username the user who owns the repo
30+
* @param string $repository the name of the repo
31+
* @param array $params
32+
* @return array
33+
*/
34+
public function allInRepository($username, $repository, array $params = array())
35+
{
36+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/notifications', $params);
37+
}
38+
39+
/**
40+
* @link http://developer.github.com/v3/activity/notifications/#mark-as-read
41+
*
42+
* @param array $params
43+
* @return array
44+
*/
45+
public function markAsReadAll(array $params = array())
46+
{
47+
return $this->put('notifications', $params);
48+
}
49+
50+
/**
51+
* @link http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository
52+
*
53+
* @param string $username the user who owns the repo
54+
* @param string $repository the name of the repo
55+
* @param array $params
56+
* @return array
57+
*/
58+
public function markAsReadInRepository($username, $repository, array $params = array())
59+
{
60+
return $this->put('repos/'.urlencode($username).'/'.urlencode($repository).'/notifications', $params);
61+
}
62+
63+
/**
64+
* @link http://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read
65+
*
66+
* @param string $id the notification number
67+
* @param array $params
68+
* @return array
69+
*/
70+
public function markAsRead($id, array $params)
71+
{
72+
return $this->patch('notifications/threads/'.urlencode($id), $params);
73+
}
74+
75+
/**
76+
* @link http://developer.github.com/v3/activity/notifications/#view-a-single-thread
77+
*
78+
* @param string $id the notification number
79+
* @return array
80+
*/
81+
public function show($id)
82+
{
83+
return $this->get('notifications/threads/'.urlencode($id));
84+
}
85+
86+
/**
87+
* @link http://developer.github.com/v3/activity/notifications/#get-a-thread-subscription
88+
*
89+
* @param string $id the notification number
90+
* @return array
91+
*/
92+
public function showSubscription($id)
93+
{
94+
return $this->get('notifications/threads/'.urlencode($id).'/subscription');
95+
}
96+
97+
/**
98+
* @link http://developer.github.com/v3/activity/notifications/#set-a-thread-subscription
99+
*
100+
* @param string $id the notification number
101+
* @param array $params
102+
* @return array
103+
*/
104+
public function createSubscription($id, array $params)
105+
{
106+
return $this->put('notifications/threads/'.urlencode($id).'/subscription', $params);
107+
}
108+
109+
/**
110+
* @link http://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription
111+
*
112+
* @param string $id the notification number
113+
* @return array
114+
*/
115+
public function removeSubscription($id)
116+
{
117+
return $this->delete('notifications/threads/'.urlencode($id).'/subscription');
118+
}
119+
}

test/Github/Tests/Api/CurrentUserTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Github\Tests\Api;
44

55
/**
6-
* CurrentUser api test case
6+
* CurrentUser api test case
77
*
88
* @author Leszek Prabucki <leszek.prabucki@gmail.com>
99
*/
@@ -119,6 +119,16 @@ public function shouldGetFollowersApiObject()
119119
$this->assertInstanceOf('Github\Api\CurrentUser\Followers', $api->follow());
120120
}
121121

122+
/**
123+
* @test
124+
*/
125+
public function shouldGetNotificationsApiObject()
126+
{
127+
$api = $this->getApiMock();
128+
129+
$this->assertInstanceOf('Github\Api\CurrentUser\Notifications', $api->notifications());
130+
}
131+
122132
/**
123133
* @test
124134
*/

0 commit comments

Comments
 (0)