From 086afb49b7f4e858610100526172f93db7afb5c5 Mon Sep 17 00:00:00 2001 From: Joseph Shanak Date: Mon, 5 Oct 2020 09:50:47 -0500 Subject: [PATCH] Allow assigning a domain to a list of ips during creation --- src/Api/Domain.php | 19 +++++++++++++------ tests/Api/DomainTest.php | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Api/Domain.php b/src/Api/Domain.php index 0b1cb29..d9337f7 100644 --- a/src/Api/Domain.php +++ b/src/Api/Domain.php @@ -74,15 +74,16 @@ class Domain extends HttpApi * * @see https://documentation.mailgun.com/en/latest/api-domains.html#domains * - * @param string $domain name of the domain - * @param string $smtpPass password for SMTP authentication - * @param string $spamAction `disable` or `tag` - inbound spam filtering - * @param bool $wildcard domain will accept email for subdomains - * @param bool $forceDkimAuthority force DKIM authority + * @param string $domain name of the domain + * @param string $smtpPass password for SMTP authentication + * @param string $spamAction `disable` or `tag` - inbound spam filtering + * @param bool $wildcard domain will accept email for subdomains + * @param bool $forceDkimAuthority force DKIM authority + * @param string[] $ips an array of ips to be assigned to the domain * * @return CreateResponse|array|ResponseInterface */ - public function create(string $domain, string $smtpPass = null, string $spamAction = null, bool $wildcard = null, bool $forceDkimAuthority = null) + public function create(string $domain, string $smtpPass = null, string $spamAction = null, bool $wildcard = null, bool $forceDkimAuthority = null, ?array $ips = null) { Assert::stringNotEmpty($domain); @@ -113,6 +114,12 @@ class Domain extends HttpApi $params['force_dkim_authority'] = $forceDkimAuthority ? 'true' : 'false'; } + if (null !== $ips) { + Assert::isList($ips); + + $params['ips'] = join(',', $ips); + } + $response = $this->httpPost('/v3/domains', $params); return $this->hydrateResponse($response, CreateResponse::class); diff --git a/tests/Api/DomainTest.php b/tests/Api/DomainTest.php index 29a07ed..1466a83 100644 --- a/tests/Api/DomainTest.php +++ b/tests/Api/DomainTest.php @@ -241,4 +241,19 @@ JSON $api = $this->getApiInstance(); $api->verify('example.com'); } + + public function testCreateWithIps() + { + $this->setRequestMethod('POST'); + $this->setRequestUri('/v3/domains'); + $this->setRequestBody([ + 'name' => 'example.com', + 'smtp_password' => 'foo', + 'ips' => "127.0.0.1,127.0.0.2", + ]); + $this->setHydrateClass(CreateResponse::class); + + $api = $this->getApiInstance(); + $api->create('example.com', 'foo', null, null, null, ["127.0.0.1", "127.0.0.2"]); + } }