Skip to content

Commit 0468f73

Browse files
authored
Add SESv2 suppressed destination deletion and retrieval methods (#1834)
1 parent 53b605b commit 0468f73

16 files changed

+646
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## NOT RELEASED
44

5+
### Added
6+
7+
- Added support for `getSuppressedDestination` and `deleteSuppressedDestination` to manage SESv2 suppression list entries.
8+
59
## 1.10.0
610

711
### Added

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"extra": {
2929
"branch-alias": {
30-
"dev-master": "1.10-dev"
30+
"dev-master": "1.11-dev"
3131
}
3232
}
3333
}

src/Enum/SuppressionListReason.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace AsyncAws\Ses\Enum;
4+
5+
/**
6+
* The reason that the address was added to the suppression list for your account. The value can be one of the
7+
* following:
8+
*
9+
* - `COMPLAINT` – Amazon SES added an email address to the suppression list for your account because a message sent
10+
* to that address results in a complaint.
11+
* - `BOUNCE` – Amazon SES added an email address to the suppression list for your account because a message sent to
12+
* that address results in a hard bounce.
13+
*/
14+
final class SuppressionListReason
15+
{
16+
public const BOUNCE = 'BOUNCE';
17+
public const COMPLAINT = 'COMPLAINT';
18+
19+
public static function exists(string $value): bool
20+
{
21+
return isset([
22+
self::BOUNCE => true,
23+
self::COMPLAINT => true,
24+
][$value]);
25+
}
26+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace AsyncAws\Ses\Input;
4+
5+
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Input;
7+
use AsyncAws\Core\Request;
8+
use AsyncAws\Core\Stream\StreamFactory;
9+
10+
/**
11+
* A request to remove an email address from the suppression list for your account.
12+
*/
13+
final class DeleteSuppressedDestinationRequest extends Input
14+
{
15+
/**
16+
* The suppressed email destination to remove from the account suppression list.
17+
*
18+
* @required
19+
*
20+
* @var string|null
21+
*/
22+
private $emailAddress;
23+
24+
/**
25+
* @param array{
26+
* EmailAddress?: string,
27+
* '@region'?: string|null,
28+
* } $input
29+
*/
30+
public function __construct(array $input = [])
31+
{
32+
$this->emailAddress = $input['EmailAddress'] ?? null;
33+
parent::__construct($input);
34+
}
35+
36+
/**
37+
* @param array{
38+
* EmailAddress?: string,
39+
* '@region'?: string|null,
40+
* }|DeleteSuppressedDestinationRequest $input
41+
*/
42+
public static function create($input): self
43+
{
44+
return $input instanceof self ? $input : new self($input);
45+
}
46+
47+
public function getEmailAddress(): ?string
48+
{
49+
return $this->emailAddress;
50+
}
51+
52+
/**
53+
* @internal
54+
*/
55+
public function request(): Request
56+
{
57+
// Prepare headers
58+
$headers = [
59+
'Content-Type' => 'application/json',
60+
'Accept' => 'application/json',
61+
];
62+
63+
// Prepare query
64+
$query = [];
65+
66+
// Prepare URI
67+
$uri = [];
68+
if (null === $v = $this->emailAddress) {
69+
throw new InvalidArgument(\sprintf('Missing parameter "EmailAddress" for "%s". The value cannot be null.', __CLASS__));
70+
}
71+
$uri['EmailAddress'] = $v;
72+
$uriString = '/v2/email/suppression/addresses/' . rawurlencode($uri['EmailAddress']);
73+
74+
// Prepare Body
75+
$body = '';
76+
77+
// Return the Request
78+
return new Request('DELETE', $uriString, $query, $headers, StreamFactory::create($body));
79+
}
80+
81+
public function setEmailAddress(?string $value): self
82+
{
83+
$this->emailAddress = $value;
84+
85+
return $this;
86+
}
87+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace AsyncAws\Ses\Input;
4+
5+
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Input;
7+
use AsyncAws\Core\Request;
8+
use AsyncAws\Core\Stream\StreamFactory;
9+
10+
/**
11+
* A request to retrieve information about an email address that's on the suppression list for your account.
12+
*/
13+
final class GetSuppressedDestinationRequest extends Input
14+
{
15+
/**
16+
* The email address that's on the account suppression list.
17+
*
18+
* @required
19+
*
20+
* @var string|null
21+
*/
22+
private $emailAddress;
23+
24+
/**
25+
* @param array{
26+
* EmailAddress?: string,
27+
* '@region'?: string|null,
28+
* } $input
29+
*/
30+
public function __construct(array $input = [])
31+
{
32+
$this->emailAddress = $input['EmailAddress'] ?? null;
33+
parent::__construct($input);
34+
}
35+
36+
/**
37+
* @param array{
38+
* EmailAddress?: string,
39+
* '@region'?: string|null,
40+
* }|GetSuppressedDestinationRequest $input
41+
*/
42+
public static function create($input): self
43+
{
44+
return $input instanceof self ? $input : new self($input);
45+
}
46+
47+
public function getEmailAddress(): ?string
48+
{
49+
return $this->emailAddress;
50+
}
51+
52+
/**
53+
* @internal
54+
*/
55+
public function request(): Request
56+
{
57+
// Prepare headers
58+
$headers = [
59+
'Content-Type' => 'application/json',
60+
'Accept' => 'application/json',
61+
];
62+
63+
// Prepare query
64+
$query = [];
65+
66+
// Prepare URI
67+
$uri = [];
68+
if (null === $v = $this->emailAddress) {
69+
throw new InvalidArgument(\sprintf('Missing parameter "EmailAddress" for "%s". The value cannot be null.', __CLASS__));
70+
}
71+
$uri['EmailAddress'] = $v;
72+
$uriString = '/v2/email/suppression/addresses/' . rawurlencode($uri['EmailAddress']);
73+
74+
// Prepare Body
75+
$body = '';
76+
77+
// Return the Request
78+
return new Request('GET', $uriString, $query, $headers, StreamFactory::create($body));
79+
}
80+
81+
public function setEmailAddress(?string $value): self
82+
{
83+
$this->emailAddress = $value;
84+
85+
return $this;
86+
}
87+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace AsyncAws\Ses\Result;
4+
5+
use AsyncAws\Core\Result;
6+
7+
/**
8+
* An HTTP 200 response if the request succeeds, or an error message if the request fails.
9+
*/
10+
class DeleteSuppressedDestinationResponse extends Result
11+
{
12+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace AsyncAws\Ses\Result;
4+
5+
use AsyncAws\Core\Response;
6+
use AsyncAws\Core\Result;
7+
use AsyncAws\Ses\ValueObject\SuppressedDestination;
8+
use AsyncAws\Ses\ValueObject\SuppressedDestinationAttributes;
9+
10+
/**
11+
* Information about the suppressed email address.
12+
*/
13+
class GetSuppressedDestinationResponse extends Result
14+
{
15+
/**
16+
* An object containing information about the suppressed email address.
17+
*
18+
* @var SuppressedDestination
19+
*/
20+
private $suppressedDestination;
21+
22+
public function getSuppressedDestination(): SuppressedDestination
23+
{
24+
$this->initialize();
25+
26+
return $this->suppressedDestination;
27+
}
28+
29+
protected function populateResult(Response $response): void
30+
{
31+
$data = $response->toArray();
32+
33+
$this->suppressedDestination = $this->populateResultSuppressedDestination($data['SuppressedDestination']);
34+
}
35+
36+
private function populateResultSuppressedDestination(array $json): SuppressedDestination
37+
{
38+
return new SuppressedDestination([
39+
'EmailAddress' => (string) $json['EmailAddress'],
40+
'Reason' => (string) $json['Reason'],
41+
'LastUpdateTime' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['LastUpdateTime'])),
42+
'Attributes' => empty($json['Attributes']) ? null : $this->populateResultSuppressedDestinationAttributes($json['Attributes']),
43+
]);
44+
}
45+
46+
private function populateResultSuppressedDestinationAttributes(array $json): SuppressedDestinationAttributes
47+
{
48+
return new SuppressedDestinationAttributes([
49+
'MessageId' => isset($json['MessageId']) ? (string) $json['MessageId'] : null,
50+
'FeedbackId' => isset($json['FeedbackId']) ? (string) $json['FeedbackId'] : null,
51+
]);
52+
}
53+
}

src/SesClient.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
use AsyncAws\Ses\Exception\NotFoundException;
1616
use AsyncAws\Ses\Exception\SendingPausedException;
1717
use AsyncAws\Ses\Exception\TooManyRequestsException;
18+
use AsyncAws\Ses\Input\DeleteSuppressedDestinationRequest;
19+
use AsyncAws\Ses\Input\GetSuppressedDestinationRequest;
1820
use AsyncAws\Ses\Input\SendEmailRequest;
21+
use AsyncAws\Ses\Result\DeleteSuppressedDestinationResponse;
22+
use AsyncAws\Ses\Result\GetSuppressedDestinationResponse;
1923
use AsyncAws\Ses\Result\SendEmailResponse;
2024
use AsyncAws\Ses\ValueObject\Destination;
2125
use AsyncAws\Ses\ValueObject\EmailContent;
@@ -24,6 +28,60 @@
2428

2529
class SesClient extends AbstractApi
2630
{
31+
/**
32+
* Removes an email address from the suppression list for your account.
33+
*
34+
* @see https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_DeleteSuppressedDestination.html
35+
* @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2019-09-27.html#deletesuppresseddestination
36+
*
37+
* @param array{
38+
* EmailAddress: string,
39+
* '@region'?: string|null,
40+
* }|DeleteSuppressedDestinationRequest $input
41+
*
42+
* @throws NotFoundException
43+
* @throws BadRequestException
44+
* @throws TooManyRequestsException
45+
*/
46+
public function deleteSuppressedDestination($input): DeleteSuppressedDestinationResponse
47+
{
48+
$input = DeleteSuppressedDestinationRequest::create($input);
49+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'DeleteSuppressedDestination', 'region' => $input->getRegion(), 'exceptionMapping' => [
50+
'NotFoundException' => NotFoundException::class,
51+
'BadRequestException' => BadRequestException::class,
52+
'TooManyRequestsException' => TooManyRequestsException::class,
53+
]]));
54+
55+
return new DeleteSuppressedDestinationResponse($response);
56+
}
57+
58+
/**
59+
* Retrieves information about a specific email address that's on the suppression list for your account.
60+
*
61+
* @see https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetSuppressedDestination.html
62+
* @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2019-09-27.html#getsuppresseddestination
63+
*
64+
* @param array{
65+
* EmailAddress: string,
66+
* '@region'?: string|null,
67+
* }|GetSuppressedDestinationRequest $input
68+
*
69+
* @throws BadRequestException
70+
* @throws TooManyRequestsException
71+
* @throws NotFoundException
72+
*/
73+
public function getSuppressedDestination($input): GetSuppressedDestinationResponse
74+
{
75+
$input = GetSuppressedDestinationRequest::create($input);
76+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'GetSuppressedDestination', 'region' => $input->getRegion(), 'exceptionMapping' => [
77+
'BadRequestException' => BadRequestException::class,
78+
'TooManyRequestsException' => TooManyRequestsException::class,
79+
'NotFoundException' => NotFoundException::class,
80+
]]));
81+
82+
return new GetSuppressedDestinationResponse($response);
83+
}
84+
2785
/**
2886
* Sends an email message. You can use the Amazon SES API v2 to send the following types of messages:
2987
*

0 commit comments

Comments
 (0)