From 8390bdd803be200a668831dd5d338e6bf7446309 Mon Sep 17 00:00:00 2001 From: iwahara <3982522+iwahara@users.noreply.github.com> Date: Tue, 1 Oct 2019 17:49:15 +0900 Subject: [PATCH] add unsubscribe delete parameter. --- src/Api/Suppression/Unsubscribe.php | 14 ++++++++++---- tests/Api/Suppression/UnsubscribeTest.php | 11 +++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Api/Suppression/Unsubscribe.php b/src/Api/Suppression/Unsubscribe.php index db6dbf4..762caae 100644 --- a/src/Api/Suppression/Unsubscribe.php +++ b/src/Api/Suppression/Unsubscribe.php @@ -84,17 +84,23 @@ class Unsubscribe extends HttpApi } /** - * @param string $domain Domain to delete unsubscribe for + * @param string $domain Domain to delete unsubscribe for * @param string $address Unsubscribe address - * + * @param string|null $tag Unsubscribe tag * @return DeleteResponse */ - public function delete(string $domain, string $address) + public function delete(string $domain, string $address, string $tag = null) { Assert::stringNotEmpty($domain); Assert::stringNotEmpty($address); + Assert::nullOrStringNotEmpty($tag); - $response = $this->httpDelete(sprintf('/v3/%s/unsubscribes/%s', $domain, $address)); + $params = []; + if (!is_null($tag)) { + $params['tag'] = $tag; + } + + $response = $this->httpDelete(sprintf('/v3/%s/unsubscribes/%s', $domain, $address), $params); return $this->hydrateResponse($response, DeleteResponse::class); } diff --git a/tests/Api/Suppression/UnsubscribeTest.php b/tests/Api/Suppression/UnsubscribeTest.php index c4ec05f..eb4a31c 100644 --- a/tests/Api/Suppression/UnsubscribeTest.php +++ b/tests/Api/Suppression/UnsubscribeTest.php @@ -65,6 +65,17 @@ class UnsubscribeTest extends TestCase $api->delete('example.com', 'foo@bar.com'); } + public function testDeleteWithTag() + { + $this->setRequestMethod('DELETE'); + $this->setRequestUri('/v3/example.com/unsubscribes/foo@bar.com'); + $this->setRequestBody(['tag' => 'tag1']); + $this->setHydrateClass(DeleteResponse::class); + + $api = $this->getApiInstance(); + $api->delete('example.com', 'foo@bar.com', 'tag1'); + } + public function testDeleteAll() { $this->setRequestMethod('DELETE');