-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBrancherApp.php
More file actions
97 lines (76 loc) · 2.73 KB
/
BrancherApp.php
File metadata and controls
97 lines (76 loc) · 2.73 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
<?php
declare(strict_types=1);
namespace Hypernode\Api\Service;
use Hypernode\Api\Exception\HypernodeApiClientException;
use Hypernode\Api\Exception\HypernodeApiServerException;
class BrancherApp extends AbstractService
{
/**
* List all brancher nodes for given parent app.
*
* @param string $app Name of the parent app
* @param array|null $data Extra data to be provided
* @return array Array containing brancher nodes
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function list(string $app, ?array $data = null): array
{
$url = sprintf(App::V2_BRANCHER_APP_URL, $app);
$response = $this->client->api->get($url, [], $data ? json_encode($data) : null);
$this->client->maybeThrowApiExceptions($response);
$data = $this->client->getJsonFromResponse($response);
return $data['branchers'];
}
/**
* Create a brancher app for given parent app.
*
* @param string $app Name of the parent app
* @param array|null $data Extra data to be provided
* @return string Name of the brancher app
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function create(string $app, ?array $data = null): string
{
$url = sprintf(App::V2_BRANCHER_APP_URL, $app);
$response = $this->client->api->post($url, [], $data ? json_encode($data) : null);
$this->client->maybeThrowApiExceptions($response);
$data = $this->client->getJsonFromResponse($response);
return $data['name'];
}
/**
* Update a Brancher app.
*
* Currently, only the `labels` field is supported.
*
* @param string $name Name of the Brancher node
* @param array $data Data to be updated
* @return array Updated data
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function update(string $name, array $data): array
{
$url = sprintf(App::V2_BRANCHER_DETAIL_URL, $name);
$response = $this->client->api->put($url, [], json_encode($data));
$this->client->maybeThrowApiExceptions($response);
/** @var array $data */
$data = $this->client->getJsonFromResponse($response);
return $data;
}
/**
* Cancel an brancher app.
*
* @param string $app Name of the brancher app
* @return void
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function cancel(string $app): void
{
$url = sprintf(App::V2_APP_CANCEL_URL, $app);
$response = $this->client->api->post($url);
$this->client->maybeThrowApiExceptions($response);
}
}