PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.8.14
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.8.14
7.8.14 7.8.14.1 7.8.13 7.8.13.1 trunk 3.0 3.1 3.1.1 3.1.2 3.1.3 3.1.4 4.3.2 4.4.4 4.4.5 4.4.5.1 4.4.5.4 4.6 4.6.1.1 4.6.1.4 4.7.0.2 4.7.0.3 4.7.0.7 4.7.0.9 4.7.1.0 4.7.1.1 4.8.0.0 5.0.0 5.0.1 5.0.1.1 5.0.1.2 5.1 5.1.1 5.1.2 5.1.3 5.1.3.1 5.1.3.2 5.1.4 5.1.5 6.0 6.0.1 6.0.2 6.0.3 6.0.4.2 6.0.5 6.0.6.1 6.0.7 6.0.8.1 6.0.9 7.0.0.1 7.0.2 7.0.3 7.0.4 7.1.0 7.1.1 7.2.0 7.2.1 7.3.0 7.3.1 7.3.3 7.3.5 7.3.6 7.3.7 7.4.0 7.4.1 7.4.11 7.4.13 7.4.13.1 7.4.2 7.4.3 7.4.4 7.4.5 7.4.5.1 7.4.5.2 7.4.6 7.4.7 7.5.0 7.6.0 7.6.1 7.6.3 7.6.4 7.6.6 7.7.0 7.7.1 7.8.0 7.8.1 7.8.10 7.8.10.1 7.8.10.2 7.8.11 7.8.12 7.8.12.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.8.9.1 7.8.9.2 7.8.9.3
wordpress-popup / inc / providers / constantcontact / CtCt / ConstantContact.php
wordpress-popup / inc / providers / constantcontact / CtCt Last commit date
Auth 3 years ago Components 2 years ago Exceptions 6 years ago Services 6 years ago Util 3 years ago WebHooks 6 years ago ConstantContact.php 6 years ago SplClassLoader.php 6 years ago autoload.php 6 years ago
ConstantContact.php
927 lines
1 <?php
2 namespace Ctct;
3
4 use Ctct\Services\AccountService;
5 use Ctct\Services\ContactService;
6 use Ctct\Services\LibraryService;
7 use Ctct\Services\ListService;
8 use Ctct\Services\EmailMarketingService;
9 use Ctct\Services\CampaignScheduleService;
10 use Ctct\Services\CampaignTrackingService;
11 use Ctct\Services\ContactTrackingService;
12 use Ctct\Services\ActivityService;
13 use Ctct\Components\Account\AccountInfo;
14 use Ctct\Components\Activities\Activity;
15 use Ctct\Components\Contacts\Contact;
16 use Ctct\Components\Contacts\ContactList;
17 use Ctct\Components\EmailMarketing\Campaign;
18 use Ctct\Components\EmailMarketing\Schedule;
19 use Ctct\Components\EmailMarketing\TestSend;
20 use Ctct\Components\ResultSet;
21 use Ctct\Components\Tracking\TrackingSummary;
22 use Ctct\Components\Activities\AddContacts;
23 use Ctct\Components\Activities\ExportContacts;
24 use Ctct\Exceptions\IllegalArgumentException;
25 use Ctct\Util\Config;
26
27 /**
28 * Exposes all implemented Constant Contact API functionality
29 *
30 * @package Ctct
31 * @version 1.1.0
32 * @author Constant Contact
33 * @link https://developer.constantcontact.com
34 */
35 class ConstantContact
36 {
37 /**
38 * Constant Contact API Key
39 * @var string
40 */
41 private $apiKey;
42
43 /**
44 * Handles handling interaction with contact management
45 * @var ContactService
46 */
47 public $contactService;
48
49 /**
50 * Handles interaction with email marketing
51 * @var EmailMarketingService
52 */
53 protected $emailMarketingService;
54
55 /**
56 * Handles interaction with contact list management
57 * @var ListService
58 */
59 public $listService;
60
61 /**
62 * ActivityService for handling interaction with bulk activities
63 * @var ActivityService
64 */
65 protected $activityService;
66
67 /**
68 * Handles interaction with email marketing tracking
69 * @var CampaignTrackingService
70 */
71 protected $campaignTrackingService;
72
73 /**
74 * Handles interaction with contact tracking
75 * @var ContactTrackingService
76 */
77 protected $contactTrackingService;
78
79 /**
80 * Handles interaction with email marketing campaign scheduling
81 * @var CampaignScheduleService
82 */
83 protected $campaignScheduleService;
84
85 /**
86 * Handles interaction with account management
87 * @var AccountService
88 */
89 protected $accountService;
90
91 /**
92 * Handles interaction with Library management
93 * @var LibraryService
94 */
95 protected $libraryService;
96
97 /**
98 * Class constructor
99 * Registers the API key with the ConstantContact class that will be used for all API calls.
100 * @param string $apiKey - Constant Contact API Key
101 */
102 public function __construct($apiKey)
103 {
104 $this->apiKey = $apiKey;
105 $this->contactService = new ContactService($apiKey);
106 $this->emailMarketingService = new EmailMarketingService($apiKey);
107 $this->activityService = new ActivityService($apiKey);
108 $this->campaignTrackingService = new CampaignTrackingService($apiKey);
109 $this->contactTrackingService = new ContactTrackingService($apiKey);
110 $this->campaignScheduleService = new CampaignScheduleService($apiKey);
111 $this->listService = new ListService($apiKey);
112 $this->accountService = new AccountService($apiKey);
113 $this->libraryService = new LibraryService($apiKey);
114 }
115
116 /**
117 * Get a set of campaigns
118 * @param string $accessToken - Constant Contact OAuth2 access token
119 * @param mixed $params - associative array of query parameters and values to append to the request.
120 * Allowed parameters include:
121 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
122 * modified_since - ISO-8601 formatted timestamp.
123 * next - the next link returned from a previous paginated call. May only be used by itself.
124 * email - the contact by email address to retrieve information for.
125 * status - a contact status to filter results by. Must be one of ACTIVE, OPTOUT, REMOVED, UNCONFIRMED.
126 * @return ResultSet containing a results array of {@link Ctct\Components\Contacts\Contact}
127 */
128 public function getContacts($accessToken, array $params = array())
129 {
130 return $this->contactService->getContacts($accessToken, $params);
131 }
132
133 /**
134 * Get an individual contact
135 * @param string $accessToken - Valid access token
136 * @param int $contactId - Id of the contact to retrieve
137 * @return Contact
138 */
139 public function getContact($accessToken, $contactId)
140 {
141 return $this->contactService->getContact($accessToken, $contactId);
142 }
143
144 /**
145 * Get contacts with a specified email address
146 * @param string $accessToken - Constant Contact OAuth2 access token
147 * @param string $email - contact email address to search for
148 * @return ResultSet
149 */
150 public function getContactByEmail($accessToken, $email)
151 {
152 return $this->contactService->getContacts($accessToken, array('email' => $email));
153 }
154
155 /**
156 * Add a new contact to an account
157 * @param string $accessToken - Valid access token
158 * @param Contact $contact - Contact to add
159 * @param boolean $actionByVisitor - is the action being taken by the visitor
160 * @return Contact
161 */
162 public function addContact($accessToken, Contact $contact, $actionByVisitor = false)
163 {
164 $params = array();
165 if ($actionByVisitor == true) {
166 $params['action_by'] = "ACTION_BY_VISITOR";
167 }
168 return $this->contactService->addContact($accessToken, $contact, $params);
169 }
170
171 /**
172 * Sets an individual contact to 'REMOVED' status
173 * @param string $accessToken - Valid access token
174 * @param mixed $contact - Either a Contact id or the Contact itself
175 * @throws IllegalArgumentException - if an int or Contact object is not provided
176 * @return boolean
177 */
178 public function deleteContact($accessToken, $contact)
179 {
180 $contactId = $this->getArgumentId($contact, 'Contact');
181 return $this->contactService->deleteContact($accessToken, $contactId);
182 }
183
184 /**
185 * Delete a contact from all contact lists
186 * @param string $accessToken - Constant Contact OAuth2 access token
187 * @param mixed $contact - Contact id or the Contact object itself
188 * @throws IllegalArgumentException - if an int or Contact object is not provided
189 * @return boolean
190 */
191 public function deleteContactFromLists($accessToken, $contact)
192 {
193 $contactId = $this->getArgumentId($contact, 'Contact');
194 return $this->contactService->deleteContactFromLists($accessToken, $contactId);
195 }
196
197 /**
198 * Delete a contact from all contact lists
199 * @param string $accessToken - Constant Contact OAuth2 access token
200 * @param mixed $contact - Contact id or a Contact object
201 * @param mixed $list - ContactList id or a ContactList object
202 * @throws IllegalArgumentException - if an int or Contact object is not provided,
203 * as well as an int or ContactList object
204 * @return boolean
205 */
206 public function deleteContactFromList($accessToken, $contact, $list)
207 {
208 $contactId = $this->getArgumentId($contact, 'Contact');
209 $listId = $this->getArgumentId($list, 'ContactList');
210
211 return $this->contactService->deleteContactFromList($accessToken, $contactId, $listId);
212 }
213
214 /**
215 * Update an individual contact
216 * @param string $accessToken - Valid access token
217 * @param Contact $contact - Contact to update
218 * @param boolean $actionByVisitor - is the action being taken by the visitor, default is false
219 * @return Contact
220 */
221 public function updateContact($accessToken, Contact $contact, $actionByVisitor = false)
222 {
223 $params = array();
224 if ($actionByVisitor == true) {
225 $params['action_by'] = "ACTION_BY_VISITOR";
226 }
227 return $this->contactService->updateContact($accessToken, $contact, $params);
228 }
229
230 /**
231 * Get lists
232 * @param string $accessToken - Valid access token
233 * @param array $params - associative array of query parameters and values to append to the request.
234 * Allowed parameters include:
235 * modified_since - ISO-8601 formatted timestamp.
236 * @return array of ContactList
237 */
238 public function getLists($accessToken, array $params = array())
239 {
240 return $this->listService->getLists($accessToken, $params);
241 }
242
243 /**
244 * Get an individual list
245 * @param string $accessToken - Valid access token
246 * @param int $listId - Id of the list to retrieve
247 * @return ContactList
248 */
249 public function getList($accessToken, $listId)
250 {
251 return $this->listService->getList($accessToken, $listId);
252 }
253
254 /**
255 * Add a new contact list to an account
256 * @param string $accessToken - Valid access token
257 * @param ContactList $list - List to add
258 * @return ContactList
259 */
260 public function addList($accessToken, ContactList $list)
261 {
262 return $this->listService->addList($accessToken, $list);
263 }
264
265 /**
266 * Update a contact list
267 * @param string $accessToken - Valid access token
268 * @param ContactList $list - ContactList to update
269 * @return ContactList
270 */
271 public function updateList($accessToken, ContactList $list)
272 {
273 return $this->listService->updateList($accessToken, $list);
274 }
275
276 /**
277 * Delete a contact list from an account
278 * @param string $accessToken - Valid access token
279 * @param int $listId - Id of the list to delete
280 * @return boolean
281 */
282 public function deleteList($accessToken, $listId)
283 {
284 return $this->listService->deleteList($accessToken, $listId);
285 }
286
287 /**
288 * Get contact that belong to a specific list
289 * @param string $accessToken - Constant Contact OAuth2 access token
290 * @param mixed $list - Id of the list or a ContactList object
291 * @param mixed $param - denotes the number of results per set, limited to 50, or a next parameter provided
292 * from a previous getContactsFromList call
293 * @return ResultSet
294 * @throws IllegalArgumentException - if a ContactList object or id is not passed
295 */
296 public function getContactsFromList($accessToken, $list, $param = null)
297 {
298 $listId = $this->getArgumentId($list, 'ContactList');
299 $param = $this->determineParam($param);
300 return $this->listService->getContactsFromList($accessToken, $listId, $param);
301 }
302
303 /**
304 * Get a set of campaigns
305 * @param string $accessToken - Constant Contact OAuth2 access token
306 * @param mixed $params - associative array of query parameters and values to append to the request.
307 * Allowed parameters include:
308 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
309 * modified_since - ISO-8601 formatted timestamp.
310 * next - the next link returned from a previous paginated call. May only be used by itself.
311 * email - the contact by email address to retrieve information for
312 * @return ResultSet containing a results array of {@link Ctct\Components\EmailMarketing\Campaign}
313 */
314 public function getEmailCampaigns($accessToken, array $params = array())
315 {
316 return $this->emailMarketingService->getCampaigns($accessToken, $params);
317 }
318
319 /**
320 * Get an individual campaign
321 * @param string $accessToken - Constant Contact OAuth2 access token
322 * @param int $campaignId - Valid campaign id
323 * @return \Ctct\Components\EmailMarketing\Campaign
324 */
325 public function getEmailCampaign($accessToken, $campaignId)
326 {
327 return $this->emailMarketingService->getCampaign($accessToken, $campaignId);
328 }
329
330 /**
331 * Delete an individual campaign
332 * @param string $accessToken - Constant Contact OAuth2 access token
333 * @param mixed $campaign - Id of a campaign or a Campaign object itself
334 * @throws IllegalArgumentException - if a Campaign object or campaign id is not passed
335 * @return boolean
336 */
337 public function deleteEmailCampaign($accessToken, $campaign)
338 {
339 $campaignId = $this->getArgumentId($campaign, 'Campaign');
340 return $this->emailMarketingService->deleteCampaign($accessToken, $campaignId);
341 }
342
343 /**
344 * Create a new campaign
345 * @param string $accessToken - Constant Contact OAuth2 access token
346 * @param Campaign $campaign - Campaign to be created
347 * @return Campaign - created campaign
348 */
349 public function addEmailCampaign($accessToken, Campaign $campaign)
350 {
351 return $this->emailMarketingService->addCampaign($accessToken, $campaign);
352 }
353
354 /**
355 * Update a specific campaign
356 * @param string $accessToken - Constant Contact OAuth2 access token
357 * @param Campaign $campaign - Campaign to be updated
358 * @return Campaign - updated campaign
359 */
360 public function updateEmailCampaign($accessToken, Campaign $campaign)
361 {
362 return $this->emailMarketingService->updateCampaign($accessToken, $campaign);
363 }
364
365 /**
366 * Schedule a campaign to be sent
367 * @param string $accessToken - Constant Contact OAuth2 access token
368 * @param mixed $campaign - Campaign to be updated
369 * @param Schedule $schedule - Schedule to be associated with the provided campaign
370 * @return Schedule schedule created
371 */
372 public function addEmailCampaignSchedule($accessToken, $campaign, Schedule $schedule)
373 {
374 $campaignId = $this->getArgumentId($campaign, 'Campaign');
375 return $this->campaignScheduleService->addSchedule($accessToken, $campaignId, $schedule);
376 }
377
378 /**
379 * Get an array of schedules associated with a given campaign
380 * @param string $accessToken - Constant Contact OAuth2 access token
381 * @param mixed $campaign - Campaign id or Campaign object itself
382 * @return array
383 */
384 public function getEmailCampaignSchedules($accessToken, $campaign)
385 {
386 $campaignId = $this->getArgumentId($campaign, 'Campaign');
387 return $this->campaignScheduleService->getSchedules($accessToken, $campaignId);
388 }
389
390 /**
391 * Get a specific schedule associated with a given campaign
392 * @param string $accessToken - Constant Contact OAuth2 access token
393 * @param mixed $campaign - Campaign id or Campaign object itself
394 * @param mixed $schedule - Schedule id or Schedule object itself
395 * @throws IllegalArgumentException
396 * @return Schedule
397 */
398 public function getEmailCampaignSchedule($accessToken, $campaign, $schedule)
399 {
400 $campaignId = $this->getArgumentId($campaign, 'Campaign');
401 $scheduleId = null;
402
403 if ($schedule instanceof Schedule) {
404 $scheduleId = $schedule->id;
405 } elseif (is_numeric($schedule)) {
406 $scheduleId = $schedule;
407 } else {
408 throw new IllegalArgumentException(sprintf(Config::get('errors.id_or_object'), 'Schedule'));
409 }
410
411 return $this->campaignScheduleService->getSchedule($accessToken, $campaignId, $scheduleId);
412 }
413
414 /**
415 * Update a specific schedule associated with a given campaign
416 * @param string $accessToken - Constant Contact OAuth2 access token
417 * @param mixed $campaign - Campaign id or Campaign object itself
418 * @param Schedule $schedule - Schedule to be updated
419 * @return Schedule
420 */
421 public function updateEmailCampaignSchedule($accessToken, $campaign, Schedule $schedule)
422 {
423 $campaignId = $this->getArgumentId($campaign, 'Campaign');
424 return $this->campaignScheduleService->updateSchedule($accessToken, $campaignId, $schedule);
425 }
426
427 /**
428 * Delete a specific schedule associated with a given campaign
429 * @param string $accessToken - Constant Contact OAuth2 access token
430 * @param mixed $campaign - Campaign id or Campaign object itself
431 * @param mixed $schedule - Schedule id or Schedule object itself
432 * @throws IllegalArgumentException
433 * @return boolean
434 */
435 public function deleteEmailCampaignSchedule($accessToken, $campaign, $schedule)
436 {
437 $campaignId = $this->getArgumentId($campaign, 'Campaign');
438 $scheduleId = null;
439
440 if ($schedule instanceof Schedule) {
441 $scheduleId = $schedule->id;
442 } elseif (is_numeric($schedule)) {
443 $scheduleId = $schedule;
444 } else {
445 throw new IllegalArgumentException(sprintf(Config::get('errors.id_or_object'), 'Schedule'));
446 }
447
448 return $this->campaignScheduleService->deleteSchedule($accessToken, $campaignId, $scheduleId);
449 }
450
451 /**
452 * Send a test send of a campaign
453 * @param string $accessToken - Constant Contact OAuth2 access token
454 * @param mixed $campaign - Campaign id or Campaign object itself
455 * @param TestSend $testSend - test send details
456 * @return TestSend
457 */
458 public function sendEmailCampaignTest($accessToken, $campaign, TestSend $testSend)
459 {
460 $campaignId = $this->getArgumentId($campaign, 'Campaign');
461 return $this->campaignScheduleService->sendTest($accessToken, $campaignId, $testSend);
462 }
463
464 /**
465 * Get sends for a campaign
466 * @param string $accessToken - Constant Contact OAuth2 access token
467 * @param mixed $campaign - Campaign id or Campaign object itself
468 * @param mixed $params - associative array of query parameters and values to append to the request.
469 * Allowed parameters include:
470 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
471 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
472 * next - the next link returned from a previous paginated call. May only be used by itself.
473 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\SendActivity}
474 */
475 public function getEmailCampaignSends($accessToken, $campaign, array $params = array())
476 {
477 $campaignId = $this->getArgumentId($campaign, 'Campaign');
478 return $this->campaignTrackingService->getSends($accessToken, $campaignId, $params);
479 }
480
481 /**
482 * Get bounces for a campaign
483 * @param string $accessToken - Constant Contact OAuth2 access token
484 * @param mixed $campaign - Campaign id or Campaign object itself
485 * @param mixed $params - associative array of query parameters and values to append to the request.
486 * Allowed parameters include:
487 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
488 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
489 * next - the next link returned from a previous paginated call. May only be used by itself.
490 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\BounceActivity}
491 */
492 public function getEmailCampaignBounces($accessToken, $campaign, array $params = array())
493 {
494 $campaignId = $this->getArgumentId($campaign, 'Campaign');
495 return $this->campaignTrackingService->getBounces($accessToken, $campaignId, $params);
496 }
497
498 /**
499 * Get clicks for a campaign
500 * @param string $accessToken - Constant Contact OAuth2 access token
501 * @param mixed $campaign - Campaign id or Campaign object itself
502 * @param array $params - associative array of query parameters and values to append to the request.
503 * Allowed parameters include:
504 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
505 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
506 * next - the next link returned from a previous paginated call. May only be used by itself.
507 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\ClickActivity}
508 */
509 public function getEmailCampaignClicks($accessToken, $campaign, array $params = array())
510 {
511 $campaignId = $this->getArgumentId($campaign, 'Campaign');
512 return $this->campaignTrackingService->getClicks($accessToken, $campaignId, $params);
513 }
514
515 /**
516 * Get opens for a campaign
517 * @param string $accessToken - Constant Contact OAuth2 access token
518 * @param mixed $campaign - Campaign id or Campaign object itself
519 * @param mixed $params - associative array of query parameters and values to append to the request.
520 * Allowed parameters include:
521 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
522 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
523 * next - the next link returned from a previous paginated call. May only be used by itself.
524 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\OpenActivity}
525 */
526 public function getEmailCampaignOpens($accessToken, $campaign, array $params = array())
527 {
528 $campaignId = $this->getArgumentId($campaign, 'Campaign');
529 return $this->campaignTrackingService->getOpens($accessToken, $campaignId, $params);
530 }
531
532 /**
533 * Get forwards for a campaign
534 * @param string $accessToken - Constant Contact OAuth2 access token
535 * @param mixed $campaign - Campaign id or Campaign object itself
536 * @param mixed $params - associative array of query parameters and values to append to the request.
537 * Allowed parameters include:
538 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
539 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
540 * next - the next link returned from a previous paginated call. May only be used by itself.
541 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\ForwardActivity}
542 */
543 public function getEmailCampaignForwards($accessToken, $campaign, array $params = array())
544 {
545 $campaignId = $this->getArgumentId($campaign, 'Campaign');
546 return $this->campaignTrackingService->getForwards($accessToken, $campaignId, $params);
547 }
548
549 /**
550 * Get unsubscribes for a campaign
551 * @param string $accessToken - Constant Contact OAuth2 access token
552 * @param mixed $campaign - Campaign id or Campaign object itself
553 * @param mixed $params - associative array of query parameters and values to append to the request.
554 * Allowed parameters include:
555 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
556 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
557 * next - the next link returned from a previous paginated call. May only be used by itself.
558 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\UnsubscribeActivity}
559 */
560 public function getEmailCampaignUnsubscribes($accessToken, $campaign, array $params = array())
561 {
562 $campaignId = $this->getArgumentId($campaign, 'Campaign');
563 return $this->campaignTrackingService->getUnsubscribes($accessToken, $campaignId, $params);
564 }
565
566 /**
567 * Get a reporting summary for a campaign
568 * @param string $accessToken - Constant Contact OAuth2 access token
569 * @param mixed $campaign - Campaign id or Campaign object itself
570 * @return TrackingSummary
571 */
572 public function getEmailCampaignSummaryReport($accessToken, $campaign)
573 {
574 $campaignId = $this->getArgumentId($campaign, 'Campaign');
575 return $this->campaignTrackingService->getSummary($accessToken, $campaignId);
576 }
577
578 /**
579 * Get sends for a Contact
580 * @param string $accessToken - Constant Contact OAuth2 access token
581 * @param mixed $contact - Contact id or Contact object itself
582 * @param mixed $params - associative array of query parameters and values to append to the request.
583 * Allowed parameters include:
584 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
585 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
586 * next - the next link returned from a previous paginated call. May only be used by itself.
587 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\SendActivity}
588 */
589 public function getContactSends($accessToken, $contact, array $params = array())
590 {
591 $contactId = $this->getArgumentId($contact, 'Contact');
592 return $this->contactTrackingService->getSends($accessToken, $contactId, $params);
593 }
594
595 /**
596 * Get bounces for a Contact
597 * @param string $accessToken - Constant Contact OAuth2 access token
598 * @param mixed $contact - Contact id or Contact object itself
599 * @param mixed $params - associative array of query parameters and values to append to the request.
600 * Allowed parameters include:
601 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
602 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
603 * next - the next link returned from a previous paginated call. May only be used by itself.
604 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\BounceActivity}
605 */
606 public function getContactBounces($accessToken, $contact, array $params = array())
607 {
608 $contactId = $this->getArgumentId($contact, 'Contact');
609 return $this->contactTrackingService->getBounces($accessToken, $contactId, $params);
610 }
611
612 /**
613 * Get clicks for a Contact
614 * @param string $accessToken - Constant Contact OAuth2 access token
615 * @param mixed $contact - Contact id or Contact object itself
616 * @param mixed $params - associative array of query parameters and values to append to the request.
617 * Allowed parameters include:
618 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
619 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
620 * next - the next link returned from a previous paginated call. May only be used by itself.
621 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\ClickActivity}
622 */
623 public function getContactClicks($accessToken, $contact, array $params = array())
624 {
625 $contactId = $this->getArgumentId($contact, 'Contact');
626 return $this->contactTrackingService->getClicks($accessToken, $contactId, $params);
627 }
628
629 /**
630 * Get opens for a Contact
631 * @param string $accessToken - Constant Contact OAuth2 access token
632 * @param mixed $contact - Contact id or Contact object itself
633 * @param mixed $params - associative array of query parameters and values to append to the request.
634 * Allowed parameters include:
635 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
636 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
637 * next - the next link returned from a previous paginated call. May only be used by itself.
638 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\OpenActivity}
639 */
640 public function getContactOpens($accessToken, $contact, array $params = array())
641 {
642 $contactId = $this->getArgumentId($contact, 'Contact');
643 return $this->contactTrackingService->getOpens($accessToken, $contactId, $params);
644 }
645
646 /**
647 * Get forwards for a Contact
648 * @param string $accessToken - Constant Contact OAuth2 access token
649 * @param mixed $contact - Contact id or Contact object itself
650 * @param mixed $params - associative array of query parameters and values to append to the request.
651 * Allowed parameters include:
652 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
653 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
654 * next - the next link returned from a previous paginated call. May only be used by itself.
655 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\ForwardActivity}
656 */
657 public function getContactForwards($accessToken, $contact, array $params = array())
658 {
659 $contactId = $this->getArgumentId($contact, 'Contact');
660 return $this->contactTrackingService->getForwards($accessToken, $contactId, $params);
661 }
662
663 /**
664 * Get opt outs for a Contact
665 * @param string $accessToken - Constant Contact OAuth2 access token
666 * @param mixed $contact - Contact id or Contact object itself
667 * @param mixed $params - associative array of query parameters and values to append to the request.
668 * Allowed parameters include:
669 * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
670 * created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
671 * next - the next link returned from a previous paginated call. May only be used by itself.
672 * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\UnsubscribeActivity}
673 */
674 public function getContactUnsubscribes($accessToken, $contact, array $params = array())
675 {
676 $contactId = $this->getArgumentId($contact, 'Contact');
677 return $this->contactTrackingService->getUnsubscribes($accessToken, $contactId, $params);
678 }
679
680 /**
681 * Get verified addresses for the account
682 * @param string $accessToken - Constant Contact OAuth2 access token
683 * @param string $status - Status to filter query results by
684 * @return array of VerifiedEmailAddress objects
685 */
686 public function getVerifiedEmailAddresses($accessToken, $status = null)
687 {
688 $params = array();
689 if ($status) {
690 $params['status'] = $status;
691 }
692 return $this->accountService->getVerifiedEmailAddresses($accessToken, $params);
693 }
694
695 /**
696 * Create new verified email addresses. This will also prompt the account to send
697 * a verification email to the address.
698 * @param string $accessToken - Constant Contact OAuth2 Access Token
699 * @param string $emailAddress - email address to create
700 * @return array - array of VerifiedEmailAddress created
701 */
702 public function createVerifiedEmailAddress($accessToken, $emailAddress)
703 {
704 return $this->accountService->createVerifiedEmailAddress($accessToken, $emailAddress);
705 }
706
707 /**
708 * Get details for account associated with an access token
709 * @param string $accessToken - Constant Contact OAuth2 access token
710 * @return AccountInfo
711 */
712 public function getAccountInfo($accessToken)
713 {
714 return $this->accountService->getAccountInfo($accessToken);
715 }
716
717 /**
718 * Update information of the account.
719 * @param string $accessToken - Constant Contact OAuth2 Access Token
720 * @param AccountInfo $accountInfo - Updated AccountInfo
721 * @return AccountInfo
722 */
723 public function updateAccountInfo($accessToken, $accountInfo)
724 {
725 return $this->accountService->updateAccountInfo($accessToken, $accountInfo);
726 }
727
728 /**
729 * @param string $accessToken - Constant Contact OAuth2 access token
730 * @param string $fileId - File Id
731 * @return File
732 */
733 public function getLibraryFile($accessToken, $fileId)
734 {
735 return $this->libraryService->getLibraryFile($accessToken, $fileId);
736 }
737
738 /**
739 * @param string $accessToken - Constant Contact OAuth2 access token
740 * @param string $folderId - Optionally search for files in a specified folder
741 * @param mixed $params - associative array of query parameters and values to append to the request.
742 * Allowed parameters include:
743 * limit - Specifies the number of results displayed per page of output, from 1 - 1000, default = 50.
744 * sort_by - Specifies how the list of files is sorted; valid sort options are:
745 * CREATED_DATE, CREATED_DATE_DESC, MODIFIED_DATE, MODIFIED_DATE_DESC, NAME, NAME_DESC, SIZE, SIZE_DESC DIMENSION, DIMENSION_DESC
746 * source - Specifies to retrieve files from a particular source:
747 * ALL, MyComputer, Facebook, Instagram, Shutterstock, Mobile
748 * next - the next link returned from a previous paginated call. May only be used by itself.
749 * @return ResultSet - Containing a results array of {@link Ctct\Components\Library\File}
750 */
751 public function getLibraryFiles($accessToken, $folderId = null, array $params = array())
752 {
753 if ($folderId) {
754 return $this->libraryService->getLibraryFilesByFolder($accessToken, $folderId, $params);
755 }
756 return $this->libraryService->getLibraryFiles($accessToken, $params);
757 }
758
759 /**
760 * @param string $accessToken - Constant Contact OAuth2 access token
761 * @param mixed $params - associative array of query parameters and values to append to the request.
762 * Allowed parameters include:
763 * limit - Specifies the number of results displayed per page of output, from 1 - 1000, default = 50.
764 * sort_by - Specifies how the list of files is sorted; valid sort options are:
765 * CREATED_DATE, CREATED_DATE_DESC, MODIFIED_DATE, MODIFIED_DATE_DESC, NAME, NAME_DESC
766 * @return ResultSet
767 */
768 public function getLibraryFolders($accessToken, array $params = array())
769 {
770 return $this->libraryService->getLibraryFolders($accessToken, $params);
771 }
772
773 /**
774 * Get a reporting summary for a Contact
775 * @param string $accessToken - Constant Contact OAuth2 access token
776 * @param mixed $contact - Contact id or Contact object itself
777 * @return TrackingSummary
778 */
779 public function getContactSummaryReport($accessToken, $contact)
780 {
781 $contactId = $this->getArgumentId($contact, 'Contact');
782 return $this->contactTrackingService->getSummary($accessToken, $contactId);
783 }
784
785 /**
786 * Get an array of activities
787 * @param string $accessToken - Constant Contact OAuth2 access token
788 * @param array $params - associative array of query parameters and values to append to the request.
789 * Allowed parameters include:
790 * status - Status of the activity, must be one of UNCONFIRMED, PENDING, QUEUED, RUNNING, COMPLETE, ERROR
791 * type - Type of activity, must be one of ADD_CONTACTS, REMOVE_CONTACTS_FROM_LISTS, CLEAR_CONTACTS_FROM_LISTS,
792 * EXPORT_CONTACTS
793 * @return Activity
794 */
795 public function getActivities($accessToken, array $params = array())
796 {
797 return $this->activityService->getActivities($accessToken, $params);
798 }
799
800 /**
801 * Get a single activity by id
802 * @param string $accessToken - Constant Contact OAuth2 access token
803 * @param string $activityId - Activity id
804 * @return Activity
805 */
806 public function getActivity($accessToken, $activityId)
807 {
808 return $this->activityService->getActivity($accessToken, $activityId);
809 }
810
811 /**
812 * Add an AddContacts Activity to add contacts in bulk
813 * @param string $accessToken - Constant Contact OAuth2 access token
814 * @param AddContacts $addContactsActivity - Add Contacts Activity
815 * @return Activity
816 */
817 public function addCreateContactsActivity($accessToken, AddContacts $addContactsActivity)
818 {
819 return $this->activityService->createAddContactsActivity($accessToken, $addContactsActivity);
820 }
821
822 /**
823 * Create an Add Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
824 * @param string $accessToken - Constant Contact OAuth2 access token
825 * @param string $fileName - The name of the file (ie: contacts.csv)
826 * @param string $contents - The contents of the file
827 * @param string $lists - Comma separated list of ContactList id's to add the contacts to
828 * @return Activity
829 */
830 public function addCreateContactsActivityFromFile($accessToken, $fileName, $contents, $lists)
831 {
832 return $this->activityService->createAddContactsActivityFromFile($accessToken, $fileName, $contents, $lists);
833 }
834
835 /**
836 * Add an ClearLists Activity to remove all contacts from the provided lists
837 * @param string $accessToken - Constant Contact OAuth2 access token
838 * @param array $lists - Array of list id's to be cleared
839 * @return Activity
840 */
841 public function addClearListsActivity($accessToken, Array $lists)
842 {
843 return $this->activityService->addClearListsActivity($accessToken, $lists);
844 }
845
846 /**
847 * Add a Remove Contacts From Lists Activity
848 * @param string $accessToken - Constant Contact OAuth2 access token
849 * @param array $emailAddresses - email addresses to be removed
850 * @param array $lists - lists to remove the provided email addresses from
851 * @return Activity
852 */
853 public function addRemoveContactsFromListsActivity($accessToken, Array $emailAddresses, Array $lists)
854 {
855 return $this->activityService->addRemoveContactsFromListsActivity($accessToken, $emailAddresses, $lists);
856 }
857
858 /**
859 * Add a Remove Contacts From Lists Activity from a file. Valid file types are txt, csv, xls, xlsx
860 * @param string $accessToken - Constant Contact OAuth2 access token
861 * @param string $fileName - The name of the file (ie: contacts.csv)
862 * @param string $contents - The contents of the file
863 * @param string $lists - Comma separated list of ContactList id' to add the contacts too
864 * @return Activity
865 */
866 public function addRemoveContactsFromListsActivityFromFile($accessToken, $fileName, $contents, $lists)
867 {
868 return $this->activityService->addRemoveContactsFromListsActivityFromFile(
869 $accessToken,
870 $fileName,
871 $contents,
872 $lists
873 );
874 }
875
876 /**
877 * Create an Export Contacts Activity
878 * @param string $accessToken - Constant Contact OAuth2 access token
879 * @param ExportContacts $exportContacts
880 * @return Activity
881 */
882 public function addExportContactsActivity($accessToken, ExportContacts $exportContacts)
883 {
884 return $this->activityService->addExportContactsActivity($accessToken, $exportContacts);
885 }
886
887 /**
888 * Get the id of object, or attempt to convert the argument to an int
889 * @param mixed $item - object or a numeric value
890 * @param string $className - class name to test the given object against
891 * @throws IllegalArgumentException - if the item is not an instance of the class name given, or cannot be
892 * converted to a numeric value
893 * @return int
894 */
895 private function getArgumentId($item, $className)
896 {
897 $id = null;
898
899 if (is_numeric($item)) {
900 $id = $item;
901 } elseif (join('', array_slice(explode('\\', get_class($item)), -1)) == $className) {
902 $id = $item->id;
903 } else {
904 throw new IllegalArgumentException(sprintf(Config::get('errors.id_or_object'), $className));
905 }
906
907 return $id;
908 }
909
910 /**
911 * Builds an array of query parameters to be added to the request
912 * @param string $param
913 * @return array
914 */
915 private function determineParam($param)
916 {
917 $params = array();
918 if (substr($param, 0, 1) === '?') {
919 $param = substr($param, 1);
920 parse_str($param, $params);
921 } else {
922 $params['limit'] = $param;
923 }
924 return $params;
925 }
926 }
927