Browse code

Added README.md appinfo/info.xml appinfo/signature.json lib/Controller/AuthorApiController.php and the providers directory

DoubleBastionAdmin authored on 20/08/2022 16:33:00
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,260 @@
1
+<?php
2
+
3
+namespace Telnyx;
4
+
5
+/**
6
+ * Class Telnyx
7
+ *
8
+ * @package Telnyx
9
+ */
10
+class Telnyx
11
+{
12
+    // @var string The Telnyx API key to be used for requests.
13
+    public static $apiKey;
14
+
15
+    // @var string The Telnyx client_id to be used for Connect requests.
16
+    public static $clientId;
17
+
18
+    // @var string The base URL for the Telnyx API.
19
+    #public static $apiBase = 'https://api.telnyx.com';
20
+    public static $apiBase = 'https://api.telnyx.com';
21
+    
22
+    // @var string|null The version of the Telnyx API to use for requests.
23
+    public static $apiVersion = null;
24
+
25
+    // @var string|null The account ID for connected accounts requests.
26
+    public static $accountId = null;
27
+
28
+    // @var string Path to the CA bundle used to verify SSL certificates
29
+    public static $caBundlePath = null;
30
+
31
+    // @var boolean Defaults to true.
32
+    public static $verifySslCerts = true;
33
+
34
+    // @var array The application's information (name, version, URL)
35
+    public static $appInfo = null;
36
+
37
+    // @var Util\LoggerInterface|null The logger to which the library will
38
+    //   produce messages.
39
+    public static $logger = null;
40
+
41
+    // @var int Maximum number of request retries
42
+    public static $maxNetworkRetries = 0;
43
+
44
+    // @var boolean Whether client telemetry is enabled. Defaults to false.
45
+    public static $enableTelemetry = false;
46
+
47
+    // @var float Maximum delay between retries, in seconds
48
+    private static $maxNetworkRetryDelay = 2.0;
49
+
50
+    // @var float Initial delay between retries, in seconds
51
+    private static $initialNetworkRetryDelay = 0.5;
52
+
53
+    const VERSION = '0.0.1';
54
+
55
+    /**
56
+     * @return string The API key used for requests.
57
+     */
58
+    public static function getApiKey()
59
+    {
60
+        return self::$apiKey;
61
+    }
62
+
63
+    /**
64
+     * @return string The client_id used for Connect requests.
65
+     */
66
+    public static function getClientId()
67
+    {
68
+        return self::$clientId;
69
+    }
70
+
71
+    /**
72
+     * @return Util\LoggerInterface The logger to which the library will
73
+     *   produce messages.
74
+     */
75
+    public static function getLogger()
76
+    {
77
+        if (self::$logger == null) {
78
+            return new Util\DefaultLogger();
79
+        }
80
+        return self::$logger;
81
+    }
82
+
83
+    /**
84
+     * @param Util\LoggerInterface $logger The logger to which the library
85
+     *   will produce messages.
86
+     */
87
+    public static function setLogger($logger)
88
+    {
89
+        self::$logger = $logger;
90
+    }
91
+
92
+    /**
93
+     * Sets the API key to be used for requests.
94
+     *
95
+     * @param string $apiKey
96
+     */
97
+    public static function setApiKey($apiKey)
98
+    {
99
+        self::$apiKey = $apiKey;
100
+    }
101
+
102
+    /**
103
+     * Sets the client_id to be used for Connect requests.
104
+     *
105
+     * @param string $clientId
106
+     */
107
+    public static function setClientId($clientId)
108
+    {
109
+        self::$clientId = $clientId;
110
+    }
111
+
112
+    /**
113
+     * @return string The API version used for requests. null if we're using the
114
+     *    latest version.
115
+     */
116
+    public static function getApiVersion()
117
+    {
118
+        return self::$apiVersion;
119
+    }
120
+
121
+    /**
122
+     * @param string $apiVersion The API version to use for requests.
123
+     */
124
+    public static function setApiVersion($apiVersion)
125
+    {
126
+        self::$apiVersion = $apiVersion;
127
+    }
128
+
129
+    /**
130
+     * @return string
131
+     */
132
+    private static function getDefaultCABundlePath()
133
+    {
134
+        return realpath(dirname(__FILE__) . '/../data/ca-certificates.crt');
135
+    }
136
+
137
+    /**
138
+     * @return string
139
+     */
140
+    public static function getCABundlePath()
141
+    {
142
+        return self::$caBundlePath ?: self::getDefaultCABundlePath();
143
+    }
144
+
145
+    /**
146
+     * @param string $caBundlePath
147
+     */
148
+    public static function setCABundlePath($caBundlePath)
149
+    {
150
+        self::$caBundlePath = $caBundlePath;
151
+    }
152
+
153
+    /**
154
+     * @return boolean
155
+     */
156
+    public static function getVerifySslCerts()
157
+    {
158
+        return self::$verifySslCerts;
159
+    }
160
+
161
+    /**
162
+     * @param boolean $verify
163
+     */
164
+    public static function setVerifySslCerts($verify)
165
+    {
166
+        self::$verifySslCerts = $verify;
167
+    }
168
+
169
+    /**
170
+     * @return string | null The Telnyx account ID for connected account
171
+     *   requests.
172
+     */
173
+    public static function getAccountId()
174
+    {
175
+        return self::$accountId;
176
+    }
177
+
178
+    /**
179
+     * @param string $accountId The Telnyx account ID to set for connected
180
+     *   account requests.
181
+     */
182
+    public static function setAccountId($accountId)
183
+    {
184
+        self::$accountId = $accountId;
185
+    }
186
+
187
+    /**
188
+     * @return array | null The application's information
189
+     */
190
+    public static function getAppInfo()
191
+    {
192
+        return self::$appInfo;
193
+    }
194
+
195
+    /**
196
+     * @param string $appName The application's name
197
+     * @param string $appVersion The application's version
198
+     * @param string $appUrl The application's URL
199
+     */
200
+    public static function setAppInfo($appName, $appVersion = null, $appUrl = null, $appPartnerId = null)
201
+    {
202
+        self::$appInfo = self::$appInfo ?: [];
203
+        self::$appInfo['name'] = $appName;
204
+        self::$appInfo['partner_id'] = $appPartnerId;
205
+        self::$appInfo['url'] = $appUrl;
206
+        self::$appInfo['version'] = $appVersion;
207
+    }
208
+
209
+    /**
210
+     * @return int Maximum number of request retries
211
+     */
212
+    public static function getMaxNetworkRetries()
213
+    {
214
+        return self::$maxNetworkRetries;
215
+    }
216
+
217
+    /**
218
+     * @param int $maxNetworkRetries Maximum number of request retries
219
+     */
220
+    public static function setMaxNetworkRetries($maxNetworkRetries)
221
+    {
222
+        self::$maxNetworkRetries = $maxNetworkRetries;
223
+    }
224
+
225
+    /**
226
+     * @return float Maximum delay between retries, in seconds
227
+     */
228
+    public static function getMaxNetworkRetryDelay()
229
+    {
230
+        return self::$maxNetworkRetryDelay;
231
+    }
232
+
233
+    /**
234
+     * @return float Initial delay between retries, in seconds
235
+     */
236
+    public static function getInitialNetworkRetryDelay()
237
+    {
238
+        return self::$initialNetworkRetryDelay;
239
+    }
240
+
241
+    /**
242
+     * @return bool Whether client telemetry is enabled
243
+     */
244
+    public static function getEnableTelemetry()
245
+    {
246
+        return self::$enableTelemetry;
247
+    }
248
+
249
+    /**
250
+     * @param bool $enableTelemetry Enables client telemetry.
251
+     *
252
+     * Client telemetry enables timing and request metrics to be sent back to Telnyx as an HTTP Header
253
+     * with the current request. This enables Telnyx to do latency and metrics analysis without adding extra
254
+     * overhead (such as extra network calls) on the client.
255
+     */
256
+    public static function setEnableTelemetry($enableTelemetry)
257
+    {
258
+        self::$enableTelemetry = $enableTelemetry;
259
+    }
260
+}