Skip to content

Commit

Permalink
Add support for message direction
Browse files Browse the repository at this point in the history
  • Loading branch information
jm-mailosaur committed Oct 13, 2022
1 parent 9fb8a85 commit 15b4dbb
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Operations/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ class Messages extends AOperation
* @param SearchCriteria $searchCriteria The search criteria to use in order to find a match.
* @param int $timeout Specify how long to wait for a matching result (in milliseconds).
* @param \DateTime $receivedAfter Limits results to only messages received after this date/time.
* @param string $dir Optionally limits results based on the direction (`Sent` or
* `Received`), with the default being `Received`.
*
* @return Message
* @throws MailosaurException
* @see https://mailosaur.com/docs/api/#operation/Messages_Get Retrieve a message docs
* @example https://mailosaur.com/docs/api/#operation/Messages_Get
*/
public function get($server, SearchCriteria $searchCriteria, $timeout = 10000, \DateTime $receivedAfter = null)
public function get($server, SearchCriteria $searchCriteria, $timeout = 10000, \DateTime $receivedAfter = null, $dir = null)
{
if (strlen($server) != 8) {
throw new MailosaurException('Must provide a valid Server ID.', 'invalid_request');
Expand All @@ -38,7 +40,7 @@ public function get($server, SearchCriteria $searchCriteria, $timeout = 10000, \
$datetime->sub(new \DateInterval('PT1H'));
}

$result = $this->search($server, $searchCriteria, 0, 1, $timeout, $receivedAfter);
$result = $this->search($server, $searchCriteria, 0, 1, $timeout, $receivedAfter, $dir);
return $this->getById($result->items[0]->id);
}

Expand Down Expand Up @@ -83,20 +85,23 @@ public function delete($id)
* @param int $page Used in conjunction with itemsPerPage to support pagination.
* @param int $itemsPerPage A limit on the number of results to be returned per page.
* Can be set between 1 and 1000 items, the default is 50.
* @param string $dir Optionally limits results based on the direction (`Sent` or
* `Received`), with the default being `Received`.
* @param \DateTime $receivedAfter Limits results to only messages received after this date/time.
*
* @return MessageListResult
* @throws MailosaurException
* @see https://mailosaur.com/docs/api/#operation/Messages_List List all messages
* @example https://mailosaur.com/docs/api/#operation/Messages_List
*/
public function all($server, $page = 0, $itemsPerPage = 50, \DateTime $receivedAfter = null)
public function all($server, $page = 0, $itemsPerPage = 50, \DateTime $receivedAfter = null, $dir = null)
{
$path = 'api/messages?' . http_build_query(array(
'server' => $server,
'page' => $page,
'itemsPerPage' => $itemsPerPage,
'receivedAfter' => ($receivedAfter != null) ? $receivedAfter->format(\DateTime::ATOM) : null
'receivedAfter' => ($receivedAfter != null) ? $receivedAfter->format(\DateTime::ATOM) : null,
'dir' => ($dir != null) ? $dir : ''
));

$messagesResponse = $this->request($path);
Expand Down Expand Up @@ -134,19 +139,22 @@ public function deleteAll($server)
* @param \DateTime $receivedAfter Limits results to only messages received after this date/time.
* @param bool $errorOnTimeout When set to false, an error will not be throw if timeout is reached
* (default: true).
* @param string $dir Optionally limits results based on the direction (`Sent` or
* `Received`), with the default being `Received`.
*
* @return MessageListResult
* @throws MailosaurException
*/
public function search($server, SearchCriteria $searchCriteria, $page = 0, $itemsPerPage = 50, $timeout = null, \DateTime $receivedAfter = null, $errorOnTimeout = true)
public function search($server, SearchCriteria $searchCriteria, $page = 0, $itemsPerPage = 50, $timeout = null, \DateTime $receivedAfter = null, $errorOnTimeout = true, $dir = null)
{
$payload = $searchCriteria->toJsonString();

$path = 'api/messages/search?' . http_build_query(array(
'server' => $server,
'page' => $page,
'itemsPerPage' => $itemsPerPage,
'receivedAfter' => ($receivedAfter != null) ? $receivedAfter->format(\DateTime::ATOM) : null
'receivedAfter' => ($receivedAfter != null) ? $receivedAfter->format(\DateTime::ATOM) : null,
'dir' => ($dir != null) ? $dir : ''
));

$pollCount = 0;
Expand Down

0 comments on commit 15b4dbb

Please sign in to comment.