-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHypernodeClient.php
More file actions
65 lines (58 loc) · 2.07 KB
/
Copy pathHypernodeClient.php
File metadata and controls
65 lines (58 loc) · 2.07 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
<?php
declare(strict_types=1);
namespace Hypernode\Api;
use Http\Client\Common\HttpMethodsClientInterface;
use Hypernode\Api\Exception\HypernodeApiClientException;
use Hypernode\Api\Exception\HypernodeApiServerException;
use Hypernode\Api\Service\Addon;
use Hypernode\Api\Service\App;
use Hypernode\Api\Service\Backup;
use Hypernode\Api\Service\BrancherApp;
use Hypernode\Api\Service\Configuration;
use Hypernode\Api\Service\InsightsAnnotation;
use Hypernode\Api\Service\Logbook;
use Hypernode\Api\Service\Product;
use Hypernode\Api\Service\Settings;
use Hypernode\Api\Service\Whitelist;
use Psr\Http\Message\ResponseInterface;
class HypernodeClient
{
public HttpMethodsClientInterface $api;
public Addon $addon;
public App $app;
public Backup $backup;
public BrancherApp $brancherApp;
public Configuration $configuration;
public InsightsAnnotation $insightsAnnotation;
public Product $product;
public Settings $settings;
public Logbook $logbook;
public Whitelist $whitelist;
public function __construct(HttpMethodsClientInterface $apiClient)
{
$this->api = $apiClient;
$this->addon = new Addon($this);
$this->app = new App($this);
$this->backup = new Backup($this);
$this->brancherApp = new BrancherApp($this);
$this->configuration = new Configuration($this);
$this->insightsAnnotation = new InsightsAnnotation($this);
$this->product = new Product($this);
$this->settings = new Settings($this);
$this->logbook = new Logbook($this);
$this->whitelist = new Whitelist($this);
}
public function getJsonFromResponse(ResponseInterface $response)
{
return json_decode((string)$response->getBody(), true, JSON_THROW_ON_ERROR);
}
public function maybeThrowApiExceptions(ResponseInterface $response)
{
if ($response->getStatusCode() >= 500) {
throw new HypernodeApiServerException($response);
}
if ($response->getStatusCode() >= 400) {
throw new HypernodeApiClientException($response);
}
}
}