1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage GitHub
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * GitHub API Activity Events class for the Joomla Platform.
14 *
15 * @documentation https://developer.github.com/v3/activity/notifications/
16 *
17 * @since 3.3 (CMS)
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackageActivityNotifications extends JGithubPackage
21 {
22 /**
23 * List your notifications.
24 *
25 * List all notifications for the current user, grouped by repository.
26 *
27 * @param boolean $all True to show notifications marked as read.
28 * @param boolean $participating True to show only notifications in which the user is directly participating or
29 * mentioned.
30 * @param JDate $since filters out any notifications updated before the given time. The time should be passed in
31 * as UTC in the ISO 8601 format.
32 *
33 * @since 3.3 (CMS)
34 *
35 * @return object
36 */
37 public function getList($all = true, $participating = true, JDate $since = null)
38 {
39 // Build the request path.
40 $path = '/notifications?';
41
42 $path .= ($all) ? '&all=1' : '';
43 $path .= ($participating) ? '&participating=1' : '';
44 $path .= ($since) ? '&since=' . $since->toISO8601() : '';
45
46 return $this->processResponse(
47 $this->client->get($this->fetchUrl($path))
48 );
49 }
50
51 /**
52 * List your notifications in a repository.
53 *
54 * List all notifications for the current user.
55 *
56 * @param string $owner Repository owner.
57 * @param string $repo Repository name.
58 * @param boolean $all True to show notifications marked as read.
59 * @param boolean $participating True to show only notifications in which the user is directly participating or
60 * mentioned.
61 * @param JDate $since filters out any notifications updated before the given time. The time should be passed in
62 * as UTC in the ISO 8601 format.
63 *
64 * @since 3.3 (CMS)
65 *
66 * @return object
67 */
68 public function getListRepository($owner, $repo, $all = true, $participating = true, JDate $since = null)
69 {
70 // Build the request path.
71 $path = '/repos/' . $owner . '/' . $repo . '/notifications?';
72
73 $path .= ($all) ? '&all=1' : '';
74 $path .= ($participating) ? '&participating=1' : '';
75 $path .= ($since) ? '&since=' . $since->toISO8601() : '';
76
77 return $this->processResponse(
78 $this->client->get($this->fetchUrl($path))
79 );
80 }
81
82 /**
83 * Mark as read.
84 *
85 * Marking a notification as “read” removes it from the default view on GitHub.com.
86 *
87 * @param boolean $unread Changes the unread status of the threads.
88 * @param boolean $read Inverse of “unread”.
89 * @param JDate $last_read_at Describes the last point that notifications were checked.
90 * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format.
91 *
92 * @since 3.3 (CMS)
93 *
94 * @return object
95 */
96 public function markRead($unread = true, $read = true, JDate $last_read_at = null)
97 {
98 // Build the request path.
99 $path = '/notifications';
100
101 $data = array(
102 'unread' => $unread,
103 'read' => $read,
104 );
105
106 if ($last_read_at)
107 {
108 $data['last_read_at'] = $last_read_at->toISO8601();
109 }
110
111 return $this->processResponse(
112 $this->client->put($this->fetchUrl($path), json_encode($data)),
113 205
114 );
115 }
116
117 /**
118 * Mark notifications as read in a repository.
119 *
120 * Marking all notifications in a repository as “read” removes them from the default view on GitHub.com.
121 *
122 * @param string $owner Repository owner.
123 * @param string $repo Repository name.
124 * @param boolean $unread Changes the unread status of the threads.
125 * @param boolean $read Inverse of “unread”.
126 * @param JDate $last_read_at Describes the last point that notifications were checked.
127 * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format.
128 *
129 * @since 3.3 (CMS)
130 *
131 * @return object
132 */
133 public function markReadRepository($owner, $repo, $unread, $read, JDate $last_read_at = null)
134 {
135 // Build the request path.
136 $path = '/repos/' . $owner . '/' . $repo . '/notifications';
137
138 $data = array(
139 'unread' => $unread,
140 'read' => $read,
141 );
142
143 if ($last_read_at)
144 {
145 $data['last_read_at'] = $last_read_at->toISO8601();
146 }
147
148 return $this->processResponse(
149 $this->client->put($this->fetchUrl($path), json_encode($data)),
150 205
151 );
152 }
153
154 /**
155 * View a single thread.
156 *
157 * @param integer $id The thread id.
158 *
159 * @since 3.3 (CMS)
160 *
161 * @return object
162 */
163 public function viewThread($id)
164 {
165 // Build the request path.
166 $path = '/notifications/threads/' . $id;
167
168 return $this->processResponse(
169 $this->client->get($this->fetchUrl($path))
170 );
171 }
172
173 /**
174 * Mark a thread as read.
175 *
176 * @param integer $id The thread id.
177 * @param boolean $unread Changes the unread status of the threads.
178 * @param boolean $read Inverse of “unread”.
179 *
180 * @since 3.3 (CMS)
181 *
182 * @return object
183 */
184 public function markReadThread($id, $unread = true, $read = true)
185 {
186 // Build the request path.
187 $path = '/notifications/threads/' . $id;
188
189 $data = array(
190 'unread' => $unread,
191 'read' => $read,
192 );
193
194 return $this->processResponse(
195 $this->client->patch($this->fetchUrl($path), json_encode($data)),
196 205
197 );
198 }
199
200 /**
201 * Get a Thread Subscription.
202 *
203 * This checks to see if the current user is subscribed to a thread.
204 * You can also get a Repository subscription.
205 *
206 * @param integer $id The thread id.
207 *
208 * @since 3.3 (CMS)
209 *
210 * @return object
211 */
212 public function getThreadSubscription($id)
213 {
214 // Build the request path.
215 $path = '/notifications/threads/' . $id . '/subscription';
216
217 return $this->processResponse(
218 $this->client->get($this->fetchUrl($path))
219 );
220 }
221
222 /**
223 * Set a Thread Subscription.
224 *
225 * This lets you subscribe to a thread, or ignore it. Subscribing to a thread is unnecessary
226 * if the user is already subscribed to the repository. Ignoring a thread will mute all
227 * future notifications (until you comment or get @mentioned).
228 *
229 * @param integer $id The thread id.
230 * @param boolean $subscribed Determines if notifications should be received from this thread.
231 * @param boolean $ignored Determines if all notifications should be blocked from this thread.
232 *
233 * @since 3.3 (CMS)
234 *
235 * @return object
236 */
237 public function setThreadSubscription($id, $subscribed, $ignored)
238 {
239 // Build the request path.
240 $path = '/notifications/threads/' . $id . '/subscription';
241
242 $data = array(
243 'subscribed' => $subscribed,
244 'ignored' => $ignored,
245 );
246
247 return $this->processResponse(
248 $this->client->put($this->fetchUrl($path), json_encode($data))
249 );
250 }
251
252 /**
253 * Delete a Thread Subscription.
254 *
255 * @param integer $id The thread id.
256 *
257 * @since 3.3 (CMS)
258 *
259 * @return object
260 */
261 public function deleteThreadSubscription($id)
262 {
263 // Build the request path.
264 $path = '/notifications/threads/' . $id . '/subscription';
265
266 return $this->processResponse(
267 $this->client->delete($this->fetchUrl($path)),
268 204
269 );
270 }
271 }
272