-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHypernodeClient.php
More file actions
49 lines (41 loc) · 1.39 KB
/
HypernodeClient.php
File metadata and controls
49 lines (41 loc) · 1.39 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
<?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\App;
use Hypernode\Api\Service\BrancherApp;
use Hypernode\Api\Service\Logbook;
use Hypernode\Api\Service\Settings;
use Psr\Http\Message\ResponseInterface;
class HypernodeClient
{
public const VERSION = '0.1.0';
public HttpMethodsClientInterface $api;
public App $app;
public BrancherApp $brancherApp;
public Settings $settings;
public Logbook $logbook;
public function __construct(HttpMethodsClientInterface $apiClient)
{
$this->api = $apiClient;
$this->app = new App($this);
$this->brancherApp = new BrancherApp($this);
$this->settings = new Settings($this);
$this->logbook = new Logbook($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);
}
}
}