1: <?php
2: namespace Ctct;
3:
4: use Ctct\Services\AccountService;
5: use Ctct\Services\ContactService;
6: use Ctct\Services\ListService;
7: use Ctct\Services\EmailMarketingService;
8: use Ctct\Services\CampaignScheduleService;
9: use Ctct\Services\CampaignTrackingService;
10: use Ctct\Services\ContactTrackingService;
11: use Ctct\Services\ActivityService;
12: use Ctct\Components\Account\VerifiedEmailAddress;
13: use Ctct\Components\Contacts\Contact;
14: use Ctct\Components\Contacts\ContactList;
15: use Ctct\Components\EmailMarketing\Campaign;
16: use Ctct\Components\EmailMarketing\Schedule;
17: use Ctct\Components\EmailMarketing\TestSend;
18: use Ctct\Components\Tracking\TrackingSummary;
19: use Ctct\Components\Tracking\TrackingActivity;
20: use Ctct\Components\Activities\AddContacts;
21: use Ctct\Components\Activities\ExportContacts;
22: use Ctct\Exceptions\CtctException;
23: use Ctct\Exceptions\IllegalArgumentException;
24: use Ctct\Util\Config;
25:
26: /**
27: * Exposes all implemented Constant Contact API functionality
28: * @package Ctct
29: * @author Constant Contact
30: */
31: class ConstantContact
32: {
33: /**
34: * Constant Contact API Key
35: * @var string
36: */
37: private $apiKey;
38:
39: /**
40: * ContactService
41: * @var ContactService
42: */
43: private $contactService;
44:
45: /**
46: * CampaignService
47: * @var CampaignService
48: */
49: private $EmailMarketingService;
50:
51: /**
52: * ListService
53: * @var ListService
54: */
55: private $listService;
56:
57: /**
58: * ActivityService
59: * @var ActivityService
60: */
61: private $activityService;
62:
63: /**
64: * CampaignTrackingService
65: * @var CampaignTrackingService
66: */
67: private $campaignTrackingService;
68:
69: /**
70: * ContactTrackingService
71: * @var ContactTrackingService
72: */
73: private $contactTrackingService;
74:
75: /**
76: * CampaignScheduleService
77: * @var CampaignScheduleService
78: */
79: private $campaignScheduleService;
80:
81: /**
82: * AccountService
83: * @var AccountService
84: */
85: private $accountService;
86:
87: /**
88: * Class constructor
89: * @param string $apiKey - Constant Contact API Key
90: */
91: public function __construct($apiKey)
92: {
93: $this->api_key = $apiKey;
94: $this->contactService = new ContactService($apiKey);
95: $this->EmailMarketingService = new EmailMarketingService($apiKey);
96: $this->activityService = new ActivityService($apiKey);
97: $this->campaignTrackingService = new CampaignTrackingService($apiKey);
98: $this->contactTrackingService = new ContactTrackingService($apiKey);
99: $this->campaignScheduleService = new CampaignScheduleService($apiKey);
100: $this->listService = new ListService($apiKey);
101: $this->accountService = new AccountService($apiKey);
102: }
103:
104: /**
105: * Get a set of campaigns
106: * @param string $accessToken - Constant Contact OAuth2 access token
107: * @param mixed $param - denotes the number of results per set, limited to 50, or a next parameter provided
108: * from a previous getContacts call
109: * @return ResultSet
110: */
111: public function getContacts($accessToken, $param = null)
112: {
113: $param = $this->determineParam($param);
114: return $this->contactService->getContacts($accessToken, $param);
115: }
116:
117: /**
118: * Get an individual contact
119: * @param string $accessToken - Valid access token
120: * @param int $contactId - Id of the contact to retrieve
121: * @return Contact
122: */
123: public function getContact($accessToken, $contactId)
124: {
125: return $this->contactService->getContact($accessToken, $contactId);
126: }
127:
128: /**
129: * Get contacts with a specified email eaddress
130: * @param string $accessToken - Constant Contact OAuth2 access token
131: * @param string $email - contact email address to search for
132: * @return array
133: */
134: public function getContactByEmail($accessToken, $email)
135: {
136: return $this->contactService->getContacts($accessToken, array('email' => $email));
137: }
138:
139: /**
140: * Add a new contact to an account
141: * @param string $accessToken - Valid access token
142: * @param Contact $contact - Contact to add
143: * @param boolean $actionByVisitor - is the action being taken by the visitor
144: * @return Contact
145: */
146: public function addContact($accessToken, Contact $contact, $actionByVisitor = false)
147: {
148: return $this->contactService->addContact($accessToken, $contact, $actionByVisitor);
149: }
150:
151: /**
152: * Sets an individual contact to 'REMOVED' status
153: * @param string $accessToken - Valid access token
154: * @param mixed $contact - Either a Contact id or the Contact itself
155: * @throws IllegalArgumentException - if an int or Contact object is not provided
156: * @return boolean
157: */
158: public function deleteContact($accessToken, $contact)
159: {
160: $contactId = $this->getArgumentId($contact, 'Contact');
161: return $this->contactService->deleteContact($accessToken, $contactId);
162: }
163:
164: /**
165: * Delete a contact from all contact lists
166: * @param string $accessToken - Constant Contact OAuth2 access token
167: * @param mixed $contact - Contact id or the Contact object itself
168: * @throws IllegalArgumentException - if an int or Contact object is not provided
169: * @return boolean
170: */
171: public function deleteContactFromLists($accessToken, $contact)
172: {
173: $contactId = $this->getArgumentId($contact, 'Contact');
174: return $this->contactService->deleteContactFromLists($accessToken, $contactId);
175: }
176:
177: /**
178: * Delete a contact from all contact lists
179: * @param string $accessToken - Constant Contact OAuth2 access token
180: * @param mixed $contact - Contact id or a Contact object
181: * @param mixed $list - ContactList id or a ContactList object
182: * @throws IllegalArgumentException - if an int or Contact object is not provided,
183: * as well as an int or ContactList object
184: * @return boolean
185: */
186: public function deleteContactFromList($accessToken, $contact, $list)
187: {
188: $contactId = $this->getArgumentId($contact, 'Contact');
189: $listId = $this->getArgumentId($list, 'ContactList');
190:
191: return $this->contactService->deleteContactFromList($accessToken, $contactId, $listId);
192: }
193:
194: /**
195: * Update an individual contact
196: * @param string $accessToken - Valid access token
197: * @param Contact $contact - Contact to update
198: * @param boolean $actionByVisitor - is the action being taken by the visitor, default is false
199: * @return Contact
200: */
201: public function updateContact($accessToken, Contact $contact, $actionByVisitor = false)
202: {
203: return $this->contactService->updateContact($accessToken, $contact, $actionByVisitor);
204: }
205:
206: /**
207: * Get lists
208: * @param string $accessToken - Valid access token
209: * @return array
210: */
211: public function getLists($accessToken)
212: {
213: return $this->listService->getLists($accessToken);
214: }
215:
216: /**
217: * Get an individual list
218: * @param string $accessToken - Valid access token
219: * @param int $listId - Id of the list to retrieve
220: * @return ContactList
221: */
222: public function getList($accessToken, $listId)
223: {
224: return $this->listService->getList($accessToken, $listId);
225: }
226:
227: /**
228: * Add a new contact list to an account
229: * @param string $accessToken - Valid access token
230: * @param ContactList $list - List to add
231: * @return ContactList
232: */
233: public function addList($accessToken, ContactList $list)
234: {
235: return $this->listService->addList($accessToken, $list);
236: }
237:
238: /**
239: * Update a contact list
240: * @param string $accessToken - Valid access token
241: * @param ContactList $list - ContactList to update
242: * @return ContactList
243: */
244: public function updateList($accessToken, ContactList $list)
245: {
246: return $this->listService->updateList($accessToken, $list);
247: }
248:
249: /**
250: * Get contact that belong to a specific list
251: * @param string $accessToken - Constant Contact OAuth2 access token
252: * @param mixed $list - Id of the list or a ContactList object
253: * @param mixed $param - denotes the number of results per set, limited to 50, or a next parameter provided
254: * from a previous getContactsFromList call
255: * @return array
256: * @throws IllegalArgumentException - if a ContactList object or id is not passed
257: */
258: public function getContactsFromList($accessToken, $list, $param = null)
259: {
260: $listId = $this->getArgumentId($list, 'ContactList');
261: $param = $this->determineParam($param);
262: return $this->listService->getContactsFromList($accessToken, $listId, $param);
263: }
264:
265: /**
266: * Get a set of campaigns
267: * @param string $accessToken - Constant Contact OAuth2 access token
268: * @param mixed $param - denotes the number of results per set, limited to 50, or a next parameter provided
269: * from a previous getCampaigns call
270: * @return ResultSet
271: */
272: public function getEmailCampaigns($accessToken, $param = null)
273: {
274: $param = $this->determineParam($param);
275: return $this->EmailMarketingService->getCampaigns($accessToken, $param);
276: }
277:
278: /**
279: * Get an individual campaign
280: * @param string $accessToken - Constant Contact OAuth2 access token
281: * @param int $campaignId - Valid campaign id
282: */
283: public function getEmailCampaign($accessToken, $campaignId)
284: {
285: return $this->EmailMarketingService->getCampaign($accessToken, $campaignId);
286: }
287:
288: /**
289: * Delete an individual campaign
290: * @param string $accessToken - Constant Contact OAuth2 access token
291: * @param mixed $campaign - Id of a campaign or a Campaign object itself
292: * @throws IllegalArgumentException - if a Campaign object or campaign id is not passed
293: * @return boolean
294: */
295: public function deleteEmailCampaign($accessToken, $campaign)
296: {
297: $campaignId = $this->getArgumentId($campaign, 'Campaign');
298: return $this->EmailMarketingService->deleteCampaign($accessToken, $campaignId);
299: }
300:
301: /**
302: * Create a new campaign
303: * @param string $accessToken - Constant Contact OAuth2 access token
304: * @param Campaign $campaign - Campaign to be created
305: * @return Campaign - created campaign
306: */
307: public function addEmailCampaign($accessToken, Campaign $campaign)
308: {
309: return $this->EmailMarketingService->addCampaign($accessToken, $campaign);
310: }
311:
312: /**
313: * Update a specific campaign
314: * @param string $accessToken - Constant Contact OAuth2 access token
315: * @param Campaign $campaign - Campaign to be updated
316: * @return Campaign - updated campaign
317: */
318: public function updateEmailCampaign($accessToken, Campaign $campaign)
319: {
320: return $this->EmailMarketingService->updateCampaign($accessToken, $campaign);
321: }
322:
323: /**
324: * Schedule a campaign to be sent
325: * @param string $accessToken - Constant Contact OAuth2 access token
326: * @param mixed $campaign - Campaign to be updated
327: * @param Schedule $schedule - Schedule to be associated with the provided campaign
328: * @return Campaign - updated campaign
329: */
330: public function addEmailCampaignSchedule($accessToken, $campaign, Schedule $schedule)
331: {
332: $campaignId = $this->getArgumentId($campaign, 'Campaign');
333: return $this->campaignScheduleService->addSchedule($accessToken, $campaignId, $schedule);
334: }
335:
336: /**
337: * Get an array of schedules associated with a given campaign
338: * @param string $accessToken - Constant Contact OAuth2 access token
339: * @param mixed $campaign - Campaign id or Campaign object itself
340: * @return array
341: */
342: public function getEmailCampaignSchedules($accessToken, $campaign)
343: {
344: $campaignId = $this->getArgumentId($campaign, 'Campaign');
345: return $this->campaignScheduleService->getSchedules($accessToken, $campaignId);
346: }
347:
348: /**
349: * Get a specific schedule associated with a given campaign
350: * @param string $accessToken - Constant Contact OAuth2 access token
351: * @param mixed $campaign - Campaign id or Campaign object itself
352: * @param mixed $schedule - Schedule id or Schedule object itself
353: * @throws IllegalArgumentException
354: * @return array
355: */
356: public function getEmailCampaignSchedule($accessToken, $campaign, $schedule)
357: {
358: $campaignId = $this->getArgumentId($campaign, 'Campaign');
359:
360: $schedule_id = null;
361:
362: if ($schedule instanceof Schedule) {
363: $schedule_id = $schedule->schedule_id;
364: } elseif (is_numeric($schedule)) {
365: $schedule_id = $schedule;
366: } else {
367: throw new IllegalArgumentException(sprintf(Config::get('errors.id_or_object'), 'Schedule'));
368: }
369:
370: return $this->campaignScheduleService->getSchedule($accessToken, $campaignId, $schedule_id);
371: }
372:
373: /**
374: * Update a specific schedule associated with a given campaign
375: * @param string $accessToken - Constant Contact OAuth2 access token
376: * @param mixed $campaign - Campaign id or Campaign object itself
377: * @param Schedule $schedule - Schedule to be updated
378: * @return array
379: */
380: public function updateEmailCampaignSchedule($accessToken, $campaign, Schedule $schedule)
381: {
382: $campaignId = $this->getArgumentId($campaign, 'EmailCampaign');
383:
384: return $this->campaignScheduleService->updateSchedule($accessToken, $campaignId, $schedule);
385: }
386:
387: /**
388: * Delete a specific schedule associated with a given campaign
389: * @param string $accessToken - Constant Contact OAuth2 access token
390: * @param mixed $campaign - Campaign id or Campaign object itself
391: * @param mixed $schedule - Schedule id or Schedule object itself
392: * @throws IllegalArgumentException
393: * @return array
394: */
395: public function deleteEmailCampaignSchedule($accessToken, $campaign, $schedule)
396: {
397: $campaignId = $this->getArgumentId($campaign, 'Campaign');
398: $schedule_id = null;
399:
400: if ($schedule instanceof Schedule) {
401: $schedule_id = $schedule->schedule_id;
402: } elseif (is_numeric($schedule)) {
403: $schedule_id = $schedule;
404: } else {
405: throw new IllegalArgumentException(sprintf(Config::get('errors.id_or_object'), 'Schedule'));
406: }
407:
408: return $this->campaignScheduleService->deleteSchedule($accessToken, $campaignId, $schedule_id);
409: }
410:
411: /**
412: * Send a test send of a campaign
413: * @param string $accessToken - Constant Contact OAuth2 access token
414: * @param mixed $emailCampaign - Campaign id or Campaign object itself
415: * @param TestSend $test_send - test send details
416: * @return TestSend
417: */
418: public function sendEmailCampaignTest($accessToken, $campaign, TestSend $test_send)
419: {
420: $campaignId = $this->getArgumentId($campaign, 'Campaign');
421: return $this->campaignScheduleService->sendTest($accessToken, $campaignId, $test_send);
422: }
423:
424: /**
425: * Get sends for a campaign
426: * @param string $accessToken - Constant Contact OAuth2 access token
427: * @param mixed $emailCampaign - Campaign id or Campaign object itself
428: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
429: * an initial request
430: * @return TrackingActivity - Containing a results array of {@link Ctct\Components\CampaignTracking\SendActivity}
431: */
432: public function getEmailCampaignSends($accessToken, $campaign, $param = null)
433: {
434: $campaignId = $this->getArgumentId($campaign, 'Campaign');
435: $param = $this->determineParam($param);
436: return $this->campaignTrackingService->getSends($accessToken, $campaignId, $param);
437: }
438:
439: /**
440: * Get bounces for a campaign
441: * @param string $accessToken - Constant Contact OAuth2 access token
442: * @param mixed $emailCampaign - Campaign id or Campaign object itself
443: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
444: * an initial request
445: * @return ResultSet - Containing a results array of {@link Ctct\Components\CampaignTracking\BounceActivity}
446: */
447: public function getEmailCampaignBounces($accessToken, $campaign, $param = null)
448: {
449: $campaignId = $this->getArgumentId($campaign, 'Campaign');
450: $param = $this->determineParam($param);
451: return $this->campaignTrackingService->getBounces($accessToken, $campaignId, $param);
452: }
453:
454: /**
455: * Get clicks for a campaign
456: * @param string $accessToken - Constant Contact OAuth2 access token
457: * @param mixed $emailCampaign - Campaign id or Campaign object itself
458: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
459: * an initial request
460: * @return ResultSet - Containing a results array of {@link Ctct\Components\CampaignTracking\ClickActivity}
461: */
462: public function getEmailCampaignClicks($accessToken, $campaign, $param = null)
463: {
464: $campaignId = $this->getArgumentId($campaign, 'Campaign');
465: $param = $this->determineParam($param);
466: return $this->campaignTrackingService->getClicks($accessToken, $campaignId, $param);
467: }
468:
469: /**
470: * Get opens for a campaign
471: * @param string $accessToken - Constant Contact OAuth2 access token
472: * @param mixed $emailCampaign - Campaign id or Campaign object itself
473: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
474: * an initial request
475: * @return ResultSet - Containing a results array of {@link Ctct\Components\CampaignTracking\OpenActivity}
476: */
477: public function getEmailCampaignOpens($accessToken, $campaign, $param = null)
478: {
479: $campaignId = $this->getArgumentId($campaign, 'Campaign');
480: $param = $this->determineParam($param);
481: return $this->campaignTrackingService->getOpens($accessToken, $campaignId, $param);
482: }
483:
484: /**
485: * Get forwards for a campaign
486: * @param string $accessToken - Constant Contact OAuth2 access token
487: * @param mixed $emailCampaign - Campaign id or Campaign object itself
488: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
489: * an initial request
490: * @return ResultSet - Containing a results array of {@link Ctct\Components\CampaignTracking\ForwardActivity}
491: */
492: public function getEmailCampaignForwards($accessToken, $campaign, $param = null)
493: {
494: $campaignId = $this->getArgumentId($campaign, 'Campaign');
495: $param = $this->determineParam($param);
496: return $this->campaignTrackingService->getForwards($accessToken, $campaignId, $param);
497: }
498:
499: /**
500: * Get unsubscribes for a campaign
501: * @param string $accessToken - Constant Contact OAuth2 access token
502: * @param mixed $emailCampaign - Campaign id or Campaign object itself
503: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
504: * an initial request
505: * @return ResultSet - Containing a results array of {@link Ctct\Components\CampaignTracking\OptOutActivity}
506: */
507: public function getEmailCampaignUnsubscribes($accessToken, $campaign, $param = null)
508: {
509: $campaignId = $this->getArgumentId($campaign, 'Campaign');
510: $param = $this->determineParam($param);
511: return $this->campaignTrackingService->getUnsubscribes($accessToken, $campaignId, $param);
512: }
513:
514: /**
515: * Get a reporting summary for a campaign
516: * @param string $accessToken - Constant Contact OAuth2 access token
517: * @param mixed $emailCampaign - Campaign id or Campaign object itself
518: * @param string $next - next value returned from a previous request (used in pagination)
519: * @param int $limit - number of results to return per page
520: * @return TrackingSummary
521: */
522: public function getEmailCampaignSummaryReport($accessToken, $campaign)
523: {
524: $campaignId = $this->getArgumentId($campaign, 'Campaign');
525: return $this->campaignTrackingService->getSummary($accessToken, $campaignId);
526: }
527:
528: /**
529: * Get sends for a Contact
530: * @param string $accessToken - Constant Contact OAuth2 access token
531: * @param mixed $contact - Contact id or Contact object itself
532: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
533: * an initial request
534: * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\SendActivity}
535: */
536: public function getContactSends($accessToken, $contact, $param = null)
537: {
538: $contactId = $this->getArgumentId($contact, 'Contact');
539: $param = $this->determineParam($param);
540: return $this->contactTrackingService->getSends($accessToken, $contactId, $param);
541: }
542:
543: /**
544: * Get bounces for a Contact
545: * @param string $accessToken - Constant Contact OAuth2 access token
546: * @param mixed $contact - Contact id or Contact object itself
547: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
548: * an initial request
549: * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\BounceActivity}
550: */
551: public function getContactBounces($accessToken, $contact, $param = null)
552: {
553: $contactId = $this->getArgumentId($contact, 'Contact');
554: $param = $this->determineParam($param);
555: return $this->contactTrackingService->getBounces($accessToken, $contactId, $param);
556: }
557:
558: /**
559: * Get clicks for a Contact
560: * @param string $accessToken - Constant Contact OAuth2 access token
561: * @param mixed $contact - Contact id or Contact object itself
562: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
563: * an initial request
564: * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\ClickActivity}
565: */
566: public function getContactClicks($accessToken, $contact, $param = null)
567: {
568: $contactId = $this->getArgumentId($contact, 'Contact');
569: $param = $this->determineParam($param);
570: return $this->contactTrackingService->getClicks($accessToken, $contactId, $param);
571: }
572:
573: /**
574: * Get opens for a Contact
575: * @param string $accessToken - Constant Contact OAuth2 access token
576: * @param mixed $contact - Contact id or Contact object itself
577: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
578: * an initial request
579: * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\OpenActivity}
580: */
581: public function getContactOpens($accessToken, $contact, $param = null)
582: {
583: $contactId = $this->getArgumentId($contact, 'Contact');
584: $param = $this->determineParam($param);
585: return $this->contactTrackingService->getOpens($accessToken, $contactId, $param);
586: }
587:
588: /**
589: * Get forwards for a Contact
590: * @param string $accessToken - Constant Contact OAuth2 access token
591: * @param mixed $contact - Contact id or Contact object itself
592: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
593: * an initial request
594: * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\ForwardActivity}
595: */
596: public function getContactForwards($accessToken, $contact, $param = null)
597: {
598: $contactId = $this->getArgumentId($contact, 'Contact');
599: $param = $this->determineParam($param);
600: return $this->contactTrackingService->getForwards($accessToken, $contactId, $param);
601: }
602:
603: /**
604: * Get opt outs for a Contact
605: * @param string $accessToken - Constant Contact OAuth2 access token
606: * @param mixed $contact - Contact id or Contact object itself
607: * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of
608: * an initial request
609: * @return TrackingActivity - Containing a results array of {@link Ctct\Components\Tracking\OptOutActivity}
610: */
611: public function getContactUnsubscribes($accessToken, $contact, $param = null)
612: {
613: $contactId = $this->getArgumentId($contact, 'Contact');
614: $param = $this->determineParam($param);
615: return $this->contactTrackingService->getUnsubscribes($accessToken, $contactId, $param);
616: }
617:
618: /**
619: * Get verified addresses for the account
620: * @param string $accessToken - Constant Contact OAuth2 access token
621: * @return array of VerifiedEmailAddress objects
622: */
623: public function getVerifiedEmailAddresses($accessToken)
624: {
625: return $this->accountService->getVerifiedEmailAddresses($accessToken);
626: }
627:
628: /**
629: * Get a reporting summary for a Contact
630: * @param string $accessToken - Constant Contact OAuth2 access token
631: * @param mixed $contact - Contact id or Contact object itself
632: * @param string $next - next value returned from a previous request (used in pagination)
633: * @param int $limit - number of results to return per page
634: * @return TrackingSummary
635: */
636: public function getContactSummaryReport($accessToken, $contact)
637: {
638: $contactId = $this->getArgumentId($contact, 'Contact');
639: return $this->contactTrackingService->getSummary($accessToken, $contactId);
640: }
641:
642: /**
643: * Get an array of activities
644: * @param string $accessToken - Constant Contact OAuth2 access token
645: * @return array
646: */
647: public function getActivities($accessToken)
648: {
649: return $this->activityService->getActivities($accessToken);
650: }
651:
652: /**
653: * Get a single activity by id
654: * @param string $accessToken - Constant Contact OAuth2 access token
655: * @param string $activityId - Activity id
656: * @return array
657: */
658: public function getActivity($accessToken, $activityId)
659: {
660: return $this->activityService->getActivity($accessToken, $activityId);
661: }
662:
663: /**
664: * Add an AddContacts Activity to add contacts in bulk
665: * @param string $accessToken - Constant Contact OAuth2 access token
666: * @param AddContacts - Add Contacts Activity
667: */
668: public function addCreateContactsActivity($accessToken, AddContacts $addContactsActivity)
669: {
670: return $this->activityService->createAddContactsActivity($accessToken, $addContactsActivity);
671: }
672:
673: /**
674: * Add an ClearLists Activity to remove all contacts from the provided lists
675: * @param string $accessToken - Constant Contact OAuth2 access token
676: * @param AddContacts - Add Contacts Activity
677: */
678: public function addClearListsActivity($accessToken, Array $lists)
679: {
680: return $this->activityService->addClearListsActivity($accessToken, $lists);
681: }
682:
683: /**
684: * Add a Remove Contacts From Lists Activity
685: * @param string $accessToken - Constant Contact OAuth2 access token
686: * @param array $emailAddresses - email addresses to be removed
687: * @param array $lists - lists to remove the provided email addresses from
688: * @param AddContacts - Add Contacts Activity
689: */
690: public function addRemoveContactsFromListsActivity($accessToken, Array $emailAddresses, Array $lists)
691: {
692: return $this->activityService->addRemoveContactsFromListsActivity($accessToken, $emailAddresses, $lists);
693: }
694:
695: /**
696: * Create an Export Contacts Activity
697: * @param string $accessToken - Constant Contact OAuth2 access token
698: * @param ExportContacts $exportContacts
699: * @return array - Array of all ActivitySummaryReports
700: */
701: public function addExportContactsActivity($accessToken, ExportContacts $exportContacts)
702: {
703: return $this->activityService->addExportContactsActivity($accessToken, $exportContacts);
704: }
705:
706: /**
707: * Get the id of object, or attempt to convert the argument to an int
708: * @param mixed $item - object or a numeric value
709: * @param string $class_name - class name to test the given object against
710: * @throws IllegalArgumentException - if the item is not an instance of the class name given, or cannot be
711: * converted to a numeric value
712: * @return int
713: */
714: private function getArgumentId($item, $class_name)
715: {
716: $id = null;
717:
718: if (is_numeric($item)) {
719: $id = $item;
720: } elseif (join('', array_slice(explode('\\', get_class($item)), -1)) == $class_name) {
721: $id = $item->id;
722: } else {
723: throw new IllegalArgumentException(sprintf(Config::get('errors.id_or_object'), $class_name));
724: }
725:
726: return $id;
727: }
728:
729: /**
730: * Builds an array of query parameters to be added to the request
731: * @param string $param
732: * @return array
733: */
734: private function determineParam($param)
735: {
736: $params = array();
737: if (substr($param, 0, 1) === '?') {
738: $param = substr($param, 1);
739: parse_str($param, $params);
740: } else {
741: $params['limit'] = $param;
742: }
743: return $params;
744: }
745: }
746: