Skip to content

Commit 7305250

Browse files
authored
feat: add ticket DELETE endpoint (#203)
* feat: add ticket DELETE endpoint * remove duplicated code
1 parent b692e1e commit 7305250

24 files changed

+134
-112
lines changed

src/Api/SelfService/Attachments.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Psr\Http\Message\StreamInterface;
66
use SupportPal\ApiClient\Exception\HttpResponseException;
77
use SupportPal\ApiClient\Exception\InvalidArgumentException;
8-
use SupportPal\ApiClient\Exception\MissingIdentifierException;
98
use SupportPal\ApiClient\Http\SelfServiceClient;
109
use SupportPal\ApiClient\Model\Collection;
1110
use SupportPal\ApiClient\Model\SelfService\Attachment;
@@ -41,15 +40,10 @@ public function getAttachment(int $id): Attachment
4140

4241
/**
4342
* @throws HttpResponseException
44-
* @throws MissingIdentifierException
4543
*/
46-
public function downloadAttachment(Attachment $attachment): StreamInterface
44+
public function downloadAttachment(int $id): StreamInterface
4745
{
48-
if (! isset($attachment->id)) {
49-
throw new MissingIdentifierException('missing attachment identifier');
50-
}
51-
52-
return $this->getApiClient()->downloadAttachment($attachment->id)->getBody();
46+
return $this->getApiClient()->downloadAttachment($id)->getBody();
5347
}
5448

5549
/**

src/Api/Ticket/Attachments.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Psr\Http\Message\StreamInterface;
66
use SupportPal\ApiClient\Exception\HttpResponseException;
77
use SupportPal\ApiClient\Exception\InvalidArgumentException;
8-
use SupportPal\ApiClient\Exception\MissingIdentifierException;
98
use SupportPal\ApiClient\Http\TicketClient;
109
use SupportPal\ApiClient\Model\Collection;
1110
use SupportPal\ApiClient\Model\Ticket\Attachment;
@@ -23,7 +22,7 @@ public function getAttachments(array $queryParameters = []): Collection
2322
{
2423
$response = $this->getApiClient()->getAttachments($queryParameters);
2524
$body = $this->decodeBody($response);
26-
$models = array_map([$this, 'createAttachment'], $body['data']);
25+
$models = array_map([$this, 'createAttachmentModel'], $body['data']);
2726

2827
return $this->createCollection($body['count'], $models);
2928
}
@@ -35,26 +34,21 @@ public function getAttachment(int $attachmentId): Attachment
3534
{
3635
$response = $this->getApiClient()->getAttachment($attachmentId);
3736

38-
return $this->createAttachment($this->decodeBody($response)['data']);
37+
return $this->createAttachmentModel($this->decodeBody($response)['data']);
3938
}
4039

4140
/**
4241
* @throws HttpResponseException
43-
* @throws MissingIdentifierException
4442
*/
45-
public function downloadAttachment(Attachment $attachment): StreamInterface
43+
public function downloadAttachment(int $id): StreamInterface
4644
{
47-
if (! isset($attachment->id)) {
48-
throw new MissingIdentifierException('missing attachment identifier');
49-
}
50-
51-
return $this->getApiClient()->downloadAttachment($attachment->id)->getBody();
45+
return $this->getApiClient()->downloadAttachment($id)->getBody();
5246
}
5347

5448
/**
5549
* @param array<mixed> $data
5650
*/
57-
private function createAttachment(array $data): Attachment
51+
private function createAttachmentModel(array $data): Attachment
5852
{
5953
return new Attachment($data);
6054
}

src/Api/Ticket/CustomFields.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ public function getCustomFields(array $queryParameters = []): Collection
2222
{
2323
$response = $this->getApiClient()->getCustomFields($queryParameters);
2424
$body = $this->decodeBody($response);
25-
$models = array_map([$this, 'createTicketCustomField'], $body['data']);
25+
$models = array_map([$this, 'createTicketCustomFieldModel'], $body['data']);
2626

2727
return $this->createCollection($body['count'], $models);
2828
}
2929

3030
/**
3131
* @throws HttpResponseException
3232
*/
33-
public function getCustomField(int $customFieldId): CustomField
33+
public function getCustomField(int $id): CustomField
3434
{
35-
$response = $this->getApiClient()->getCustomField($customFieldId);
35+
$response = $this->getApiClient()->getCustomField($id);
3636

37-
return $this->createTicketCustomField($this->decodeBody($response)['data']);
37+
return $this->createTicketCustomFieldModel($this->decodeBody($response)['data']);
3838
}
3939

4040
/**
4141
* @param array<mixed> $data
4242
*/
43-
private function createTicketCustomField(array $data): TicketCustomField
43+
private function createTicketCustomFieldModel(array $data): TicketCustomField
4444
{
4545
return new TicketCustomField($data);
4646
}

src/Api/Ticket/Departments.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ public function getDepartments(array $queryParameters = []): Collection
2121
{
2222
$response = $this->getApiClient()->getDepartments($queryParameters);
2323
$body = $this->decodeBody($response);
24-
$models = array_map([$this, 'createDepartment'], $body['data']);
24+
$models = array_map([$this, 'createDepartmentModel'], $body['data']);
2525

2626
return $this->createCollection($body['count'], $models);
2727
}
2828

2929
/**
3030
* @throws HttpResponseException
3131
*/
32-
public function getDepartment(int $departmentId): Department
32+
public function getDepartment(int $id): Department
3333
{
34-
$response = $this->getApiClient()->getDepartment($departmentId);
34+
$response = $this->getApiClient()->getDepartment($id);
3535

36-
return $this->createDepartment($this->decodeBody($response)['data']);
36+
return $this->createDepartmentModel($this->decodeBody($response)['data']);
3737
}
3838

3939
/**
4040
* @param array<mixed> $data
4141
*/
42-
private function createDepartment(array $data): Department
42+
private function createDepartmentModel(array $data): Department
4343
{
4444
return new Department($data);
4545
}

src/Api/Ticket/Messages.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ public function getMessages(int $ticketId, array $queryParameters = []): Collect
2323
$queryParameters['ticket_id'] = $ticketId;
2424
$response = $this->getApiClient()->getMessages($queryParameters);
2525
$body = $this->decodeBody($response);
26-
$models = array_map([ $this, 'createMessageModel' ], $body['data']);
26+
$models = array_map([$this, 'createMessageModel'], $body['data']);
2727

2828
return $this->createCollection($body['count'], $models);
2929
}
3030

3131
/**
3232
* @throws HttpResponseException
3333
*/
34-
public function getMessage(int $messageId): Message
34+
public function getMessage(int $id): Message
3535
{
36-
$response = $this->getApiClient()->getMessage($messageId);
36+
$response = $this->getApiClient()->getMessage($id);
3737

3838
return $this->createMessageModel($this->decodeBody($response)['data']);
3939
}

src/Api/Ticket/Priorities.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function getPriorities(array $queryParameters = []): Collection
2121
{
2222
$response = $this->getApiClient()->getPriorities($queryParameters);
2323
$body = $this->decodeBody($response);
24-
$models = array_map([$this, 'createPriority'], $body['data']);
24+
$models = array_map([$this, 'createPriorityModel'], $body['data']);
2525

2626
return $this->createCollection($body['count'], $models);
2727
}
@@ -33,13 +33,13 @@ public function getPriority(int $priorityId): Priority
3333
{
3434
$response = $this->getApiClient()->getPriority($priorityId);
3535

36-
return $this->createPriority($this->decodeBody($response)['data']);
36+
return $this->createPriorityModel($this->decodeBody($response)['data']);
3737
}
3838

3939
/**
4040
* @param array<mixed> $data
4141
*/
42-
private function createPriority(array $data): Priority
42+
private function createPriorityModel(array $data): Priority
4343
{
4444
return new Priority($data);
4545
}

src/Api/Ticket/Statuses.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function getStatuses(array $queryParameters = []): Collection
2121
{
2222
$response = $this->getApiClient()->getStatuses($queryParameters);
2323
$body = $this->decodeBody($response);
24-
$models = array_map([$this, 'createStatus'], $body['data']);
24+
$models = array_map([$this, 'createStatusModel'], $body['data']);
2525

2626
return $this->createCollection($body['count'], $models);
2727
}
@@ -33,13 +33,13 @@ public function getStatus(int $statusId): Status
3333
{
3434
$response = $this->getApiClient()->getStatus($statusId);
3535

36-
return $this->createStatus($this->decodeBody($response)['data']);
36+
return $this->createStatusModel($this->decodeBody($response)['data']);
3737
}
3838

3939
/**
4040
* @param array<mixed> $data
4141
*/
42-
private function createStatus(array $data): Status
42+
private function createStatusModel(array $data): Status
4343
{
4444
return new Status($data);
4545
}

src/Api/Ticket/Tickets.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ public function updateTicket(int $id, UpdateTicket $data): Ticket
5959
return $this->createTicketModel($this->decodeBody($response)['data']);
6060
}
6161

62+
/**
63+
* @throws HttpResponseException
64+
*/
65+
public function deleteTicket(int $id): bool
66+
{
67+
$response = $this->getApiClient()->deleteTicket($id);
68+
69+
return $this->decodeBody($response)['status'] === 'success';
70+
}
71+
6272
/**
6373
* @param array<mixed> $data
6474
*/

src/Http/Ticket/ChannelSettingsApis.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ trait ChannelSettingsApis
1414
use ApiClientAware;
1515

1616
/**
17-
* @param string $channel
18-
* @return ResponseInterface
1917
* @throws HttpResponseException
2018
*/
2119
public function getChannelSettings(string $channel): ResponseInterface

src/Http/Ticket/CustomFieldApis.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ trait CustomFieldApis
1313

1414
/**
1515
* @param array<mixed> $queryParameters
16-
* @return ResponseInterface
1716
* @throws HttpResponseException
1817
*/
1918
public function getCustomFields(array $queryParameters): ResponseInterface
@@ -22,15 +21,10 @@ public function getCustomFields(array $queryParameters): ResponseInterface
2221
}
2322

2423
/**
25-
* @param int $customFieldId
26-
* @return ResponseInterface
2724
* @throws HttpResponseException
2825
*/
29-
public function getCustomField(int $customFieldId): ResponseInterface
26+
public function getCustomField(int $id): ResponseInterface
3027
{
31-
return $this->prepareAndSendGetRequest(
32-
ApiDictionary::TICKET_CUSTOMFIELD . '/' . $customFieldId,
33-
[]
34-
);
28+
return $this->prepareAndSendGetRequest(ApiDictionary::TICKET_CUSTOMFIELD . '/' . $id, []);
3529
}
3630
}

0 commit comments

Comments
 (0)