Source of file ConstantContact.php
Size: 29,551 Bytes - Last Modified: 2021-12-23T10:20:09+00:00
/var/www/docs.ssmods.com/process/src/src/Ctct/ConstantContact.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756 | <?php namespace Ctct; use Ctct\Services\BaseService; use Ctct\Services\AccountService; use Ctct\Services\ContactService; use Ctct\Services\ListService; use Ctct\Services\EmailMarketingService; use Ctct\Services\CampaignScheduleService; use Ctct\Services\CampaignTrackingService; use Ctct\Services\ContactTrackingService; use Ctct\Services\ActivityService; use Ctct\Components\Account\VerifiedEmailAddress; use Ctct\Components\Contacts\Contact; use Ctct\Components\Contacts\ContactList; use Ctct\Components\EmailMarketing\Campaign; use Ctct\Components\EmailMarketing\Schedule; use Ctct\Components\EmailMarketing\TestSend; use Ctct\Components\ResultSet; use Ctct\Components\Tracking\TrackingSummary; use Ctct\Components\Tracking\TrackingActivity; use Ctct\Components\Activities\AddContacts; use Ctct\Components\Activities\ExportContacts; use Ctct\Exceptions\CtctException; use Ctct\Exceptions\IllegalArgumentException; use Ctct\Util\Config; /** * Exposes all implemented Constant Contact API functionality * @package Ctct * @version 1.0.0 * @author Constant Contact */ class ConstantContact { /** * Constant Contact API Key * @var string */ private $apiKey; /** * ContactService * @var ContactService */ private $contactService; /** * CampaignService * @var CampaignService */ private $emailMarketingService; /** * ListService * @var ListService */ private $listService; /** * ActivityService * @var ActivityService */ private $activityService; /** * CampaignTrackingService * @var CampaignTrackingService */ private $campaignTrackingService; /** * ContactTrackingService * @var ContactTrackingService */ private $contactTrackingService; /** * CampaignScheduleService * @var CampaignScheduleService */ private $campaignScheduleService; /** * AccountService * @var AccountService */ private $accountService; /** * Class constructor * @param string $apiKey - Constant Contact API Key */ public function __construct($apiKey) { $this->api_key = $apiKey; $this->contactService = new ContactService($apiKey); $this->emailMarketingService = new EmailMarketingService($apiKey); $this->activityService = new ActivityService($apiKey); $this->campaignTrackingService = new CampaignTrackingService($apiKey); $this->contactTrackingService = new ContactTrackingService($apiKey); $this->campaignScheduleService = new CampaignScheduleService($apiKey); $this->listService = new ListService($apiKey); $this->accountService = new AccountService($apiKey); } /** * Get a set of campaigns * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $param - denotes the number of results per set, limited to 50, or a next parameter provided * from a previous getContacts call * @return ResultSet */ public function getContacts($accessToken, $param = null) { $param = $this->determineParam($param); return $this->contactService->getContacts($accessToken, $param); } /** * Get an individual contact * @param string $accessToken - Valid access token * @param int $contactId - Id of the contact to retrieve * @return Contact */ public function getContact($accessToken, $contactId) { return $this->contactService->getContact($accessToken, $contactId); } /** * Get contacts with a specified email eaddress * @param string $accessToken - Constant Contact OAuth2 access token * @param string $email - contact email address to search for * @return ResultSet */ public function getContactByEmail($accessToken, $email) { return $this->contactService->getContacts($accessToken, array('email' => $email)); } /** * Add a new contact to an account * @param string $accessToken - Valid access token * @param Contact $contact - Contact to add * @param boolean $actionByVisitor - is the action being taken by the visitor * @return Contact */ public function addContact($accessToken, Contact $contact, $actionByVisitor = false) { return $this->contactService->addContact($accessToken, $contact, $actionByVisitor); } /** * Sets an individual contact to 'REMOVED' status * @param string $accessToken - Valid access token * @param mixed $contact - Either a Contact id or the Contact itself * @throws IllegalArgumentException - if an int or Contact object is not provided * @return boolean */ public function deleteContact($accessToken, $contact) { $contactId = $this->getArgumentId($contact, 'Contact'); return $this->contactService->deleteContact($accessToken, $contactId); } /** * Delete a contact from all contact lists * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $contact - Contact id or the Contact object itself * @throws IllegalArgumentException - if an int or Contact object is not provided * @return boolean */ public function deleteContactFromLists($accessToken, $contact) { $contactId = $this->getArgumentId($contact, 'Contact'); return $this->contactService->deleteContactFromLists($accessToken, $contactId); } /** * Delete a contact from all contact lists * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $contact - Contact id or a Contact object * @param mixed $list - ContactList id or a ContactList object * @throws IllegalArgumentException - if an int or Contact object is not provided, * as well as an int or ContactList object * @return boolean */ public function deleteContactFromList($accessToken, $contact, $list) { $contactId = $this->getArgumentId($contact, 'Contact'); $listId = $this->getArgumentId($list, 'ContactList'); return $this->contactService->deleteContactFromList($accessToken, $contactId, $listId); } /** * Update an individual contact * @param string $accessToken - Valid access token * @param Contact $contact - Contact to update * @param boolean $actionByVisitor - is the action being taken by the visitor, default is false * @return Contact */ public function updateContact($accessToken, Contact $contact, $actionByVisitor = false) { return $this->contactService->updateContact($accessToken, $contact, $actionByVisitor); } /** * Get lists * @param string $accessToken - Valid access token * @return array */ public function getLists($accessToken) { return $this->listService->getLists($accessToken); } /** * Get an individual list * @param string $accessToken - Valid access token * @param int $listId - Id of the list to retrieve * @return ContactList */ public function getList($accessToken, $listId) { return $this->listService->getList($accessToken, $listId); } /** * Add a new contact list to an account * @param string $accessToken - Valid access token * @param ContactList $list - List to add * @return ContactList */ public function addList($accessToken, ContactList $list) { return $this->listService->addList($accessToken, $list); } /** * Update a contact list * @param string $accessToken - Valid access token * @param ContactList $list - ContactList to update * @return ContactList */ public function updateList($accessToken, ContactList $list) { return $this->listService->updateList($accessToken, $list); } /** * Get contact that belong to a specific list * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $list - Id of the list or a ContactList object * @param mixed $param - denotes the number of results per set, limited to 50, or a next parameter provided * from a previous getContactsFromList call * @return ResultSet * @throws IllegalArgumentException - if a ContactList object or id is not passed */ public function getContactsFromList($accessToken, $list, $param = null) { $listId = $this->getArgumentId($list, 'ContactList'); $param = $this->determineParam($param); return $this->listService->getContactsFromList($accessToken, $listId, $param); } /** * Get a set of campaigns * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $param - denotes the number of results per set, limited to 50, or a next parameter provided * from a previous getCampaigns call * @return ResultSet */ public function getEmailCampaigns($accessToken, $status = null, $param = null) { $params = $this->determineParam($param); if ($status) { $params['status'] = $status; } return $this->emailMarketingService->getCampaigns($accessToken, $params); } /** * Get an individual campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param int $campaignId - Valid campaign id */ public function getEmailCampaign($accessToken, $campaignId) { return $this->emailMarketingService->getCampaign($accessToken, $campaignId); } /** * Delete an individual campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $campaign - Id of a campaign or a Campaign object itself * @throws IllegalArgumentException - if a Campaign object or campaign id is not passed * @return boolean */ public function deleteEmailCampaign($accessToken, $campaign) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); return $this->emailMarketingService->deleteCampaign($accessToken, $campaignId); } /** * Create a new campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param Campaign $campaign - Campaign to be created * @return Campaign - created campaign */ public function addEmailCampaign($accessToken, Campaign $campaign) { return $this->emailMarketingService->addCampaign($accessToken, $campaign); } /** * Update a specific campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param Campaign $campaign - Campaign to be updated * @return Campaign - updated campaign */ public function updateEmailCampaign($accessToken, Campaign $campaign) { return $this->emailMarketingService->updateCampaign($accessToken, $campaign); } /** * Schedule a campaign to be sent * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $campaign - Campaign to be updated * @param Schedule $schedule - Schedule to be associated with the provided campaign * @return Campaign - updated campaign */ public function addEmailCampaignSchedule($accessToken, $campaign, Schedule $schedule) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); return $this->campaignScheduleService->addSchedule($accessToken, $campaignId, $schedule); } /** * Get an array of schedules associated with a given campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $campaign - Campaign id or Campaign object itself * @return array */ public function getEmailCampaignSchedules($accessToken, $campaign) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); return $this->campaignScheduleService->getSchedules($accessToken, $campaignId); } /** * Get a specific schedule associated with a given campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $campaign - Campaign id or Campaign object itself * @param mixed $schedule - Schedule id or Schedule object itself * @throws IllegalArgumentException * @return Schedule */ public function getEmailCampaignSchedule($accessToken, $campaign, $schedule) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); $scheduleId = null; if ($schedule instanceof Schedule) { $scheduleId = $schedule->id; } elseif (is_numeric($schedule)) { $scheduleId = $schedule; } else { throw new IllegalArgumentException(sprintf(Config::get('errors.id_or_object'), 'Schedule')); } return $this->campaignScheduleService->getSchedule($accessToken, $campaignId, $scheduleId); } /** * Update a specific schedule associated with a given campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $campaign - Campaign id or Campaign object itself * @param Schedule $schedule - Schedule to be updated * @return Schedule */ public function updateEmailCampaignSchedule($accessToken, $campaign, Schedule $schedule) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); return $this->campaignScheduleService->updateSchedule($accessToken, $campaignId, $schedule); } /** * Delete a specific schedule associated with a given campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $campaign - Campaign id or Campaign object itself * @param mixed $schedule - Schedule id or Schedule object itself * @throws IllegalArgumentException * @return boolean */ public function deleteEmailCampaignSchedule($accessToken, $campaign, $schedule) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); $scheduleId = null; if ($schedule instanceof Schedule) { $scheduleId = $schedule->id; } elseif (is_numeric($schedule)) { $scheduleId = $schedule; } else { throw new IllegalArgumentException(sprintf(Config::get('errors.id_or_object'), 'Schedule')); } return $this->campaignScheduleService->deleteSchedule($accessToken, $campaignId, $scheduleId); } /** * Send a test send of a campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $emailCampaign - Campaign id or Campaign object itself * @param TestSend $test_send - test send details * @return TestSend */ public function sendEmailCampaignTest($accessToken, $campaign, TestSend $test_send) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); return $this->campaignScheduleService->sendTest($accessToken, $campaignId, $test_send); } /** * Get sends for a campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $emailCampaign - Campaign id or Campaign object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return TrackingActivity - Containing a results array of {@link Ctct\Components\CampaignTracking\SendActivity} */ public function getEmailCampaignSends($accessToken, $campaign, $param = null) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); $param = $this->determineParam($param); return $this->campaignTrackingService->getSends($accessToken, $campaignId, $param); } /** * Get bounces for a campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $emailCampaign - Campaign id or Campaign object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return ResultSet - Containing a results array of {@link Ctct\Components\CampaignTracking\BounceActivity} */ public function getEmailCampaignBounces($accessToken, $campaign, $param = null) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); $param = $this->determineParam($param); return $this->campaignTrackingService->getBounces($accessToken, $campaignId, $param); } /** * Get clicks for a campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $emailCampaign - Campaign id or Campaign object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return ResultSet - Containing a results array of {@link Ctct\Components\CampaignTracking\ClickActivity} */ public function getEmailCampaignClicks($accessToken, $campaign, $param = null) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); $param = $this->determineParam($param); return $this->campaignTrackingService->getClicks($accessToken, $campaignId, $param); } /** * Get opens for a campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $emailCampaign - Campaign id or Campaign object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return ResultSet - Containing a results array of {@link Ctct\Components\CampaignTracking\OpenActivity} */ public function getEmailCampaignOpens($accessToken, $campaign, $param = null) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); $param = $this->determineParam($param); return $this->campaignTrackingService->getOpens($accessToken, $campaignId, $param); } /** * Get forwards for a campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $emailCampaign - Campaign id or Campaign object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return ResultSet - Containing a results array of {@link Ctct\Components\CampaignTracking\ForwardActivity} */ public function getEmailCampaignForwards($accessToken, $campaign, $param = null) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); $param = $this->determineParam($param); return $this->campaignTrackingService->getForwards($accessToken, $campaignId, $param); } /** * Get unsubscribes for a campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $emailCampaign - Campaign id or Campaign object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return ResultSet - Containing a results array of {@link Ctct\Components\CampaignTracking\UnsubscribeActivity} */ public function getEmailCampaignUnsubscribes($accessToken, $campaign, $param = null) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); $param = $this->determineParam($param); return $this->campaignTrackingService->getUnsubscribes($accessToken, $campaignId, $param); } /** * Get a reporting summary for a campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $emailCampaign - Campaign id or Campaign object itself * @param string $next - next value returned from a previous request (used in pagination) * @param int $limit - number of results to return per page * @return TrackingSummary */ public function getEmailCampaignSummaryReport($accessToken, $campaign) { $campaignId = $this->getArgumentId($campaign, 'Campaign'); return $this->campaignTrackingService->getSummary($accessToken, $campaignId); } /** * Get sends for a Contact * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $contact - Contact id or Contact object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\SendActivity} */ public function getContactSends($accessToken, $contact, $param = null) { $contactId = $this->getArgumentId($contact, 'Contact'); $param = $this->determineParam($param); return $this->contactTrackingService->getSends($accessToken, $contactId, $param); } /** * Get bounces for a Contact * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $contact - Contact id or Contact object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\BounceActivity} */ public function getContactBounces($accessToken, $contact, $param = null) { $contactId = $this->getArgumentId($contact, 'Contact'); $param = $this->determineParam($param); return $this->contactTrackingService->getBounces($accessToken, $contactId, $param); } /** * Get clicks for a Contact * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $contact - Contact id or Contact object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\ClickActivity} */ public function getContactClicks($accessToken, $contact, $param = null) { $contactId = $this->getArgumentId($contact, 'Contact'); $param = $this->determineParam($param); return $this->contactTrackingService->getClicks($accessToken, $contactId, $param); } /** * Get opens for a Contact * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $contact - Contact id or Contact object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\OpenActivity} */ public function getContactOpens($accessToken, $contact, $param = null) { $contactId = $this->getArgumentId($contact, 'Contact'); $param = $this->determineParam($param); return $this->contactTrackingService->getOpens($accessToken, $contactId, $param); } /** * Get forwards for a Contact * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $contact - Contact id or Contact object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return ResultSet - Containing a results array of {@link Ctct\Components\Tracking\ForwardActivity} */ public function getContactForwards($accessToken, $contact, $param = null) { $contactId = $this->getArgumentId($contact, 'Contact'); $param = $this->determineParam($param); return $this->contactTrackingService->getForwards($accessToken, $contactId, $param); } /** * Get opt outs for a Contact * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $contact - Contact id or Contact object itself * @param mixed $param - either the next link from a previous request, or a limit or restrict the page size of * an initial request * @return TrackingActivity - Containing a results array of {@link Ctct\Components\Tracking\UnsubscribeActivity} */ public function getContactUnsubscribes($accessToken, $contact, $param = null) { $contactId = $this->getArgumentId($contact, 'Contact'); $param = $this->determineParam($param); return $this->contactTrackingService->getUnsubscribes($accessToken, $contactId, $param); } /** * Get verified addresses for the account * @param string $accessToken - Constant Contact OAuth2 access token * @param string $status - Status to filter query results by * @return array of VerifiedEmailAddress objects */ public function getVerifiedEmailAddresses($accessToken, $status = null) { $params = array(); if ($status) { $params['status'] = $status; } return $this->accountService->getVerifiedEmailAddresses($accessToken, $params); } /** * Get a reporting summary for a Contact * @param string $accessToken - Constant Contact OAuth2 access token * @param mixed $contact - Contact id or Contact object itself * @param string $next - next value returned from a previous request (used in pagination) * @param int $limit - number of results to return per page * @return TrackingSummary */ public function getContactSummaryReport($accessToken, $contact) { $contactId = $this->getArgumentId($contact, 'Contact'); return $this->contactTrackingService->getSummary($accessToken, $contactId); } /** * Get an array of activities * @param string $accessToken - Constant Contact OAuth2 access token * @return array */ public function getActivities($accessToken) { return $this->activityService->getActivities($accessToken); } /** * Get a single activity by id * @param string $accessToken - Constant Contact OAuth2 access token * @param string $activityId - Activity id * @return Activity */ public function getActivity($accessToken, $activityId) { return $this->activityService->getActivity($accessToken, $activityId); } /** * Add an AddContacts Activity to add contacts in bulk * @param string $accessToken - Constant Contact OAuth2 access token * @param AddContacts - Add Contacts Activity */ public function addCreateContactsActivity($accessToken, AddContacts $addContactsActivity) { return $this->activityService->createAddContactsActivity($accessToken, $addContactsActivity); } /** * Add an ClearLists Activity to remove all contacts from the provided lists * @param string $accessToken - Constant Contact OAuth2 access token * @param AddContacts - Add Contacts Activity */ public function addClearListsActivity($accessToken, Array $lists) { return $this->activityService->addClearListsActivity($accessToken, $lists); } /** * Add a Remove Contacts From Lists Activity * @param string $accessToken - Constant Contact OAuth2 access token * @param array $emailAddresses - email addresses to be removed * @param array $lists - lists to remove the provided email addresses from * @param AddContacts - Add Contacts Activity */ public function addRemoveContactsFromListsActivity($accessToken, Array $emailAddresses, Array $lists) { return $this->activityService->addRemoveContactsFromListsActivity($accessToken, $emailAddresses, $lists); } /** * Create an Export Contacts Activity * @param string $accessToken - Constant Contact OAuth2 access token * @param ExportContacts $exportContacts * @return Activity */ public function addExportContactsActivity($accessToken, ExportContacts $exportContacts) { return $this->activityService->addExportContactsActivity($accessToken, $exportContacts); } /** * Get the id of object, or attempt to convert the argument to an int * @param mixed $item - object or a numeric value * @param string $class_name - class name to test the given object against * @throws IllegalArgumentException - if the item is not an instance of the class name given, or cannot be * converted to a numeric value * @return int */ private function getArgumentId($item, $class_name) { $id = null; if (is_numeric($item)) { $id = $item; } elseif (join('', array_slice(explode('\\', get_class($item)), -1)) == $class_name) { $id = $item->id; } else { throw new IllegalArgumentException(sprintf(Config::get('errors.id_or_object'), $class_name)); } return $id; } /** * Builds an array of query parameters to be added to the request * @param string $param * @return array */ private function determineParam($param) { $params = array(); if (substr($param, 0, 1) === '?') { $param = substr($param, 1); parse_str($param, $params); } else { $params['limit'] = $param; } return $params; } } |