Skip to content

Commit 7e5e260

Browse files
committed
Implemented notifications from github API
1 parent 5ff25d5 commit 7e5e260

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Github\Api\Activity;
4+
5+
use DateTime;
6+
use DateTimeInterface;
7+
use Github\Api\AbstractApi;
8+
9+
/**
10+
* API for accessing Notifications from your Git/Github repositories.
11+
*
12+
* Important! You have to be authenticated to perform these methods
13+
*
14+
* @link https://developer.github.com/v3/activity/notifications/
15+
* @author Dennis de Greef <[email protected]>
16+
*/
17+
class Notification extends AbstractApi
18+
{
19+
/**
20+
* Get a listing of a notifications
21+
* @link https://developer.github.com/v3/activity/notifications/
22+
*
23+
* @param bool $includingRead
24+
* @param bool $participating
25+
* @param null $since
26+
*
27+
* @return array array of notifications
28+
*/
29+
public function all($includingRead = false, $participating = false, $since = null)
30+
{
31+
$parameters = array(
32+
'all' => $includingRead,
33+
'participating' => $participating
34+
);
35+
36+
if($since !== null) {
37+
$parameters['since'] = $since;
38+
}
39+
40+
return $this->get('notifications', $parameters);
41+
}
42+
43+
/**
44+
* Marks all notifications as read from the current date
45+
* Optionally give DateTimeInterface to mark as read before that date
46+
*
47+
* @link https://developer.github.com/v3/activity/notifications/#mark-as-read
48+
*
49+
* @param DateTimeInterface $since
50+
*
51+
*/
52+
public function markRead(DateTimeInterface $since = null)
53+
{
54+
$parameters = array();
55+
56+
if($since !== null) {
57+
$parameters['last_read_at'] = $since->format(DateTime::ISO8601);
58+
}
59+
60+
$this->put('notifications', $parameters);
61+
}
62+
}

lib/Github/Client.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ public function api($name)
143143
$api = new Api\Markdown($this);
144144
break;
145145

146+
case 'notification':
147+
case 'notifications':
148+
$api = new Api\Activity\Notification($this);
149+
break;
150+
146151
case 'organization':
147152
case 'organizations':
148153
$api = new Api\Organization($this);

0 commit comments

Comments
 (0)