add unsubscribe delete parameter.

This commit is contained in:
iwahara 2019-10-01 17:49:15 +09:00 committed by David Garcia
parent 16d0a04014
commit 8390bdd803
2 changed files with 21 additions and 4 deletions

View File

@ -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 $address Unsubscribe address
* * @param string|null $tag Unsubscribe tag
* @return DeleteResponse * @return DeleteResponse
*/ */
public function delete(string $domain, string $address) public function delete(string $domain, string $address, string $tag = null)
{ {
Assert::stringNotEmpty($domain); Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($address); 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); return $this->hydrateResponse($response, DeleteResponse::class);
} }

View File

@ -65,6 +65,17 @@ class UnsubscribeTest extends TestCase
$api->delete('example.com', 'foo@bar.com'); $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() public function testDeleteAll()
{ {
$this->setRequestMethod('DELETE'); $this->setRequestMethod('DELETE');