Skip to content

Commit 3b1e971

Browse files
Merge pull request #933 from mailgun/DE-1257-api-complaints-endpoint
## 4.3.5
2 parents eb52d54 + 550afcf commit 3b1e971

File tree

8 files changed

+352
-0
lines changed

8 files changed

+352
-0
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
## 4.3.5
6+
- Implemented `AccountManagement` API endpoints:
7+
- `updateAccountSettings` for `PUT /v5/accounts`
8+
- `getHttpSigningKey` for `GET /v5/accounts/http_signing_key`
9+
- `createHttpSigningKey` for `POST /v5/accounts/http_signing_key`
10+
- `getSandboxAuthRecipients` for `GET /v5/sandbox/auth_recipients`
11+
- Added model classes for `AccountManagement` API responses:
12+
- `AccountResponse`
13+
- `HttpSigningKeyResponse`
14+
- `SandboxAuthRecipientsResponse`
15+
- Updated `Mailgun` class to include `AccountManagement` API.
16+
517
## 4.3.4
618
- Extended limit of tags to 10.
719

doc/examples.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,46 @@ try {
5656
}
5757

5858
```
59+
60+
61+
## Account Management Examples
62+
63+
```php
64+
<?php
65+
require 'vendor/autoload.php';
66+
67+
use Mailgun\Mailgun;
68+
69+
$mgClient = Mailgun::create('xxx');
70+
$domain = "yyy.mailgun.org";
71+
72+
try {
73+
$res = $mgClient->accountManagement()->addRecipientSandbox('xxx@gmail.com');
74+
print_r($res);
75+
} catch (Throwable $t) {
76+
print_r($t->getMessage());
77+
print_r($t->getTraceAsString());
78+
}
79+
80+
try {
81+
$res = $mgClient->accountManagement()->getSandboxAuthRecipients();
82+
print_r($res);
83+
} catch (Throwable $t) {
84+
print_r($t->getMessage());
85+
print_r($t->getTraceAsString());
86+
}
87+
88+
try {
89+
$res = $mgClient->accountManagement()->getHttpSigningKey();
90+
print_r($res);
91+
} catch (Throwable $t) {
92+
print_r($t->getMessage());
93+
print_r($t->getTraceAsString());
94+
}
95+
96+
97+
98+
99+
//print_r($res);
100+
101+
```

src/Api/AccountManagement.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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\Api;
13+
14+
use Mailgun\Model\AccountManagement\AccountResponse;
15+
use Mailgun\Model\AccountManagement\HttpSigningKeyResponse;
16+
use Mailgun\Model\AccountManagement\SandboxAuthRecipientsResponse;
17+
use Psr\Http\Client\ClientExceptionInterface;
18+
use Psr\Http\Message\ResponseInterface;
19+
20+
class AccountManagement extends HttpApi
21+
{
22+
/**
23+
* Updates account settings.
24+
* @param array $params
25+
* @param array $requestHeaders
26+
* @return AccountResponse|array|ResponseInterface
27+
* @throws ClientExceptionInterface|\JsonException
28+
* @throws \Exception
29+
*/
30+
public function updateAccountSettings(array $params, array $requestHeaders = [])
31+
{
32+
$response = $this->httpPut('/v5/accounts', $params, $requestHeaders);
33+
34+
return $this->hydrateResponse($response, AccountResponse::class);
35+
}
36+
37+
/**
38+
* Retrieves the HTTP signing key.
39+
* @param array $requestHeaders
40+
* @return HttpSigningKeyResponse|array|ResponseInterface
41+
* @throws ClientExceptionInterface
42+
* @throws \Exception
43+
*/
44+
public function getHttpSigningKey(array $requestHeaders = [])
45+
{
46+
$response = $this->httpGet('/v5/accounts/http_signing_key', [], $requestHeaders);
47+
48+
return $this->hydrateResponse($response, HttpSigningKeyResponse::class);
49+
}
50+
51+
/**
52+
* Creates a new HTTP signing key.
53+
* @param array $requestHeaders
54+
* @return HttpSigningKeyResponse|array|ResponseInterface
55+
* @throws ClientExceptionInterface
56+
* @throws \JsonException
57+
* @throws \Exception
58+
*/
59+
public function createHttpSigningKey(array $requestHeaders = [])
60+
{
61+
$response = $this->httpPost('/v5/accounts/http_signing_key', [], $requestHeaders);
62+
63+
return $this->hydrateResponse($response, HttpSigningKeyResponse::class);
64+
}
65+
66+
/**
67+
* Retrieves the list of sandbox authorized recipients.
68+
* @param array $requestHeaders
69+
* @return SandboxAuthRecipientsResponse|array|ResponseInterface
70+
* @throws ClientExceptionInterface
71+
* @throws \Exception
72+
*/
73+
public function getSandboxAuthRecipients(array $requestHeaders = [])
74+
{
75+
$response = $this->httpGet('/v5/sandbox/auth_recipients', [], $requestHeaders);
76+
77+
return $this->hydrateResponse($response, SandboxAuthRecipientsResponse::class);
78+
}
79+
80+
/**
81+
* Add authorized email recipient for a sandbox domain
82+
* @param string $email
83+
* @param array $requestHeaders
84+
* @return SandboxAuthRecipientsResponse|array|ResponseInterface
85+
* @throws ClientExceptionInterface
86+
* @throws \JsonException
87+
* @throws \Exception
88+
*/
89+
public function addRecipientSandbox(string $email, array $requestHeaders = [])
90+
{
91+
$response = $this->httpPost('/v5/sandbox/auth_recipients', ['email' => $email], $requestHeaders);
92+
93+
return $this->hydrateResponse($response, SandboxAuthRecipientsResponse::class);
94+
}
95+
}

src/Api/Suppression/Complaint.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use Mailgun\Model\Suppression\Complaint\IndexResponse;
2020
use Mailgun\Model\Suppression\Complaint\ShowResponse;
2121
use Psr\Http\Client\ClientExceptionInterface;
22+
use RuntimeException;
23+
use Throwable;
2224

2325
/**
2426
* @see https://documentation.mailgun.com/en/latest/api-suppressions.html#complaints
@@ -120,4 +122,25 @@ public function deleteAll(string $domain, array $requestHeaders = [])
120122

121123
return $this->hydrateResponse($response, DeleteResponse::class);
122124
}
125+
126+
/**
127+
* @param string $domainId
128+
* @param array $complaints
129+
* @param array $requestHeaders
130+
* @return mixed
131+
*/
132+
public function importComplaints(string $domainId, array $complaints, array $requestHeaders = [])
133+
{
134+
try {
135+
$response = $this->httpPostRaw(
136+
sprintf('/v3/%s/complaints/import', $domainId),
137+
$complaints,
138+
$requestHeaders
139+
);
140+
} catch (Throwable $throwable) {
141+
throw new RuntimeException($throwable->getMessage());
142+
}
143+
144+
return $this->hydrateResponse($response, ShowResponse::class);
145+
}
123146
}

src/Mailgun.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Mailgun;
1313

1414
use Http\Client\Common\PluginClient;
15+
use Mailgun\Api\AccountManagement;
1516
use Mailgun\Api\Attachment;
1617
use Mailgun\Api\Domain;
1718
use Mailgun\Api\DomainKeys;
@@ -272,4 +273,12 @@ public function domainKeys(): Api\DomainKeys
272273
{
273274
return new Api\DomainKeys($this->httpClient, $this->requestBuilder, $this->hydrator);
274275
}
276+
277+
/**
278+
* @return AccountManagement
279+
*/
280+
public function accountManagement(): AccountManagement
281+
{
282+
return new AccountManagement($this->httpClient, $this->requestBuilder, $this->hydrator);
283+
}
275284
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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\AccountManagement;
13+
14+
use Mailgun\Model\ApiResponse;
15+
16+
final class AccountResponse implements ApiResponse
17+
{
18+
private string $message;
19+
20+
public static function create(array $data): self
21+
{
22+
$model = new self();
23+
$model->message = $data['message'] ?? '';
24+
25+
return $model;
26+
}
27+
28+
public function getMessage(): string
29+
{
30+
return $this->message;
31+
}
32+
33+
private function __construct()
34+
{
35+
}
36+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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\AccountManagement;
13+
14+
use Mailgun\Model\ApiResponse;
15+
16+
final class HttpSigningKeyResponse implements ApiResponse
17+
{
18+
private string $key;
19+
private string $createdAt;
20+
private string $httpSigningKey;
21+
private string $message;
22+
23+
/**
24+
* @param array $data
25+
* @return self
26+
*/
27+
public static function create(array $data): self
28+
{
29+
$model = new self();
30+
$model->key = $data['key'] ?? '';
31+
$model->createdAt = $data['created_at'] ?? '';
32+
$model->httpSigningKey = $data['http_signing_key'] ?? '';
33+
$model->message = $data['message'] ?? '';
34+
35+
return $model;
36+
}
37+
38+
/**
39+
* @return string
40+
*/
41+
public function getKey(): string
42+
{
43+
return $this->key;
44+
}
45+
46+
/**
47+
* @return string
48+
*/
49+
public function getCreatedAt(): string
50+
{
51+
return $this->createdAt;
52+
}
53+
54+
/**
55+
* @return string
56+
*/
57+
public function getHttpSigningKey(): string
58+
{
59+
return $this->httpSigningKey;
60+
}
61+
62+
/**
63+
* @param string $httpSigningKey
64+
* @return void
65+
*/
66+
public function setHttpSigningKey(string $httpSigningKey): void
67+
{
68+
$this->httpSigningKey = $httpSigningKey;
69+
}
70+
71+
/**
72+
* @return string
73+
*/
74+
public function getMessage(): string
75+
{
76+
return $this->message;
77+
}
78+
79+
/**
80+
* @param string $message
81+
* @return void
82+
*/
83+
public function setMessage(string $message): void
84+
{
85+
$this->message = $message;
86+
}
87+
88+
private function __construct()
89+
{
90+
}
91+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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\AccountManagement;
13+
14+
use Mailgun\Model\ApiResponse;
15+
16+
final class SandboxAuthRecipientsResponse implements ApiResponse
17+
{
18+
private array $recipients;
19+
20+
/**
21+
* @param array $data
22+
* @return self
23+
*/
24+
public static function create(array $data): self
25+
{
26+
$model = new self();
27+
$model->recipients = $data['recipients'] ?? $data['recipient'] ?? [];
28+
29+
return $model;
30+
}
31+
32+
/**
33+
* @return array
34+
*/
35+
public function getRecipients(): array
36+
{
37+
return $this->recipients;
38+
}
39+
40+
private function __construct()
41+
{
42+
}
43+
}

0 commit comments

Comments
 (0)