mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 00:09:24 +03:00
Add domain verification (#370)
This commit is contained in:
parent
8187a47fa0
commit
e800038f21
@ -25,6 +25,12 @@ $mailgun->domains()->index();
|
||||
$mailgun->domains()->show('example.com');
|
||||
```
|
||||
|
||||
#### Verify a domain
|
||||
|
||||
```php
|
||||
$mailgun->domains()->verify('example.com');
|
||||
```
|
||||
|
||||
#### Create a new domain
|
||||
|
||||
```php
|
||||
|
@ -20,6 +20,7 @@ use Mailgun\Model\Domain\IndexResponse;
|
||||
use Mailgun\Model\Domain\ShowResponse;
|
||||
use Mailgun\Model\Domain\UpdateConnectionResponse;
|
||||
use Mailgun\Model\Domain\UpdateCredentialResponse;
|
||||
use Mailgun\Model\Domain\VerifyResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
@ -263,4 +264,20 @@ class Domain extends HttpApi
|
||||
|
||||
return $this->hydrateResponse($response, UpdateConnectionResponse::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single domain.
|
||||
*
|
||||
* @param string $domain Name of the domain.
|
||||
*
|
||||
* @return VerifyResponse|array|ResponseInterface
|
||||
*/
|
||||
public function verify($domain)
|
||||
{
|
||||
Assert::stringNotEmpty($domain);
|
||||
|
||||
$response = $this->httpPut(sprintf('/v3/domains/%s/verify', $domain));
|
||||
|
||||
return $this->hydrateResponse($response, VerifyResponse::class);
|
||||
}
|
||||
}
|
||||
|
119
src/Mailgun/Model/Domain/VerifyResponse.php
Normal file
119
src/Mailgun/Model/Domain/VerifyResponse.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013-2016 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;
|
||||
|
||||
use Mailgun\Model\ApiResponse;
|
||||
|
||||
/**
|
||||
* @author Maxim Zasorin <maximzasorin@gmail.com>
|
||||
*/
|
||||
final class VerifyResponse implements ApiResponse
|
||||
{
|
||||
/**
|
||||
* @var Domain
|
||||
*/
|
||||
private $domain;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $message;
|
||||
|
||||
/**
|
||||
* @var DnsRecord[]
|
||||
*/
|
||||
private $inboundDnsRecords;
|
||||
|
||||
/**
|
||||
* @var DnsRecord[]
|
||||
*/
|
||||
private $outboundDnsRecords;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function create(array $data)
|
||||
{
|
||||
$rx = [];
|
||||
$tx = [];
|
||||
$domain = null;
|
||||
$message = null;
|
||||
|
||||
if (isset($data['domain'])) {
|
||||
$domain = Domain::create($data['domain']);
|
||||
}
|
||||
|
||||
if (isset($data['message'])) {
|
||||
$message = $data['message'];
|
||||
}
|
||||
|
||||
if (isset($data['receiving_dns_records'])) {
|
||||
foreach ($data['receiving_dns_records'] as $item) {
|
||||
$rx[] = DnsRecord::create($item);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['sending_dns_records'])) {
|
||||
foreach ($data['sending_dns_records'] as $item) {
|
||||
$tx[] = DnsRecord::create($item);
|
||||
}
|
||||
}
|
||||
|
||||
return new self($domain, $rx, $tx, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Domain $domainInfo
|
||||
* @param DnsRecord[] $rxRecords
|
||||
* @param DnsRecord[] $txRecords
|
||||
* @param string $message
|
||||
*/
|
||||
private function __construct(Domain $domainInfo, array $rxRecords, array $txRecords, $message)
|
||||
{
|
||||
$this->domain = $domainInfo;
|
||||
$this->inboundDnsRecords = $rxRecords;
|
||||
$this->outboundDnsRecords = $txRecords;
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Domain
|
||||
*/
|
||||
public function getDomain()
|
||||
{
|
||||
return $this->domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DnsRecord[]
|
||||
*/
|
||||
public function getInboundDNSRecords()
|
||||
{
|
||||
return $this->inboundDnsRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DnsRecord[]
|
||||
*/
|
||||
public function getOutboundDNSRecords()
|
||||
{
|
||||
return $this->outboundDnsRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ use Mailgun\Model\Domain\CredentialResponse;
|
||||
use Mailgun\Model\Domain\ConnectionResponse;
|
||||
use Mailgun\Model\Domain\UpdateConnectionResponse;
|
||||
use Mailgun\Model\Domain\UpdateCredentialResponse;
|
||||
use Mailgun\Model\Domain\VerifyResponse;
|
||||
use Mailgun\Tests\Api\TestCase;
|
||||
|
||||
/**
|
||||
@ -75,6 +76,20 @@ class DomainApiTest extends TestCase
|
||||
$this->assertEquals($domain->getDomain()->getState(), 'active');
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs `PUT /v3/domains/<domain>/verify` for verify domain.
|
||||
*/
|
||||
public function testDomainVerify()
|
||||
{
|
||||
$mg = $this->getMailgunClient();
|
||||
|
||||
$ret = $mg->domains()->verify($this->testDomain);
|
||||
|
||||
$this->assertNotNull($ret);
|
||||
$this->assertInstanceOf(VerifyResponse::class, $ret);
|
||||
$this->assertEquals('Domain DNS records have been updated', $ret->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs `DELETE /v3/domains/<domain>` on a non-existent domain.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user