1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// --------------------------------------------------------------------- |
4
|
|
|
// |
5
|
|
|
// Copyright (C) 2018-2024 Artem Rodygin |
6
|
|
|
// |
7
|
|
|
// You should have received a copy of the MIT License along with |
8
|
|
|
// this file. If not, see <https://opensource.org/licenses/MIT>. |
9
|
|
|
// |
10
|
|
|
// --------------------------------------------------------------------- |
11
|
|
|
|
12
|
|
|
namespace Linode\Managed\Repository; |
13
|
|
|
|
14
|
|
|
use Linode\Entity; |
15
|
|
|
use Linode\Internal\AbstractRepository; |
16
|
|
|
use Linode\Managed\ManagedService; |
17
|
|
|
use Linode\Managed\ManagedServiceRepositoryInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
21
|
|
|
*/ |
22
|
|
|
class ManagedServiceRepository extends AbstractRepository implements ManagedServiceRepositoryInterface |
23
|
|
|
{ |
24
|
|
|
public function createManagedService(array $parameters = []): ManagedService |
25
|
|
|
{ |
26
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
27
|
|
|
$contents = $response->getBody()->getContents(); |
28
|
|
|
$json = json_decode($contents, true); |
29
|
|
|
|
30
|
|
|
return new ManagedService($this->client, $json); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function updateManagedService(int $serviceId, array $parameters = []): ManagedService |
34
|
|
|
{ |
35
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $serviceId), $parameters); |
36
|
|
|
$contents = $response->getBody()->getContents(); |
37
|
|
|
$json = json_decode($contents, true); |
38
|
|
|
|
39
|
|
|
return new ManagedService($this->client, $json); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function deleteManagedService(int $serviceId): void |
43
|
|
|
{ |
44
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $serviceId)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function disableManagedService(int $serviceId): ManagedService |
48
|
|
|
{ |
49
|
|
|
$response = $this->client->post(sprintf('%s/%s/disable', $this->getBaseUri(), $serviceId)); |
50
|
|
|
$contents = $response->getBody()->getContents(); |
51
|
|
|
$json = json_decode($contents, true); |
52
|
|
|
|
53
|
|
|
return new ManagedService($this->client, $json); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function enableManagedService(int $serviceId): ManagedService |
57
|
|
|
{ |
58
|
|
|
$response = $this->client->post(sprintf('%s/%s/enable', $this->getBaseUri(), $serviceId)); |
59
|
|
|
$contents = $response->getBody()->getContents(); |
60
|
|
|
$json = json_decode($contents, true); |
61
|
|
|
|
62
|
|
|
return new ManagedService($this->client, $json); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function getBaseUri(): string |
66
|
|
|
{ |
67
|
|
|
return '/managed/services'; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function getSupportedFields(): array |
71
|
|
|
{ |
72
|
|
|
return [ |
73
|
|
|
ManagedService::FIELD_ID, |
74
|
|
|
ManagedService::FIELD_STATUS, |
75
|
|
|
ManagedService::FIELD_SERVICE_TYPE, |
76
|
|
|
ManagedService::FIELD_LABEL, |
77
|
|
|
ManagedService::FIELD_ADDRESS, |
78
|
|
|
ManagedService::FIELD_CONSULTATION_GROUP, |
79
|
|
|
ManagedService::FIELD_TIMEOUT, |
80
|
|
|
ManagedService::FIELD_BODY, |
81
|
|
|
ManagedService::FIELD_NOTES, |
82
|
|
|
ManagedService::FIELD_REGION, |
83
|
|
|
ManagedService::FIELD_CREDENTIALS, |
84
|
|
|
ManagedService::FIELD_CREATED, |
85
|
|
|
ManagedService::FIELD_UPDATED, |
86
|
|
|
]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
protected function jsonToEntity(array $json): Entity |
90
|
|
|
{ |
91
|
|
|
return new ManagedService($this->client, $json); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|