-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMailgunListMember.php
124 lines (108 loc) · 2.41 KB
/
MailgunListMember.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
<?php
/** @author Andrei Baibaratsky */
class MailgunListMember implements MailgunObject
{
private $_address;
private $_name;
private $_vars = array();
private $_isSubscribed;
/**
* @param array $data
* @return MailgunListMember
*/
public static function load($data)
{
$member = new self($data['address'], $data['name']);
$member->setIsSubscribed($data['subscribed']);
foreach ($data['vars'] as $name => $value) {
$member->addVar($name, $value);
}
return $member;
}
/**
* @param string $address
* @param string $name
*/
public function __construct($address, $name = null)
{
$this->_address = $address;
$this->_name = $name;
}
/**
* @return array POST-data for Mailgun API request
*/
public function getPostData()
{
$data = array(
'address' => $this->_address,
);
if (!empty($this->_name)) {
$data['name'] = $this->_name;
}
if (!empty($this->_vars)) {
$data['vars'] = json_encode($this->_vars);
}
if (isset($this->_isSubscribed)) {
$data['subscribed'] = $this->_isSubscribed ? 'yes' : 'no';
}
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;
}
/**
* Append a custom variable
* @param string $name Variable name
* @param string $value Variable value
*/
public function addVar($name, $value)
{
$this->_vars[$name] = $value;
}
/**
* @return array List of attached variables in 'name' => 'value' format
*/
public function getVars()
{
return $this->_vars;
}
/**
* @param mixed $isSubscribed
*/
public function setIsSubscribed($isSubscribed)
{
$this->_isSubscribed = $isSubscribed;
}
/**
* @return mixed
*/
public function getIsSubscribed()
{
return $this->_isSubscribed;
}
}