This repository was archived by the owner on Apr 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathNovu.php
More file actions
130 lines (111 loc) · 2.68 KB
/
Novu.php
File metadata and controls
130 lines (111 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
namespace Novu\SDK;
use GuzzleHttp\Client as HttpClient;
use Novu\SDK\Exceptions\IsNull;
use Novu\SDK\Exceptions\IsEmpty;
class Novu
{
use MakeHttpRequests,
Actions\ManagesTopics,
Actions\ManagesSubscribers,
Actions\ManagesActivity,
Actions\ManagesChanges,
Actions\ManagesEnvironments,
Actions\ManagesExecutionDetails,
Actions\ManagesFeeds,
Actions\ManagesIntegrations,
Actions\ManagesMessages,
Actions\ManagesTriggers,
Actions\ManagesNotificationGroups,
Actions\ManagesNotificationTemplates;
/**
* Create a new Novu instance.
*
* @param string|null $apiKey
* @param \GuzzleHttp\Client|null $guzzle
* @return void
*/
public function __construct(
/**
* The Novu API Key.
*
* @var string
*/
protected string $apiKey,
/**
* The Novu API Base URL.
*
* @var string
*/
protected string $baseUri = 'https://api.novu.co/v1/',
/**
* The Guzzle HTTP Client instance.
*
* @var \GuzzleHttp\Client
*/
public ?\GuzzleHttp\Client $client = null,
/**
* Number of seconds a request is retried.
*
* @var int
*/
public int $timeout = 30,
)
{
if( empty($apiKey)) {
throw isEmpty::make('API KEY');
}
$this->setApiKey($apiKey, $client);
$this->client = $client;
}
/**
* Set the api key and setup the client request object.
*
* @param string $apiKey
* @param \GuzzleHttp\Client|null $client
* @return $this
*/
public function setApiKey($apiKey, $client = null): self
{
$this->apiKey = $apiKey;
$this->client = $client ?: new HttpClient([
'base_uri' => $this->baseUri,
'http_errors' => false,
'headers' => [
'Authorization' => 'ApiKey '.$this->apiKey,
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
]);
return $this;
}
/**
* Set a new timeout.
*
* @param int $timeout
* @return $this
*/
public function setTimeout($timeout): self
{
$this->timeout = $timeout;
return $this;
}
/**
* Get the timeout.
*
* @return int
*/
public function getTimeout(): int
{
return $this->timeout;
}
/**
* Get the API Base Uri
*
* @return string
*/
public function getBaseUri(): string
{
return $this->baseUri;
}
}