Skip to content
61 changes: 61 additions & 0 deletions lib/Github/Api/Notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Github\Api;

use DateTime;
use DateTimeInterface;

/**
* API for accessing Notifications from your Git/Github repositories.
*
* Important! You have to be authenticated to perform these methods
*
* @link https://developer.github.com/v3/activity/notifications/
* @author Dennis de Greef <[email protected]>
*/
class Notification extends AbstractApi
{
/**
* Get a listing of a notifications
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The a should be removed here.

* @link https://developer.github.com/v3/activity/notifications/
*
* @param bool $includingRead
* @param bool $participating
* @param null $since
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be string|null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, in markRead() you treat $since as DateTime. Might be a good idea to to that here as well.

*
* @return array array of notifications
*/
public function all($includingRead = false, $participating = false, $since = null)
{
$parameters = array(
'all' => $includingRead,
'participating' => $participating
);

if($since !== null) {
$parameters['since'] = $since;
}

return $this->get('notifications', $parameters);
}

/**
* Marks all notifications as read from the current date
* Optionally give DateTimeInterface to mark as read before that date
*
* @link https://developer.github.com/v3/activity/notifications/#mark-as-read
*
* @param DateTimeInterface $since
*
*/
public function markRead(DateTimeInterface $since = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typehinting the interface means that it is not compatible with PHP 5.3 or 5.4

{
$parameters = array();

if($since !== null) {
$parameters['last_read_at'] = $since->format(DateTime::ISO8601);
}

$this->put('notifications', $parameters);
}
}
7 changes: 7 additions & 0 deletions lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @method Api\Issue issue()
* @method Api\Issue issues()
* @method Api\Markdown markdown()
* @method Api\Notification notification()
* @method Api\Notification notifications()
* @method Api\Organization organization()
* @method Api\Organization organizations()
* @method Api\PullRequest pr()
Expand Down Expand Up @@ -143,6 +145,11 @@ public function api($name)
$api = new Api\Markdown($this);
break;

case 'notification':
case 'notifications':
$api = new Api\Notification($this);
break;

case 'organization':
case 'organizations':
$api = new Api\Organization($this);
Expand Down