/** * Update information of the account. * @param string $accessToken - Constant Contact OAuth2 Access Token * @param AccountInfo $accountInfo - Updated AccountInfo * @return AccountInfo */ public function updateAccountInfo($accessToken, AccountInfo $accountInfo) { $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.account_info'); $url = $this->buildUrl($baseUrl); $response = parent::getRestClient()->put($url, parent::getHeaders($accessToken), $accountInfo->toJson()); return AccountInfo::create(json_decode($response->body, true)); }
/** * Update a specific email campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param Campaign $campaign - Campaign to be updated * @return Campaign */ public function updateCampaign($accessToken, Campaign $campaign) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign'), $campaign->id); $url = $this->buildUrl($baseUrl); $response = parent::getRestClient()->put($url, parent::getHeaders($accessToken), $campaign->toJson()); return Campaign::create(json_decode($response->body, true)); }
/** * Get account info associated with an access token * @param string $accessToken - Constant Contact OAuth2 Access Token * @param array $params - array of query parameters/values to append to the request * @return AccountInfo */ public function getAccountInfo($accessToken, array $params) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.account_info')); $url = $this->buildUrl($baseUrl, $params); $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken)); return AccountInfo::create(json_decode($response->body, true)); }
/** * Get all verified email addresses associated with an account * @param string $accessToken - Constant Contact OAuth2 Access Token * @param array $params - array of query parameters/values to append to the request * @return array of VerifiedEmailAddress */ public function getVerifiedEmailAddresses($accessToken, array $params) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.account_verified_addresses')); $url = $this->buildUrl($baseUrl, $params); $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken)); $verifiedAddresses = array(); foreach (json_decode($response->body, true) as $verifiedAddress) { $verifiedAddresses[] = VerifiedEmailAddress::create($verifiedAddress); } return $verifiedAddresses; }
/** * Get folders from the Library * @param string $accessToken - Constant Contact OAuth2 Access Token * @param array $params - array of query parameters/values to append to the request * @return ResultSet */ public function getLibraryFolders($accessToken, array $params) { $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.library_folders'); $url = $this->buildUrl($baseUrl, $params); $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken)); $body = json_decode($response->body, true); $libraryFolders = array(); foreach ($body['results'] as $folder) { $libraryFolders[] = Folder::create($folder); } return new ResultSet($libraryFolders, $body['meta']); }
/** * Get all contacts from an individual list * @param string $accessToken - Constant Contact OAuth2 access token * @param string $list_id - list id to retrieve contacts for * @param array $params - query params to attach to request * @return ResultSet */ public function getContactsFromList($accessToken, $list_id, $params = null) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list_contacts'), $list_id); $url = $this->buildUrl($baseUrl, $params); $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken)); $body = json_decode($response->body, true); $contacts = array(); foreach ($body['results'] as $contact) { $contacts[] = Contact::create($contact); } return new ResultSet($contacts, $body['meta']); }
/** * Create an Remove Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx * @param string $accessToken - Constant Contact OAuth2 access token * @param string $fileName - The name of the file (ie: contacts.csv) * @param string $contents - The contents of the file * @param string $lists - Comma separated list of ContactList id' to add the contacts too * @return \Ctct\Components\Activities\Activity */ public function addRemoveContactsFromListsActivityFromFile($accessToken, $fileName, $contents, $lists) { $eol = "\r\n"; $data = ''; $boundary = md5(time()); $data .= '--' . $boundary . $eol; $data .= 'Content-Disposition: form-data; name="file_name"' . $eol; $data .= 'Content-Type: text/plain' . $eol . $eol; $data .= $fileName . $eol; $data .= '--' . $boundary . $eol; $data .= 'Content-Disposition: form-data; name="lists"' . $eol; $data .= 'Content-Type: text/plain' . $eol . $eol; $data .= $lists . $eol; $data .= '--' . $boundary . $eol; $data .= 'Content-Disposition: form-data; name="data"' . $eol . $eol; $data .= $contents . $eol; $data .= "--" . $boundary . "--" . $eol; $headers = array("Authorization: Bearer {$accessToken}", "Content-Type: multipart/form-data; boundary={$boundary}"); $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.remove_from_lists_activity'); $url = $this->buildUrl($baseUrl); $response = parent::getRestClient()->post($url, $headers, $data); return Activity::create(json_decode($response->body, true)); }
/** * Get a summary of reporting data for a given campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param int $campaign_id - Campaign id * @return TrackingSummary */ public function getSummary($accessToken, $campaign_id) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_tracking_summary'), $campaign_id); $url = $this->buildUrl($baseUrl); $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken)); return TrackingSummary::create(json_decode($response->body, true)); }
/** * Update contact details for a specific contact * @param string $accessToken - Constant Contact OAuth2 access token * @param Contact $contact - Contact to be updated * @param boolean $actionByVisitor - is the action being taken by the visitor * @return Contact */ public function updateContact($accessToken, Contact $contact, $actionByVisitor = false) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact'), $contact->id); $params = array(); if ($actionByVisitor == true) { $params['action_by'] = "ACTION_BY_VISITOR"; } $url = $this->buildUrl($baseUrl, $params); $response = parent::getRestClient()->put($url, parent::getHeaders($accessToken), $contact->toJson()); return Contact::create(json_decode($response->body, true)); }
/** * Update contact details for a specific contact * @param string $accessToken - Constant Contact OAuth2 access token * @param Contact $contact - Contact to be updated * @param array $params - query params to be appended to the request * @return Contact */ public function updateContact($accessToken, Contact $contact, array $params = array()) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact'), $contact->id); $url = $this->buildUrl($baseUrl, $params); $response = parent::getRestClient()->put($url, parent::getHeaders($accessToken), $contact->toJson()); return Contact::create(json_decode($response->body, true)); }
/** * Send a test send of a campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param int $campaignId - Id of campaign to send test of * @param TestSend $test_send - Test send details * @return TestSend */ public function sendTest($accessToken, $campaignId, TestSend $test_send) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_test_sends'), $campaignId); $url = $this->buildUrl($baseUrl); $response = parent::getRestClient()->post($url, parent::getHeaders($accessToken), $test_send->toJson()); return TestSend::create(json_decode($response->body, true)); }