|
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\Support\Repository; |
|
13
|
|
|
|
|
14
|
|
|
use Linode\Entity; |
|
15
|
|
|
use Linode\Internal\AbstractRepository; |
|
16
|
|
|
use Linode\Support\SupportTicket; |
|
17
|
|
|
use Linode\Support\SupportTicketRepositoryInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
|
21
|
|
|
*/ |
|
22
|
|
|
class SupportTicketRepository extends AbstractRepository implements SupportTicketRepositoryInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public function createTicket(array $parameters = []): SupportTicket |
|
25
|
|
|
{ |
|
26
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
|
27
|
|
|
$contents = $response->getBody()->getContents(); |
|
28
|
|
|
$json = json_decode($contents, true); |
|
29
|
|
|
|
|
30
|
|
|
return new SupportTicket($this->client, $json); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function createTicketAttachment(int $ticketId, string $file): void |
|
34
|
|
|
{ |
|
35
|
|
|
$options = [ |
|
36
|
|
|
'multipart' => [ |
|
37
|
|
|
'name' => 'file', |
|
38
|
|
|
'contents' => fopen($file, 'r'), |
|
39
|
|
|
], |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
$this->client->post(sprintf('%s/%s/attachments', $this->getBaseUri(), $ticketId), [], $options); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function closeTicket(int $ticketId): void |
|
46
|
|
|
{ |
|
47
|
|
|
$this->client->post(sprintf('%s/%s/close', $this->getBaseUri(), $ticketId)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
protected function getBaseUri(): string |
|
51
|
|
|
{ |
|
52
|
|
|
return '/support/tickets'; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function getSupportedFields(): array |
|
56
|
|
|
{ |
|
57
|
|
|
return [ |
|
58
|
|
|
SupportTicket::FIELD_ID, |
|
59
|
|
|
SupportTicket::FIELD_SUMMARY, |
|
60
|
|
|
SupportTicket::FIELD_OPENED_BY, |
|
61
|
|
|
SupportTicket::FIELD_OPENED, |
|
62
|
|
|
SupportTicket::FIELD_DESCRIPTION, |
|
63
|
|
|
SupportTicket::FIELD_ENTITY, |
|
64
|
|
|
SupportTicket::FIELD_GRAVATAR_ID, |
|
65
|
|
|
SupportTicket::FIELD_STATUS, |
|
66
|
|
|
SupportTicket::FIELD_CLOSABLE, |
|
67
|
|
|
SupportTicket::FIELD_UPDATED_BY, |
|
68
|
|
|
SupportTicket::FIELD_UPDATED, |
|
69
|
|
|
SupportTicket::FIELD_CLOSED, |
|
70
|
|
|
SupportTicket::FIELD_ATTACHMENTS, |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
protected function jsonToEntity(array $json): Entity |
|
75
|
|
|
{ |
|
76
|
|
|
return new SupportTicket($this->client, $json); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|