Skip to content

Commit

Permalink
Merge pull request #4 from gsteel/client-clean-up
Browse files Browse the repository at this point in the history
Client clean up
  • Loading branch information
gsteel authored Feb 18, 2022
2 parents 8f27c94 + 1c65501 commit b7267ee
Show file tree
Hide file tree
Showing 56 changed files with 3,919 additions and 3,224 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

- name: "Psalm"
if: hashFiles('psalm.xml') != ''
run: vendor/bin/psalm --output-format=github
run: vendor/bin/psalm --shepherd --stats --output-format=github

run-unit-tests:

Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
composer-options: "${{ matrix.composer-options }}"

- name: "Run Tests"
run: php ./vendor/bin/phpunit --testsuite="Unit" --coverage-clover=coverage.xml
run: php ./vendor/bin/phpunit --coverage-clover=coverage.xml

- name: "Upload Coverage to CodeCov"
uses: codecov/[email protected]
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
},
"autoload-dev": {
"psr-4": {
"Postmark\\Tests\\Legacy\\": "tests/Legacy/",
"Postmark\\Tests\\Unit\\": "tests/Unit/"
}
},
Expand Down
1 change: 0 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<!-- Paths to check -->
<file>src</file>
<file>tests</file>
<exclude-pattern>tests/Legacy/*.php</exclude-pattern>

<!-- Inherit rules from Doctrine Coding Standard -->
<rule ref="Doctrine" />
Expand Down
3 changes: 0 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
<testsuites>
<testsuite name="Legacy Tests">
<directory>tests/Legacy</directory>
</testsuite>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
Expand Down
70 changes: 1 addition & 69 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,70 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.20.0@f82a70e7edfc6cf2705e9374c8a0b6a974a779ed">
<file src="src/Postmark/PostmarkAdminClient.php">
<MissingParamType occurrences="2">
<code>$offset</code>
<code>$offset</code>
</MissingParamType>
<MixedAssignment occurrences="2">
<code>$query['offset']</code>
<code>$query['offset']</code>
</MixedAssignment>
</file>
<file src="src/Postmark/PostmarkClient.php">
<InvalidIterator occurrences="1">
<code>$metadata</code>
</InvalidIterator>
<InvalidParamDefault occurrences="2">
<code>string</code>
<code>string</code>
</InvalidParamDefault>
<InvalidReturnStatement occurrences="1">
<code>new DynamicResponseModel($this-&gt;processRestRequest('GET', "/bounces/$id/dump"))</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<code>string</code>
</InvalidReturnType>
<MissingParamType occurrences="1">
<code>$headers</code>
</MissingParamType>
<MissingReturnType occurrences="1">
<code>fixHeaders</code>
</MissingReturnType>
<MixedArgument occurrences="2">
<code>$emailIdx</code>
<code>$emailIdx</code>
</MixedArgument>
<MixedArrayAssignment occurrences="2">
<code>$email[$emailIdx]</code>
<code>$email[$emailIdx]</code>
</MixedArrayAssignment>
<MixedAssignment occurrences="16">
<code>$body['Headers']</code>
<code>$body['Headers']</code>
<code>$email</code>
<code>$email</code>
<code>$emailIdx</code>
<code>$emailIdx</code>
<code>$emailValue</code>
<code>$emailValue</code>
<code>$email[$emailIdx]</code>
<code>$email[$emailIdx]</code>
<code>$final[]</code>
<code>$key</code>
<code>$key</code>
<code>$query["metadata_$key"]</code>
<code>$value</code>
<code>$value</code>
</MixedAssignment>
<MixedInferredReturnType occurrences="2">
<code>DynamicResponseModel</code>
<code>DynamicResponseModel</code>
</MixedInferredReturnType>
<UndefinedDocblockClass occurrences="4">
<code>HttpAuth</code>
<code>HttpAuth</code>
<code>WebhookConfigurationTriggers</code>
<code>WebhookConfigurationTriggers</code>
</UndefinedDocblockClass>
</file>
</files>
<files psalm-version="4.20.0@f82a70e7edfc6cf2705e9374c8a0b6a974a779ed"/>
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<directory name="tests" />
<ignoreFiles>
<directory name="vendor" />
<directory name="tests/Legacy" />
</ignoreFiles>
</projectFiles>

Expand Down
99 changes: 99 additions & 0 deletions src/Postmark/ClientBehaviour/Bounces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

declare(strict_types=1);

namespace Postmark\ClientBehaviour;

use Postmark\Models\DynamicResponseModel;

use function sprintf;

/** @internal \Postmark */
trait Bounces
{
/**
* Get a batch of bounces to be processed.
*
* @link http://developer.postmarkapp.com/developer-api-bounce.html#bounce-types)
*
* @param int $count Number of bounces to retrieve
* @param int $offset How many bounces to skip (when paging through bounces.)
* @param string|null $type The bounce type.
* @param bool|null $inactive Specifies if the bounce caused Postmark to deactivate this email.
* @param string|null $emailFilter Filter by email address
* @param string|null $tag Filter by tag
* @param string|null $messageID Filter by MessageID
* @param string|null $fromdate Filter for bounces after is date.
* @param string|null $todate Filter for bounces before this date.
* @param string|null $messagestream Filter by Message Stream ID. If null, the default "outbound"
* transactional stream will be used.
*/
public function getBounces(
int $count = 100,
int $offset = 0,
?string $type = null,
?bool $inactive = null,
?string $emailFilter = null,
?string $tag = null,
?string $messageID = null,
?string $fromdate = null,
?string $todate = null,
?string $messagestream = null
): DynamicResponseModel {
$query = [];
$query['type'] = $type;
$query['inactive'] = $this->stringifyBoolean($inactive);
$query['emailFilter'] = $emailFilter;
$query['tag'] = $tag;
$query['messageID'] = $messageID;
$query['count'] = $count;
$query['offset'] = $offset;
$query['fromdate'] = $fromdate;
$query['todate'] = $todate;
$query['messagestream'] = $messagestream;

return new DynamicResponseModel($this->processRestRequest('GET', '/bounces', $query));
}

/**
* Locate information on a specific email bounce.
*
* If the $id value is greater than PHP_INT_MAX, the ID can be passed as a string.
*
* @param int|numeric-string $id The ID of the bounce to get.
*/
public function getBounce($id): DynamicResponseModel
{
return new DynamicResponseModel(
$this->processRestRequest('GET', sprintf('/bounces/%s', $id))
);
}

/**
* Get a "dump" for a specific bounce.
*
* If the $id value is greater than PHP_INT_MAX, the ID can be passed as a string.
*
* @param int|numeric-string $id The ID of the bounce for which we want a dump.
*/
public function getBounceDump($id): DynamicResponseModel
{
return new DynamicResponseModel(
$this->processRestRequest('GET', sprintf('/bounces/%s/dump', $id))
);
}

/**
* Cause the email address associated with a Bounce to be reactivated.
*
* If the $id value is greater than PHP_INT_MAX, the ID can be passed as a string.
*
* @param int|numeric-string $id The bounce which has a deactivated email address.
*/
public function activateBounce($id): DynamicResponseModel
{
return new DynamicResponseModel(
$this->processRestRequest('PUT', sprintf('/bounces/%s/activate', $id))
);
}
}
4 changes: 4 additions & 0 deletions src/Postmark/ClientBehaviour/Discovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/** @internal Postmark */
trait Discovery
{
/** @throws DiscoveryFailure */
private static function resolveHttpClient(?ClientInterface $client): ClientInterface
{
if ($client) {
Expand All @@ -29,6 +30,7 @@ private static function resolveHttpClient(?ClientInterface $client): ClientInter
}
}

/** @throws DiscoveryFailure */
private static function resolveRequestFactory(): RequestFactoryInterface
{
try {
Expand All @@ -38,6 +40,7 @@ private static function resolveRequestFactory(): RequestFactoryInterface
}
}

/** @throws DiscoveryFailure */
private static function resolveStreamFactory(): StreamFactoryInterface
{
try {
Expand All @@ -47,6 +50,7 @@ private static function resolveStreamFactory(): StreamFactoryInterface
}
}

/** @throws DiscoveryFailure */
private static function resolveUriFactory(): UriFactoryInterface
{
try {
Expand Down
136 changes: 136 additions & 0 deletions src/Postmark/ClientBehaviour/InboundMessages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

declare(strict_types=1);

namespace Postmark\ClientBehaviour;

use Postmark\Models\DynamicResponseModel;

use function sprintf;

/** @internal \Postmark */
trait InboundMessages
{
/**
* Get messages sent to the inbound email address associated with this Server.
*
* @param int $count The number of inbound messages to retrieve in the request (defaults to 100)
* @param int $offset The number of messages to 'skip' when 'paging' through messages (defaults to 0)
* @param string|null $recipient Filter by the message recipient
* @param string|null $fromEmail Filter by the message sender
* @param string|null $tag Filter by the message tag
* @param string|null $subject Filter by the message subject
* @param string|null $mailboxHash Filter by the mailboxHash
* @param string|null $status Filter by status ('blocked' or 'processed')
* @param string|null $fromdate Filter to messages on or after YYYY-MM-DD
* @param string|null $todate Filter to messages on or before YYYY-MM-DD
*/
public function getInboundMessages(
int $count = 100,
int $offset = 0,
?string $recipient = null,
?string $fromEmail = null,
?string $tag = null,
?string $subject = null,
?string $mailboxHash = null,
?string $status = null,
?string $fromdate = null,
?string $todate = null
): DynamicResponseModel {
$query = [];
$query['recipient'] = $recipient;
$query['fromemail'] = $fromEmail;
$query['tag'] = $tag;
$query['subject'] = $subject;
$query['mailboxhash'] = $mailboxHash;
$query['count'] = $count;
$query['status'] = $status;
$query['offset'] = $offset;
$query['fromdate'] = $fromdate;
$query['todate'] = $todate;

return new DynamicResponseModel($this->processRestRequest('GET', '/messages/inbound', $query));
}

/**
* Get details for a specific inbound message.
*
* @param string $id The ID of the message for which we went to get details.
*/
public function getInboundMessageDetails(string $id): DynamicResponseModel
{
return new DynamicResponseModel(
$this->processRestRequest('GET', sprintf('/messages/inbound/%s/details', $id))
);
}

/**
* Allow an inbound message to be processed, even though the filtering rules would normally
* prevent it from being processed.
*
* @param string $id The ID for a message that we wish to unblock.
*/
public function bypassInboundMessageRules(string $id): DynamicResponseModel
{
return new DynamicResponseModel(
$this->processRestRequest('PUT', sprintf('/messages/inbound/%s/bypass', $id))
);
}

/**
* Request that Postmark retry POSTing the specified message to the Server's Inbound Hook.
*
* @param string $id The ID for a message that we wish retry the inbound hook for.
*/
public function retryInboundMessageHook(string $id): DynamicResponseModel
{
return new DynamicResponseModel(
$this->processRestRequest('PUT', sprintf('/messages/inbound/%s/retry', $id))
);
}

/**
* Create an Inbound Rule to block messages from a single email address, or an entire domain.
*
* @param string $rule The email address (or domain) that will be blocked.
*/
public function createInboundRuleTrigger(string $rule): DynamicResponseModel
{
$body = [];
$body['Rule'] = $rule;

return new DynamicResponseModel(
$this->processRestRequest('POST', '/triggers/inboundrules', $body)
);
}

/**
* Get a list of all existing Inbound Rule Triggers.
*
* @param int $count The number of rule triggers to return with this request.
* @param int $offset The number of triggers to 'skip' when 'paging' through rule triggers.
*/
public function listInboundRuleTriggers(int $count = 100, int $offset = 0): DynamicResponseModel
{
$query = [];

$query['count'] = $count;
$query['offset'] = $offset;

return new DynamicResponseModel(
$this->processRestRequest('GET', '/triggers/inboundrules', $query)
);
}

/**
* Delete an Inbound Rule Trigger.
*
* @param int $id The ID of the rule trigger we wish to delete.
*/
public function deleteInboundRuleTrigger(int $id): DynamicResponseModel
{
return new DynamicResponseModel(
$this->processRestRequest('DELETE', sprintf('/triggers/inboundrules/%s', $id))
);
}
}
Loading

0 comments on commit b7267ee

Please sign in to comment.