-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.php
More file actions
68 lines (58 loc) · 2.19 KB
/
Copy pathproxy.php
File metadata and controls
68 lines (58 loc) · 2.19 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
<?php
declare(strict_types=1);
/**
* Runnable example: proxy management endpoints.
*
* Set NOVADA_API_KEY in the environment, then run:
* php examples/proxy.php
*/
require __DIR__ . '/../vendor/autoload.php';
use Novada\Client;
use Novada\Exception\ApiException;
use Novada\Exception\AuthException;
use Novada\Exception\RateLimitException;
use Novada\Exception\ValidationException;
use Novada\Proxy\Dto\AddWhitelistParams;
use Novada\Proxy\Dto\ListAccountParams;
use Novada\Proxy\Dto\ListWhitelistParams;
use Novada\Proxy\Dto\TimeRange;
use Novada\Proxy\Product;
$client = new Client(); // reads NOVADA_API_KEY from the environment
try {
// Whitelist: add then list.
$client->proxy->whitelist->add(new AddWhitelistParams(
product: Product::Residential,
ip: '10.10.10.1',
remark: 'example run',
));
$whitelist = $client->proxy->whitelist->list(new ListWhitelistParams(
product: Product::Residential,
));
printf("whitelist total=%d\n", $whitelist->total);
foreach ($whitelist->list as $entry) {
printf(" - %s (id=%d, remark=%s)\n", $entry->markIp, $entry->id, $entry->mark);
}
// Sub-accounts.
$accounts = $client->proxy->account->list(new ListAccountParams(product: Product::Residential));
printf("accounts total=%d\n", $accounts->total);
// Residential traffic.
$balance = $client->proxy->residential->balance();
printf("residential balance=%d bytes\n", $balance->balance);
$consumeLog = $client->proxy->residential->consumeLog(new TimeRange(
start: '2025-01-01 00:00:00',
end: '2025-01-31 23:59:59',
));
printf("residential consume_log entries=%d\n", count($consumeLog->list));
} catch (ValidationException $e) {
fwrite(STDERR, "validation error in {$e->getMethod()}: " . implode(', ', $e->getFields()) . "\n");
exit(1);
} catch (AuthException $e) {
fwrite(STDERR, "invalid API key (HTTP {$e->getHttpStatus()})\n");
exit(1);
} catch (RateLimitException $e) {
fwrite(STDERR, "rate limited (HTTP {$e->getHttpStatus()})\n");
exit(1);
} catch (ApiException $e) {
fwrite(STDERR, "api error code={$e->getCode()} http={$e->getHttpStatus()}: {$e->getMsg()}\n");
exit(1);
}