Skip to content

Commit

Permalink
Support updating CNAME used for tracking opens and clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
mikktol committed Dec 15, 2023
1 parent 3dbdc2f commit 939af8d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Api/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Mailgun\Model\Domain\UpdateUnsubscribeTrackingResponse;
use Mailgun\Model\Domain\VerifyResponse;
use Mailgun\Model\Domain\WebSchemeResponse;
use Mailgun\Model\Domain\WebPrefixResponse;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\ResponseInterface;

Expand Down Expand Up @@ -468,4 +469,27 @@ public function updateUnsubscribeTracking(string $domain, string $active, string

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

/**
* Updates a CNAME used for tracking opens and clicks.
*
* @param string $domain The name of the domain
* @param string $webPrefix The tracking CNAME for a domain
*
* @return WebPrefixResponse|array|ResponseInterface
* @throws ClientExceptionInterface
*/
public function updateWebPrefix(string $domain, string $webPrefix)
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($webPrefix);

$params = [
'web_prefix' => $webPrefix,
];

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

return $this->hydrateResponse($response, WebPrefixResponse::class);
}
}
16 changes: 16 additions & 0 deletions src/Model/Domain/WebPrefixResponse.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 WebPrefixResponse extends AbstractDomainResponse
{
}
19 changes: 19 additions & 0 deletions tests/Api/DomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Mailgun\Model\Domain\UpdateOpenTrackingResponse;
use Mailgun\Model\Domain\UpdateUnsubscribeTrackingResponse;
use Mailgun\Model\Domain\VerifyResponse;
use Mailgun\Model\Domain\WebPrefixResponse;
use Nyholm\Psr7\Response;

class DomainTest extends TestCase
Expand Down Expand Up @@ -491,4 +492,22 @@ public function testUpdateUnsubscribeTrackingException()
$api = $this->getApiInstance();
$api->updateUnsubscribeTracking('example.com', 'non-valid-active-param', 'html-footer', 'text-footer');
}

public function testUpdateWebPrefix()
{
$this->setRequestMethod('PUT');
$this->setRequestUri('/v3/domains/example.com/web_prefix');
$this->setRequestBody(
[
'web_prefix' => 'tracking',
]
);
$this->setHydrateClass(WebPrefixResponse::class);

/**
* @var Domain
*/
$api = $this->getApiInstance();
$api->updateWebPrefix('example.com', 'tracking');
}
}
31 changes: 31 additions & 0 deletions tests/Model/Domain/WebPrefixResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

Check warning on line 1 in tests/Model/Domain/WebPrefixResponseTest.php

View workflow job for this annotation

GitHub Actions / PHP-CS-Fixer

Found violation(s) of type: no_unused_imports

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\Tests\Model\Domain;

use Mailgun\Model\Domain\ClickTracking;
use Mailgun\Model\Domain\WebPrefixResponse;
use Mailgun\Tests\Model\BaseModelTest;

class WebPrefixResponseTest extends BaseModelTest
{
public function testCreate()
{
$json =
<<<'JSON'
{
"message": "Domain web prefix updated"
}
JSON;
$model = WebPrefixResponse::create(json_decode($json, true));
$this->assertNotEmpty($model->getMessage());
}
}

0 comments on commit 939af8d

Please sign in to comment.