|
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\ManagedContact; |
|
17
|
|
|
use Linode\Managed\ManagedContactRepositoryInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
|
21
|
|
|
*/ |
|
22
|
|
|
class ManagedContactRepository extends AbstractRepository implements ManagedContactRepositoryInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public function createManagedContact(array $parameters = []): ManagedContact |
|
25
|
|
|
{ |
|
26
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
|
27
|
|
|
$contents = $response->getBody()->getContents(); |
|
28
|
|
|
$json = json_decode($contents, true); |
|
29
|
|
|
|
|
30
|
|
|
return new ManagedContact($this->client, $json); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function updateManagedContact(int $contactId, array $parameters = []): ManagedContact |
|
34
|
|
|
{ |
|
35
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $contactId), $parameters); |
|
36
|
|
|
$contents = $response->getBody()->getContents(); |
|
37
|
|
|
$json = json_decode($contents, true); |
|
38
|
|
|
|
|
39
|
|
|
return new ManagedContact($this->client, $json); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function deleteManagedContact(int $contactId): void |
|
43
|
|
|
{ |
|
44
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $contactId)); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function getBaseUri(): string |
|
48
|
|
|
{ |
|
49
|
|
|
return '/managed/contacts'; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function getSupportedFields(): array |
|
53
|
|
|
{ |
|
54
|
|
|
return [ |
|
55
|
|
|
ManagedContact::FIELD_ID, |
|
56
|
|
|
ManagedContact::FIELD_NAME, |
|
57
|
|
|
ManagedContact::FIELD_EMAIL, |
|
58
|
|
|
ManagedContact::FIELD_PHONE, |
|
59
|
|
|
ManagedContact::FIELD_GROUP, |
|
60
|
|
|
ManagedContact::FIELD_UPDATED, |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function jsonToEntity(array $json): Entity |
|
65
|
|
|
{ |
|
66
|
|
|
return new ManagedContact($this->client, $json); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|