1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (C) 2013-2016 Mailgun |
5
|
|
|
* |
6
|
|
|
* This software may be modified and distributed under the terms |
7
|
|
|
* of the MIT license. See the LICENSE file for details. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Mailgun\Api; |
11
|
|
|
|
12
|
|
|
use Mailgun\Assert; |
13
|
|
|
use Mailgun\Resource\Api\Tag\DeleteResponse; |
14
|
|
|
use Mailgun\Resource\Api\Tag\IndexResponse; |
15
|
|
|
use Mailgun\Resource\Api\Tag\ShowResponse; |
16
|
|
|
use Mailgun\Resource\Api\Tag\StatisticsResponse; |
17
|
|
|
use Mailgun\Resource\Api\Tag\UpdateResponse; |
18
|
|
|
use Psr\Http\Message\ResponseInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@link https://documentation.mailgun.com/api-tags.html#tags}. |
22
|
|
|
* |
23
|
|
|
* @author Tobias Nyholm <[email protected]> |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
class Tag extends HttpApi |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Returns a list of tags. |
29
|
|
|
* |
30
|
|
|
* @param string $domain |
31
|
|
|
* @param int $limit |
32
|
|
|
* |
33
|
|
|
* @return IndexResponse|ResponseInterface |
34
|
|
|
*/ |
35
|
1 |
|
public function index($domain, $limit = 100) |
36
|
|
|
{ |
37
|
1 |
|
Assert::stringNotEmpty($domain); |
38
|
1 |
|
Assert::integer($limit); |
39
|
|
|
|
40
|
|
|
$params = [ |
41
|
1 |
|
'limit' => $limit, |
42
|
1 |
|
]; |
43
|
|
|
|
44
|
1 |
|
$response = $this->httpGet(sprintf('/v3/%s/tags', $domain), $params); |
45
|
|
|
|
46
|
1 |
|
return $this->safeDeserialize($response, IndexResponse::class); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Returns a single tag. |
51
|
|
|
* |
52
|
|
|
* @param string $domain Name of the domain |
53
|
|
|
* @param string $tag |
54
|
|
|
* |
55
|
|
|
* @return ShowResponse|ResponseInterface |
56
|
|
|
*/ |
57
|
1 |
|
public function show($domain, $tag) |
58
|
|
|
{ |
59
|
1 |
|
Assert::stringNotEmpty($domain); |
60
|
1 |
|
Assert::stringNotEmpty($tag); |
61
|
|
|
|
62
|
1 |
|
$response = $this->httpGet(sprintf('/v3/%s/tags/%s', $domain, $tag)); |
63
|
|
|
|
64
|
1 |
|
return $this->safeDeserialize($response, ShowResponse::class); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Update a tag. |
69
|
|
|
* |
70
|
|
|
* @param string $domain |
71
|
|
|
* @param string $tag |
72
|
|
|
* @param string $description |
73
|
|
|
* |
74
|
|
|
* @return UpdateResponse|ResponseInterface |
75
|
|
|
*/ |
76
|
1 |
|
public function update($domain, $tag, $description) |
77
|
|
|
{ |
78
|
1 |
|
Assert::stringNotEmpty($domain); |
79
|
1 |
|
Assert::stringNotEmpty($tag); |
80
|
1 |
|
Assert::string($description); |
81
|
|
|
|
82
|
|
|
$params = [ |
83
|
1 |
|
'description' => $description, |
84
|
1 |
|
]; |
85
|
|
|
|
86
|
1 |
|
$response = $this->httpPut(sprintf('/v3/%s/tags/%s', $domain, $tag), $params); |
87
|
|
|
|
88
|
1 |
|
return $this->safeDeserialize($response, UpdateResponse::class); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns statistics for a single tag. |
93
|
|
|
* |
94
|
|
|
* @param string $domain Name of the domain |
95
|
|
|
* @param string $tag |
96
|
|
|
* @param array $params |
97
|
|
|
* |
98
|
|
|
* @return StatisticsResponse|ResponseInterface |
99
|
|
|
*/ |
100
|
1 |
|
public function stats($domain, $tag, array $params) |
101
|
|
|
{ |
102
|
1 |
|
Assert::stringNotEmpty($domain); |
103
|
1 |
|
Assert::stringNotEmpty($tag); |
104
|
1 |
|
Assert::isArray($params); |
105
|
|
|
|
106
|
1 |
|
$response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats', $domain, $tag), $params); |
107
|
|
|
|
108
|
1 |
|
return $this->safeDeserialize($response, StatisticsResponse::class); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Removes a tag from the account. |
113
|
|
|
* |
114
|
|
|
* @param string $domain Name of the domain |
115
|
|
|
* @param string $tag |
116
|
|
|
* |
117
|
|
|
* @return DeleteResponse|ResponseInterface |
118
|
|
|
*/ |
119
|
1 |
|
public function delete($domain, $tag) |
120
|
|
|
{ |
121
|
1 |
|
Assert::stringNotEmpty($domain); |
122
|
1 |
|
Assert::stringNotEmpty($tag); |
123
|
|
|
|
124
|
1 |
|
$response = $this->httpDelete(sprintf('/v3/%s/tags/%s', $domain, $tag)); |
125
|
|
|
|
126
|
1 |
|
return $this->safeDeserialize($response, DeleteResponse::class); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.