Skip to content

Commit 882e0d5

Browse files
feat(api): Notifications, notification stats, graph stats, notification
1 parent 494f473 commit 882e0d5

5 files changed

+243
-0
lines changed

src/Actions/ManagesNotifications.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Novu\SDK\Actions;
4+
5+
use Novu\SDK\Resources\Notification;
6+
use Novu\SDK\Resources\NotificationStats;
7+
use Novu\SDK\Resources\NotificationGraphStats;
8+
9+
trait ManagesNotifications
10+
{
11+
12+
/**
13+
* Get A Notification
14+
*
15+
* @param string $notificationId
16+
* @return \Novu\SDK\Resources\Notification
17+
*/
18+
public function getNotification($notificationId)
19+
{
20+
$response = $this->get("notifications/{$notificationId}");
21+
22+
return new Notification($response, $this);
23+
}
24+
25+
/**
26+
* Get All Notifications
27+
*
28+
* @return \Novu\SDK\Resources\Notification
29+
*/
30+
public function getNotifications()
31+
{
32+
$response = $this->get("notifications")['data'];
33+
34+
return new Notification($response, $this);
35+
}
36+
37+
/**
38+
* Get Notification Statistics
39+
*
40+
* @return \Novu\SDK\Resources\NotificationStats
41+
*/
42+
public function getNotificationStats()
43+
{
44+
$response = $this->get("notifications/stats")['data'];
45+
46+
return new NotificationStats($response, $this);
47+
}
48+
49+
/**
50+
* Get Notification Graph Stats
51+
*
52+
* @return \Novu\SDK\Resources\NotificationGraphStats
53+
*/
54+
public function getNotificationGraphStats()
55+
{
56+
$response = $this->get("notifications/graph/stats")['data'];
57+
58+
return new NotificationGraphStats($response, $this);
59+
}
60+
61+
}

src/Novu.php

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Novu
1313
Actions\ManagesSubscribers,
1414
Actions\ManagesActivity,
1515
Actions\ManagesInboundParse,
16+
Actions\ManagesNotifications,
1617
Actions\ManagesChanges,
1718
Actions\ManagesEnvironments,
1819
Actions\ManagesExecutionDetails,

src/Resources/Notification.php

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace Novu\SDK\Resources;
4+
5+
class Notification extends Resource
6+
{
7+
/**
8+
* The internal id Novu generated
9+
*
10+
* @var string
11+
*/
12+
public $id;
13+
14+
/**
15+
* The environment Id
16+
*
17+
* @var string
18+
*/
19+
public $environmentId;
20+
21+
/**
22+
* The organization id
23+
*
24+
* @var string
25+
*/
26+
public $organizationId;
27+
28+
/**
29+
* The transaction id
30+
*
31+
* @var string
32+
*/
33+
public $transactionId;
34+
35+
/**
36+
* The createdAt
37+
*
38+
* @var string
39+
*/
40+
public $createdAt;
41+
42+
/**
43+
* The channels
44+
*
45+
* @var array
46+
*/
47+
public $channels;
48+
49+
/**
50+
* The subscriber
51+
*
52+
* @var array
53+
*/
54+
public $subscriber;
55+
56+
/**
57+
* The template
58+
*
59+
* @var array
60+
*/
61+
public $template;
62+
63+
/**
64+
* The jobs
65+
*
66+
* @var string
67+
*/
68+
public $jobs;
69+
70+
71+
/**
72+
* Return the array form of Notification object.
73+
*
74+
* @return array
75+
*/
76+
public function toArray(): array
77+
{
78+
79+
$publicProperties = get_object_vars($this);
80+
81+
unset($publicProperties['attributes']);
82+
unset($publicProperties['novu']);
83+
84+
return array_filter($publicProperties, function ($value) {
85+
return null !== $value;
86+
});
87+
}
88+
}
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Novu\SDK\Resources;
4+
5+
class NotificationGraphStats extends Resource
6+
{
7+
/**
8+
* The internal id Novu generated
9+
*
10+
* @var string
11+
*/
12+
public $id;
13+
14+
/**
15+
* The count
16+
*
17+
* @var integer
18+
*/
19+
public $count;
20+
21+
/**
22+
* The templates
23+
*
24+
* @var array
25+
*/
26+
public $templates;
27+
28+
/**
29+
* The channels
30+
*
31+
* @var array
32+
*/
33+
public $channels;
34+
35+
36+
/**
37+
* Return the array form of Notification Graph Stats
38+
*
39+
* @return array
40+
*/
41+
public function toArray(): array
42+
{
43+
$publicProperties = get_object_vars($this);
44+
45+
unset($publicProperties['attributes']);
46+
unset($publicProperties['novu']);
47+
48+
return array_filter($publicProperties, function ($value) {
49+
return null !== $value;
50+
});
51+
}
52+
}

src/Resources/NotificationStats.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Novu\SDK\Resources;
4+
5+
class NotificationStats extends Resource
6+
{
7+
/**
8+
* The weekly sent count
9+
*
10+
* @var integer
11+
*/
12+
public $weeklySent;
13+
14+
/**
15+
* The monthly sent count
16+
*
17+
* @var integer
18+
*/
19+
public $monthlySent;
20+
21+
/**
22+
* The yearly sent count
23+
*
24+
* @var integer
25+
*/
26+
public $yearlySent;
27+
28+
/**
29+
* Return the array form of Notification Stats object.
30+
*
31+
* @return array
32+
*/
33+
public function toArray(): array
34+
{
35+
return [
36+
'weeklySent' => $this->weeklySent,
37+
'monthlySent' => $this->monthlySent,
38+
'yearlySent' => $this->yearlySent,
39+
];
40+
}
41+
}

0 commit comments

Comments
 (0)