|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* The MailChimp API manager. |
|
5
|
|
|
* |
|
6
|
|
|
* Used to retrieve API functionality for use elsewhere. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Jeremy Pry |
|
9
|
|
|
* @since %VERSION% |
|
10
|
|
|
*/ |
|
11
|
|
|
class Yikes_Inc_Easy_MailChimp_API_Manager { |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* The account details instance. |
|
15
|
|
|
* |
|
16
|
|
|
* @since %VERSION% |
|
17
|
|
|
* @var Yikes_Inc_Easy_MailChimp_API_Account_Details |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $account_details = null; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The account manager instance. |
|
23
|
|
|
* |
|
24
|
|
|
* @since %VERSION% |
|
25
|
|
|
* @var Yikes_Inc_Easy_MailChimp_API_Account |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $account_manager = null; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Our API instance. |
|
31
|
|
|
* |
|
32
|
|
|
* @since %VERSION% |
|
33
|
|
|
* @var Yikes_Inc_Easy_MailChimp_API[] |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $api = array(); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The whole API key. |
|
39
|
|
|
* |
|
40
|
|
|
* @since %VERSION% |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $api_key = ''; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Yikes_Inc_Easy_MailChimp_API_Chimp_Chatter instance. |
|
47
|
|
|
* |
|
48
|
|
|
* @since %VERSION% |
|
49
|
|
|
* @var Yikes_Inc_Easy_MailChimp_API_Chimp_Chatter |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $chimp_chatter = null; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* The Datacenter for the MailChimp account. |
|
55
|
|
|
* |
|
56
|
|
|
* @since %VERSION% |
|
57
|
|
|
* @var string |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $dc = ''; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* The API key with the datacenter portion removed. |
|
63
|
|
|
* |
|
64
|
|
|
* @since %VERSION% |
|
65
|
|
|
* @var string |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $key = ''; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* The list manager instance. |
|
71
|
|
|
* |
|
72
|
|
|
* @since %VERSION% |
|
73
|
|
|
* @var Yikes_Inc_Easy_MailChimp_API_Lists |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $list_manager = null; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Yikes_Inc_Easy_MailChimp_API_Profile instance. |
|
79
|
|
|
* |
|
80
|
|
|
* @since %VERSION% |
|
81
|
|
|
* @var Yikes_Inc_Easy_MailChimp_API_Profile |
|
82
|
|
|
*/ |
|
83
|
|
|
protected $profile = null; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Yikes_Inc_Easy_MailChimp_API_Manager constructor. |
|
87
|
|
|
* |
|
88
|
|
|
* @since %VERSION% |
|
89
|
|
|
* |
|
90
|
|
|
* @param string $api_key The full API key from MailChimp. |
|
91
|
|
|
*/ |
|
92
|
|
|
public function __construct( $api_key = '' ) { |
|
93
|
|
|
if ( empty( $api_key ) ) { |
|
94
|
|
|
$api_key = yikes_get_mc_api_key(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$this->api_key = $api_key; |
|
98
|
|
|
$parts = $this->get_api_key_parts(); |
|
99
|
|
|
$this->key = $parts['key']; |
|
100
|
|
|
$this->dc = $parts['dc']; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get the API key. |
|
105
|
|
|
* |
|
106
|
|
|
* @author Jeremy Pry |
|
107
|
|
|
* @since %VERSION% |
|
108
|
|
|
* @return string The API key with the datacenter portion removed. |
|
109
|
|
|
*/ |
|
110
|
|
|
public function get_api_key() { |
|
111
|
|
|
return $this->key; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Get the array of API Key parts. |
|
116
|
|
|
* |
|
117
|
|
|
* @author Jeremy Pry |
|
118
|
|
|
* @since %VERSION% |
|
119
|
|
|
* @return array Associative array of API key parts. |
|
120
|
|
|
*/ |
|
121
|
|
|
protected function get_api_key_parts() { |
|
122
|
|
|
$parts = explode( '-', $this->api_key ); |
|
123
|
|
|
|
|
124
|
|
|
return array( |
|
125
|
|
|
'key' => $parts[0], |
|
126
|
|
|
'dc' => isset( $parts[1] ) ? $parts[1] : '', |
|
127
|
|
|
); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Get the Datacenter for the MailChimp account. |
|
132
|
|
|
* |
|
133
|
|
|
* @author Jeremy Pry |
|
134
|
|
|
* @since %VERSION% |
|
135
|
|
|
* @return string The datacenter for the MailChimp Account. |
|
136
|
|
|
*/ |
|
137
|
|
|
public function get_datacenter() { |
|
138
|
|
|
return $this->dc; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Get the default version of the API to use. |
|
143
|
|
|
* |
|
144
|
|
|
* @author Jeremy Pry |
|
145
|
|
|
* @since %VERSION% |
|
146
|
|
|
* @return string |
|
147
|
|
|
*/ |
|
148
|
|
|
public function get_default_api_version() { |
|
149
|
|
|
/** |
|
150
|
|
|
* Filter the default MailChimp API version. |
|
151
|
|
|
* |
|
152
|
|
|
* @since %VERSION% |
|
153
|
|
|
* |
|
154
|
|
|
* @param string $version The default MailChimp API version. |
|
155
|
|
|
*/ |
|
156
|
|
|
return apply_filters( 'yikesinc_eme_default_api_version', '3.0' ); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Get the API instance. |
|
161
|
|
|
* |
|
162
|
|
|
* @author Jeremy Pry |
|
163
|
|
|
* @since %VERSION% |
|
164
|
|
|
* |
|
165
|
|
|
* @param string $version The API version instance to retrieve. |
|
166
|
|
|
* |
|
167
|
|
|
* @return Yikes_Inc_Easy_MailChimp_API |
|
168
|
|
|
*/ |
|
169
|
|
|
public function get_api( $version = '' ) { |
|
170
|
|
|
$version = $version ?: $this->get_default_api_version(); |
|
171
|
|
|
|
|
172
|
|
|
if ( ! array_key_exists( $version, $this->api ) || null === $this->api[ $version ] ) { |
|
173
|
|
|
$this->api[ $version ] = new Yikes_Inc_Easy_MailChimp_API( $this->get_datacenter(), $this->get_api_key(), $version ); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
return $this->api[ $version ]; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Get the List Manager instance. |
|
181
|
|
|
* |
|
182
|
|
|
* @author Jeremy Pry |
|
183
|
|
|
* @since %VERSION% |
|
184
|
|
|
* @return Yikes_Inc_Easy_MailChimp_API_Lists |
|
185
|
|
|
*/ |
|
186
|
|
|
public function get_list_handler() { |
|
187
|
|
|
if ( null == $this->list_manager ) { |
|
188
|
|
|
$this->list_manager = new Yikes_Inc_Easy_MailChimp_API_Lists( $this->get_api() ); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
return $this->list_manager; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* Get the Account Manager instance. |
|
196
|
|
|
* |
|
197
|
|
|
* @author Jeremy Pry |
|
198
|
|
|
* @since %VERSION% |
|
199
|
|
|
* @return Yikes_Inc_Easy_MailChimp_API_Account |
|
200
|
|
|
*/ |
|
201
|
|
|
public function get_account_handler() { |
|
202
|
|
|
if ( null === $this->account_manager ) { |
|
203
|
|
|
$this->account_manager = new Yikes_Inc_Easy_MailChimp_API_Account( $this->get_api() ); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
return $this->account_manager; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Get the chimp chatter instance. |
|
211
|
|
|
* |
|
212
|
|
|
* @author Jeremy Pry |
|
213
|
|
|
* @since %VERSION% |
|
214
|
|
|
* @return Yikes_Inc_Easy_MailChimp_API_Chimp_Chatter |
|
215
|
|
|
*/ |
|
216
|
|
|
public function get_chimp_chatter() { |
|
217
|
|
|
if ( null === $this->chimp_chatter ) { |
|
218
|
|
|
$this->chimp_chatter = new Yikes_Inc_Easy_MailChimp_API_Chimp_Chatter( $this->get_api( '2.0' ) ); |
|
|
|
|
|
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
return $this->chimp_chatter; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* Get the User Profile instance. |
|
226
|
|
|
* |
|
227
|
|
|
* This uses the V2 API. |
|
228
|
|
|
* |
|
229
|
|
|
* @author Jeremy Pry |
|
230
|
|
|
* @since %VERSION% |
|
231
|
|
|
* @return Yikes_Inc_Easy_MailChimp_API_Profile |
|
232
|
|
|
*/ |
|
233
|
|
|
public function get_profile_handler() { |
|
234
|
|
|
if ( null === $this->profile ) { |
|
235
|
|
|
$this->profile = new Yikes_Inc_Easy_MailChimp_API_Profile( $this->get_api( '2.0' ) ); |
|
|
|
|
|
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
return $this->profile; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Get the Account Details instance. |
|
243
|
|
|
* |
|
244
|
|
|
* @author Jeremy Pry |
|
245
|
|
|
* @since %VERSION% |
|
246
|
|
|
* @return Yikes_Inc_Easy_MailChimp_API_Account_Details |
|
247
|
|
|
*/ |
|
248
|
|
|
public function get_account_details_handler() { |
|
249
|
|
|
if ( null === $this->account_details ) { |
|
250
|
|
|
$this->account_details = new Yikes_Inc_Easy_MailChimp_API_Account_Details( $this->get_api( '2.0' ) ); |
|
|
|
|
|
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
return $this->account_details; |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.