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

namespace Github\Api\Activity;

use DateTime;
use DateTimeInterface;
use Github\Api\AbstractApi;

/**
* 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
* @link https://developer.github.com/v3/activity/notifications/
*
* @param bool $includingRead
* @param bool $participating
* @param null $since
*
* @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)
{
$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\Activity\Notification notification()
* @method Api\Activity\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\Activity\Notification($this);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrong. If it is in the Activity subnamespace, it should be acess from an Api\Activity API, not from the main client, to be consistent with the current architecture of the library

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to namespace Api\Notification see 300a091

break;

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