Jobs setup

This commit is contained in:
2023-06-12 21:14:07 -04:00
parent 03c1dac2f2
commit 88f91c4bd5
60 changed files with 965 additions and 495 deletions

View File

@ -0,0 +1,43 @@
<?php
namespace ProVM\Service;
use ProVM\Exception\Response\EmptyResponse;
use ProVM\Exception\Response\MissingResponse;
use Psr\Log\LoggerInterface;
use function Safe\json_decode;
class Messages
{
public function __construct(protected Communicator $communicator, protected LoggerInterface $logger) {}
public function get(int $message_id): object
{
$this->logger->info("Getting message {$message_id}");
$uri = "/message/{$message_id}";
$response = $this->communicator->get($uri);
$body = $response->getBody()->getContents();
if (trim($body) === '') {
throw new EmptyResponse($uri);
}
$json = json_decode($body);
if (!isset($json->message)) {
throw new MissingResponse('message');
}
return $json->message;
}
public function grabAttachments(string $message_uid): int
{
$this->logger->info("Grabbing attachments for message UID {$message_uid}");
$uri = '/attachments/grab';
$response = $this->communicator->put($uri, ['messages' => [$message_uid]]);
$body = $response->getBody()->getContents();
if (trim($body) === '') {
return 0;
}
$json = json_decode($body);
if (!isset($json->total)) {
return 0;
}
return $json->total;
}
}