From 1fd4f222e6d6061fed1e43a3e82f0d8aef5541f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Wed, 22 Nov 2017 09:47:57 +0100 Subject: [PATCH] Update POST domain/create with optional params (#399) According to issue #397 the stmp params are optionals in the creation of a domain --- src/Mailgun/Api/Domain.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Mailgun/Api/Domain.php b/src/Mailgun/Api/Domain.php index 6b85d6f..d592142 100644 --- a/src/Mailgun/Api/Domain.php +++ b/src/Mailgun/Api/Domain.php @@ -74,6 +74,8 @@ class Domain extends HttpApi * See below for spam filtering parameter information. * {@link https://documentation.mailgun.com/user_manual.html#um-spam-filter}. * + * @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. @@ -81,20 +83,22 @@ class Domain extends HttpApi * * @return CreateResponse|array|ResponseInterface */ - public function create($domain, $smtpPass, $spamAction, $wildcard) + public function create($domain, $smtpPass = NULL, $spamAction = NULL, $wildcard = NULL) { Assert::stringNotEmpty($domain); - Assert::stringNotEmpty($smtpPass); - // TODO(sean.johnson): Extended spam filter input validation. - Assert::stringNotEmpty($spamAction); - Assert::boolean($wildcard); + + $params = ['name'] = $domain; + + // If at least smtpPass available, check for the fields spamAction wildcard + if(!empty($smtpPass) { - $params = [ - 'name' => $domain, - 'smtp_password' => $smtpPass, - 'spam_action' => $spamAction, - 'wildcard' => $wildcard, - ]; + // TODO(sean.johnson): Extended spam filter input validation. + Assert::stringNotEmpty($spamAction); + Assert::boolean($wildcard); + + $params['smtp_password'] = $smtpPass; + $params['spam_action'] = $spamAction; + } $response = $this->httpPost('/v3/domains', $params);