-
Notifications
You must be signed in to change notification settings - Fork 13
/
MailgunList.php
142 lines (125 loc) · 2.92 KB
/
MailgunList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/** @author Andrei Baibaratsky */
class MailgunList implements MailgunObject
{
const ACCESS_LEVEL_READONLY = 'readonly';
const ACCESS_LEVEL_MEMBERS = 'members';
const ACCESS_LEVEL_EVERYONE = 'everyone';
private $_address;
private $_name;
private $_description;
private $_accessLevel = self::ACCESS_LEVEL_READONLY;
private $_membersCount = 0;
private $_createDt;
/**
* @param array $data
* @return MailgunList
*/
public static function load($data)
{
$mailingList = new self($data['address'], $data['name'], $data['description'], $data['access_level']);
$mailingList->_membersCount = $data['members_count'];
$mailingList->_createDt = new DateTime($data['created_at']);
return $mailingList;
}
/**
* @param string $address
* @param string $name
* @param string $description
* @param string $accessLevel
*/
public function __construct($address, $name = null, $description = null, $accessLevel = self::ACCESS_LEVEL_READONLY)
{
$this->_address = $address;
$this->_name = $name;
$this->_description = $description;
$this->_accessLevel = $accessLevel;
}
/**
* @return array POST-data for mailing list in Mailgun API
*/
public function getPostData()
{
$data = array(
'address' => $this->_address,
'access_level' => $this->_accessLevel,
);
if (!empty($this->_name)) {
$data['name'] = $this->_name;
}
if (!empty($this->_description)) {
$data['description'] = $this->_description;
}
return $data;
}
/**
* @param string $address
*/
public function setAddress($address)
{
$this->_address = $address;
}
/**
* @return string
*/
public function getAddress()
{
return $this->_address;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->_name = $name;
}
/**
* @return string
*/
public function getName()
{
return $this->_name;
}
/**
* @param string $description
*/
public function setDescription($description)
{
$this->_description = $description;
}
/**
* @return string
*/
public function getDescription()
{
return $this->_description;
}
/**
* @param string $accessLevel
*/
public function setAccessLevel($accessLevel)
{
$this->_accessLevel = $accessLevel;
}
/**
* @return string
*/
public function getAccessLevel()
{
return $this->_accessLevel;
}
/**
* @return int
*/
public function getMembersCount()
{
return $this->_membersCount;
}
/**
* @return DateTime
*/
public function getCreateDt()
{
return $this->_createDt;
}
}