Skip to content

Commit

Permalink
Add useAutomaticSenderSecurity support in DomainV4
Browse files Browse the repository at this point in the history
  • Loading branch information
matteotrubini committed Feb 27, 2025
1 parent 4156bf5 commit b746326
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/Api/DomainV4.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Mailgun\Model\Domain\UpdateCredentialResponse;
use Mailgun\Model\Domain\UpdateOpenTrackingResponse;
use Mailgun\Model\Domain\UpdateUnsubscribeTrackingResponse;
use Mailgun\Model\Domain\UseAutomaticSenderSecurity;
use Mailgun\Model\Domain\VerifyResponse;
use Mailgun\Model\Domain\WebPrefixResponse;
use Mailgun\Model\Domain\WebSchemeResponse;
Expand Down Expand Up @@ -94,6 +95,7 @@ public function show(string $domain, array $requestHeaders = [])
* @param array $requestHeaders
* @param string|null $dkimHostName
* @param string|null $dkimSelector
* @param bool|null $useAutomaticSenderSecurity
* @return CreateResponse|array|ResponseInterface
* @throws ClientExceptionInterface
*/
Expand All @@ -109,7 +111,8 @@ public function create(
string $dkimKeySize = '1024',
array $requestHeaders = [],
?string $dkimHostName = null,
?string $dkimSelector = null
?string $dkimSelector = null,
?bool $useAutomaticSenderSecurity = null
) {
Assert::stringNotEmpty($domain);

Expand Down Expand Up @@ -174,6 +177,10 @@ public function create(
$params['dkim_selector'] = $dkimSelector;
}

if (null !== $useAutomaticSenderSecurity) {
$params['use_automatic_sender_security'] = $useAutomaticSenderSecurity ? 'true' : 'false';
}

$response = $this->httpPost('/v4/domains', $params, $requestHeaders);

return $this->hydrateResponse($response, CreateResponse::class);
Expand Down Expand Up @@ -365,6 +372,28 @@ public function updateWebScheme(string $domain, string $webScheme = 'http', arra
return $this->hydrateResponse($response, WebSchemeResponse::class);
}

/**
* Update useAutomaticSenderSecurity for existing domain
* @see https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domains/#tag/Domains/operation/PUT-v4-domains--name-
* @param string $domain name of the domain
* @param bool $useAutomaticSenderSecurity If enabled, requires setting DNS CNAME entries for DKIM keys instead of a TXT record. Defaults to false.
* @param array $requestHeaders
* @return UseAutomaticSenderSecurity|array|ResponseInterface
* @throws ClientExceptionInterface
*/
public function updateUseAutomaticSenderSecurity(string $domain, bool $useAutomaticSenderSecurity = false, array $requestHeaders = [])
{
$params = [];
Assert::stringNotEmpty($domain);
Assert::boolean($useAutomaticSenderSecurity);

Check failure on line 388 in src/Api/DomainV4.php

View workflow job for this annotation

GitHub Actions / Psalm

Type bool for $useAutomaticSenderSecurity is always bool (see https://psalm.dev/122)

$params['use_automatic_sender_security'] = $useAutomaticSenderSecurity;

$response = $this->httpPut(sprintf('/v4/domains/%s', $domain), $params, $requestHeaders);

return $this->hydrateResponse($response, UseAutomaticSenderSecurity::class);
}

/**
* Returns a single domain.
* @param string $domain name of the domain
Expand Down
16 changes: 16 additions & 0 deletions src/Model/Domain/UseAutomaticSenderSecurity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

/*
* Copyright (C) 2013 Mailgun
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

namespace Mailgun\Model\Domain;

final class UseAutomaticSenderSecurity extends AbstractDomainResponse
{
}

0 comments on commit b746326

Please sign in to comment.