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\Model\Webhook; |
11
|
|
|
|
12
|
|
|
use Mailgun\Model\ApiResponse; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Tobias Nyholm <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class IndexResponse implements ApiResponse |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
private $bounce = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private $deliver = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
private $drop = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
private $spam = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
private $unsubscribe = []; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
private $click = []; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
private $open = []; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Do not let this object be creted without the ::create. |
56
|
|
|
*/ |
57
|
|
|
private function __construct() |
58
|
|
|
{ |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param array $data |
63
|
|
|
* |
64
|
|
|
* @return IndexResponse |
65
|
|
|
*/ |
66
|
|
|
public static function create(array $data) |
67
|
|
|
{ |
68
|
|
|
$self = new self(); |
69
|
|
|
$data = isset($data['webhooks']) ? $data['webhooks'] : $data; |
70
|
|
|
if (isset($data['bounce'])) { |
71
|
|
|
$self->setBounce($data['bounce']); |
72
|
|
|
} |
73
|
|
|
if (isset($data['deliver'])) { |
74
|
|
|
$self->setDeliver($data['deliver']); |
75
|
|
|
} |
76
|
|
|
if (isset($data['drop'])) { |
77
|
|
|
$self->setDrop($data['drop']); |
78
|
|
|
} |
79
|
|
|
if (isset($data['spam'])) { |
80
|
|
|
$self->setSpam($data['spam']); |
81
|
|
|
} |
82
|
|
|
if (isset($data['unsubscribe'])) { |
83
|
|
|
$self->setUnsubscribe($data['unsubscribe']); |
84
|
|
|
} |
85
|
|
|
if (isset($data['click'])) { |
86
|
|
|
$self->setClick($data['click']); |
87
|
|
|
} |
88
|
|
|
if (isset($data['open'])) { |
89
|
|
|
$self->setOpen($data['open']); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $self; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string|null |
97
|
|
|
*/ |
98
|
|
|
public function getBounceUrl() |
99
|
|
|
{ |
100
|
|
|
if (isset($this->bounce['url'])) { |
101
|
|
|
return $this->bounce['url']; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param array $bounce |
107
|
|
|
*/ |
108
|
|
|
private function setBounce($bounce) |
109
|
|
|
{ |
110
|
|
|
$this->bounce = $bounce; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return string|null |
115
|
|
|
*/ |
116
|
|
|
public function getDeliverUrl() |
117
|
|
|
{ |
118
|
|
|
if (isset($this->deliver['url'])) { |
119
|
|
|
return $this->deliver['url']; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param array $deliver |
125
|
|
|
*/ |
126
|
|
|
private function setDeliver($deliver) |
127
|
|
|
{ |
128
|
|
|
$this->deliver = $deliver; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string|null |
133
|
|
|
*/ |
134
|
|
|
public function getDropUrl() |
135
|
|
|
{ |
136
|
|
|
if (isset($this->drop['url'])) { |
137
|
|
|
return $this->drop['url']; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param array $drop |
143
|
|
|
*/ |
144
|
|
|
private function setDrop($drop) |
145
|
|
|
{ |
146
|
|
|
$this->drop = $drop; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return string|null |
151
|
|
|
*/ |
152
|
|
|
public function getSpamUrl() |
153
|
|
|
{ |
154
|
|
|
if (isset($this->spam['url'])) { |
155
|
|
|
return $this->spam['url']; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param array $spam |
161
|
|
|
*/ |
162
|
|
|
private function setSpam($spam) |
163
|
|
|
{ |
164
|
|
|
$this->spam = $spam; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return string|null |
169
|
|
|
*/ |
170
|
|
|
public function getUnsubscribeUrl() |
171
|
|
|
{ |
172
|
|
|
if (isset($this->unsubscribe['url'])) { |
173
|
|
|
return $this->unsubscribe['url']; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param array $unsubscribe |
179
|
|
|
*/ |
180
|
|
|
private function setUnsubscribe($unsubscribe) |
181
|
|
|
{ |
182
|
|
|
$this->unsubscribe = $unsubscribe; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return string|null |
187
|
|
|
*/ |
188
|
|
|
public function getClickUrl() |
189
|
|
|
{ |
190
|
|
|
if (isset($this->click['url'])) { |
191
|
|
|
return $this->click['url']; |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param array $click |
197
|
|
|
*/ |
198
|
|
|
private function setClick($click) |
199
|
|
|
{ |
200
|
|
|
$this->click = $click; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return string|null |
205
|
|
|
*/ |
206
|
|
|
public function getOpenUrl() |
207
|
|
|
{ |
208
|
|
|
if (isset($this->open['url'])) { |
209
|
|
|
return $this->open['url']; |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @param array $open |
215
|
|
|
*/ |
216
|
|
|
private function setOpen($open) |
217
|
|
|
{ |
218
|
|
|
$this->open = $open; |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|