Skip to content

Commit eb52d54

Browse files
Merge pull request #932 from mailgun/DE-1254-api-secure-tracking-endpoint
api secure tracking endpoint
2 parents eac73c8 + f55d535 commit eb52d54

File tree

3 files changed

+327
-7
lines changed

3 files changed

+327
-7
lines changed

src/Api/Domain.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Exception;
1515
use Mailgun\Assert;
16+
use Mailgun\Model\Domain\CertStatusResponse;
1617
use Mailgun\Model\Domain\ConnectionResponse;
1718
use Mailgun\Model\Domain\CreateCredentialResponse;
1819
use Mailgun\Model\Domain\CreateResponse;
@@ -486,4 +487,63 @@ public function updateWebPrefix(string $domain, string $webPrefix)
486487

487488
return $this->hydrateResponse($response, WebPrefixResponse::class);
488489
}
490+
491+
/**
492+
* Status of x509 TLS certificate
493+
* @link https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domain-Tracking/#tag/Domain-Tracking/operation/httpapi.(*HttpAPI).getStatusV2-fm-8
494+
*
495+
* @param string $domain
496+
* @return mixed|ResponseInterface
497+
* @throws ClientExceptionInterface
498+
* @throws \JsonException
499+
* @throws Exception
500+
*/
501+
public function statusOf509Crt(string $domain)
502+
{
503+
Assert::stringNotEmpty($domain);
504+
505+
$response = $this->httpGet(sprintf('/v2/x509/%s}/status', $domain), []);
506+
507+
return $this->hydrateResponse($response, CertStatusResponse::class);
508+
}
509+
510+
/**
511+
* @param string $domain
512+
* @return mixed|ResponseInterface
513+
* @throws ClientExceptionInterface
514+
* @throws \JsonException
515+
* @throws Exception
516+
*/
517+
public function generate509Tls(string $domain)
518+
{
519+
Assert::stringNotEmpty($domain);
520+
521+
$params = [
522+
'domain' => $domain,
523+
];
524+
525+
$response = $this->httpPost(sprintf('/v2/x509/%s', $domain), $params);
526+
527+
return $this->hydrateResponse($response, CertStatusResponse::class);
528+
}
529+
530+
/**
531+
* @param string $domain
532+
* @return mixed|ResponseInterface
533+
* @throws ClientExceptionInterface
534+
* @throws \JsonException
535+
* @throws Exception
536+
*/
537+
public function regenerateExpiredCrt(string $domain)
538+
{
539+
Assert::stringNotEmpty($domain);
540+
541+
$params = [
542+
'domain' => $domain,
543+
];
544+
545+
$response = $this->httpPut(sprintf('/v2/x509/%s', $domain), $params);
546+
547+
return $this->hydrateResponse($response, CertStatusResponse::class);
548+
}
489549
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* Copyright (C) 2013 Mailgun
7+
*
8+
* This software may be modified and distributed under the terms
9+
* of the MIT license. See the LICENSE file for details.
10+
*/
11+
12+
namespace Mailgun\Model\Domain;
13+
14+
use Mailgun\Model\ApiResponse;
15+
16+
final class CertStatusResponse implements ApiResponse
17+
{
18+
private string $status;
19+
private string $error;
20+
private string $certificate;
21+
private string $location;
22+
private string $message;
23+
24+
25+
/**
26+
* @param array $data
27+
* @return self
28+
*/
29+
public static function create(array $data): self
30+
{
31+
$model = new self();
32+
$model->setStatus($data['status']);
33+
$model->setError($data['error'] ?? '');
34+
$model->setCertificate($data['certificate'] ?? '');
35+
$model->setLocation($data['location'] ?? '');
36+
$model->setMessage($data['message'] ?? '');
37+
38+
return $model;
39+
}
40+
41+
/**
42+
* @return string
43+
*/
44+
public function getStatus(): string
45+
{
46+
return $this->status;
47+
}
48+
49+
/**
50+
* @param string $status
51+
*/
52+
public function setStatus(string $status): void
53+
{
54+
$this->status = $status;
55+
}
56+
57+
/**
58+
* @return string
59+
*/
60+
public function getError(): string
61+
{
62+
return $this->error;
63+
}
64+
65+
/**
66+
* @param string $error
67+
*/
68+
public function setError(string $error): void
69+
{
70+
$this->error = $error;
71+
}
72+
73+
/**
74+
* @return string
75+
*/
76+
public function getCertificate(): string
77+
{
78+
return $this->certificate;
79+
}
80+
81+
/**
82+
* @param string $certificate
83+
*/
84+
public function setCertificate(string $certificate): void
85+
{
86+
$this->certificate = $certificate;
87+
}
88+
89+
/**
90+
* @return string
91+
*/
92+
public function getLocation(): string
93+
{
94+
return $this->location;
95+
}
96+
97+
/**
98+
* @param string $location
99+
*/
100+
public function setLocation(string $location): void
101+
{
102+
$this->location = $location;
103+
}
104+
105+
/**
106+
* @return string
107+
*/
108+
public function getMessage(): string
109+
{
110+
return $this->message;
111+
}
112+
113+
/**
114+
* @param string $message
115+
*/
116+
public function setMessage(string $message): void
117+
{
118+
$this->message = $message;
119+
}
120+
121+
122+
/**
123+
*
124+
*/
125+
private function __construct()
126+
{
127+
}
128+
}

src/Model/Domain/Domain.php

Lines changed: 139 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Mailgun\Model\Domain;
1313

14+
use DateTimeImmutable;
15+
1416
/**
1517
* Represents domain information in its simplest form.
1618
*
@@ -26,7 +28,18 @@ final class Domain
2628
private ?string $spamAction;
2729
private ?string $state;
2830
private ?string $webScheme;
31+
private ?string $webPrefix;
32+
private string $type;
33+
private bool $useAutomaticSenderSecurity;
34+
private bool $requireTls;
35+
private bool $skipVerification;
36+
private string $id;
37+
private bool $isDisabled;
2938

39+
/**
40+
* @param array $data
41+
* @return self
42+
*/
3043
public static function create(array $data): self
3144
{
3245
$model = new self();
@@ -36,16 +49,19 @@ public static function create(array $data): self
3649
$model->wildcard = $data['wildcard'] ?? null;
3750
$model->spamAction = $data['spam_action'] ?? null;
3851
$model->state = $data['state'] ?? null;
39-
$model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null;
52+
$model->createdAt = isset($data['created_at']) ? new DateTimeImmutable($data['created_at']) : null;
4053
$model->webScheme = $data['web_scheme'] ?? null;
54+
$model->webPrefix = $data['web_prefix'] ?? null;
55+
$model->type = $data['type'] ?? 'sandbox';
56+
$model->useAutomaticSenderSecurity = $data['use_automatic_sender_security'] ?? false;
57+
$model->requireTls = $data['require_tls'] ?? false;
58+
$model->skipVerification = $data['skip_verification'] ?? false;
59+
$model->id = $data['id'] ?? '';
60+
$model->isDisabled = $data['is_disabled'] ?? false;
4161

4262
return $model;
4363
}
4464

45-
private function __construct()
46-
{
47-
}
48-
4965
/**
5066
* @return string|null
5167
*/
@@ -95,9 +111,9 @@ public function getState(): ?string
95111
}
96112

97113
/**
98-
* @return \DateTimeImmutable
114+
* @return DateTimeImmutable
99115
*/
100-
public function getCreatedAt(): \DateTimeImmutable
116+
public function getCreatedAt(): DateTimeImmutable
101117
{
102118
return $this->createdAt;
103119
}
@@ -118,4 +134,120 @@ public function setWebScheme(?string $webScheme): void
118134
{
119135
$this->webScheme = $webScheme;
120136
}
137+
138+
/**
139+
* @return string|null
140+
*/
141+
public function getWebPrefix(): ?string
142+
{
143+
return $this->webPrefix;
144+
}
145+
146+
/**
147+
* @param string|null $webPrefix
148+
*/
149+
public function setWebPrefix(?string $webPrefix): void
150+
{
151+
$this->webPrefix = $webPrefix;
152+
}
153+
154+
/**
155+
* @return string
156+
*/
157+
public function getType(): string
158+
{
159+
return $this->type;
160+
}
161+
162+
/**
163+
* @param string $type
164+
*/
165+
public function setType(string $type): void
166+
{
167+
$this->type = $type;
168+
}
169+
170+
/**
171+
* @return bool
172+
*/
173+
public function isUseAutomaticSenderSecurity(): bool
174+
{
175+
return $this->useAutomaticSenderSecurity;
176+
}
177+
178+
/**
179+
* @param bool $useAutomaticSenderSecurity
180+
*/
181+
public function setUseAutomaticSenderSecurity(bool $useAutomaticSenderSecurity): void
182+
{
183+
$this->useAutomaticSenderSecurity = $useAutomaticSenderSecurity;
184+
}
185+
186+
/**
187+
* @return bool
188+
*/
189+
public function isRequireTls(): bool
190+
{
191+
return $this->requireTls;
192+
}
193+
194+
/**
195+
* @param bool $requireTls
196+
*/
197+
public function setRequireTls(bool $requireTls): void
198+
{
199+
$this->requireTls = $requireTls;
200+
}
201+
202+
/**
203+
* @return bool
204+
*/
205+
public function isSkipVerification(): bool
206+
{
207+
return $this->skipVerification;
208+
}
209+
210+
/**
211+
* @param bool $skipVerification
212+
*/
213+
public function setSkipVerification(bool $skipVerification): void
214+
{
215+
$this->skipVerification = $skipVerification;
216+
}
217+
218+
/**
219+
* @return string
220+
*/
221+
public function getId(): string
222+
{
223+
return $this->id;
224+
}
225+
226+
/**
227+
* @param string $id
228+
*/
229+
public function setId(string $id): void
230+
{
231+
$this->id = $id;
232+
}
233+
234+
/**
235+
* @return bool
236+
*/
237+
public function isDisabled(): bool
238+
{
239+
return $this->isDisabled;
240+
}
241+
242+
/**
243+
* @param bool $isDisabled
244+
*/
245+
public function setIsDisabled(bool $isDisabled): void
246+
{
247+
$this->isDisabled = $isDisabled;
248+
}
249+
250+
private function __construct()
251+
{
252+
}
121253
}

0 commit comments

Comments
 (0)