diff --git a/src/Contracts/Resources/MessageInterface.php b/src/Contracts/Resources/MessageInterface.php index 15cccd8..64eef66 100644 --- a/src/Contracts/Resources/MessageInterface.php +++ b/src/Contracts/Resources/MessageInterface.php @@ -2,6 +2,7 @@ namespace HeyJorgeDev\QStash\Contracts\Resources; +use HeyJorgeDev\QStash\Responses\MessageCancelResponse; use HeyJorgeDev\QStash\Responses\MessageEnqueueResponse; use HeyJorgeDev\QStash\Responses\MessagePublishResponse; use HeyJorgeDev\QStash\ValueObjects\Message; @@ -17,7 +18,7 @@ public function batch(); public function get(string $messageId): Message; - public function cancel(string $messageId); + public function cancel(string $messageId): MessageCancelResponse; /** * @param array $messageIds diff --git a/src/Resources/MessageResource.php b/src/Resources/MessageResource.php index 1b6cc2c..05a78f9 100644 --- a/src/Resources/MessageResource.php +++ b/src/Resources/MessageResource.php @@ -5,6 +5,7 @@ use HeyJorgeDev\QStash\Contracts\Resources\MessageInterface; use HeyJorgeDev\QStash\Contracts\TransporterInterface; use HeyJorgeDev\QStash\Exceptions\NotImplementedException; +use HeyJorgeDev\QStash\Responses\MessageCancelResponse; use HeyJorgeDev\QStash\Responses\MessageEnqueueResponse; use HeyJorgeDev\QStash\Responses\MessagePublishResponse; use HeyJorgeDev\QStash\ValueObjects\Message; @@ -75,9 +76,23 @@ public function get(string $messageId): Message throw NotImplementedException::askForContributions('get single message'); } - public function cancel(string $messageId) + public function cancel(string $messageId): MessageCancelResponse { - throw NotImplementedException::askForContributions('cancel a message'); + $request = Request::DELETE("/messages/{$messageId}"); + + $response = $this->transporter->send($request); + + if (! $response->isSuccessful()) { + return new MessageCancelResponse( + $response->statusCode, + $response->body + ); + } + + return new MessageCancelResponse( + $response->statusCode, + [] + ); } public function bulkCancel(array $messageIds) diff --git a/src/Responses/MessageCancelResponse.php b/src/Responses/MessageCancelResponse.php new file mode 100644 index 0000000..10d7198 --- /dev/null +++ b/src/Responses/MessageCancelResponse.php @@ -0,0 +1,23 @@ +statusCode === 202; + } + + public function getErrors(): array + { + return $this->errors; + } +}