/** * 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 $testSend - Test send details * @return TestSend * @throws CtctException */ public function sendTest($accessToken, $campaignId, TestSend $testSend) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_test_sends'), $campaignId); $request = parent::createBaseRequest($accessToken, 'POST', $baseUrl); $stream = Stream::factory(json_encode($testSend)); $request->setBody($stream); try { $response = parent::getClient()->send($request); } catch (ClientException $e) { throw parent::convertException($e); } return TestSend::create($response->json()); }
/** * Get a preview of an email campaign * @param string $accessToken - Constant Contact OAuth2 access token * @param int $campaignId - Valid campaign id * @return CampaignPreview * @throws CtctException */ public function getPreview($accessToken, $campaignId) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_preview'), $campaignId); $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl); try { $response = parent::getClient()->send($request); } catch (ClientException $e) { throw parent::convertException($e); } return CampaignPreview::create($response->json()); }
/** * Get the status of a File upload * @param string $accessToken - Constant Contact OAuth2 token * @param string $uploadStatusIds - Single ID or ID's of statuses to check, separated by commas (no spaces) * @return FileUploadStatus[] - Array of FileUploadStatus * @throws CtctException */ public function getFileUploadStatus($accessToken, $uploadStatusIds) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.library_file_upload_status'), $uploadStatusIds); $request = parent::createBaseRequest($accessToken, "GET", $baseUrl); try { $response = parent::getClient()->send($request); } catch (ClientException $e) { throw parent::convertException($e); } $fileUploadStatuses = array(); foreach ($response->json() as $fileUploadStatus) { $fileUploadStatuses[] = FileUploadStatus::create($fileUploadStatus); } return $fileUploadStatuses; }
/** * Get an individual contact list * @param $accessToken - Constant Contact OAuth2 access token * @param $listId - list id * @return ContactList * @throws CtctException */ public function getList($accessToken, $listId) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list'), $listId); $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl); try { $response = parent::getClient()->send($request); } catch (ClientException $e) { throw parent::convertException($e); } return ContactList::create($response->json()); }
/** * Create a 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 $fileLocation - The location of the file on the server, this method uses fopen() * @param string $lists - Comma separated list of ContactList id's to add the contacts to * @return Activity * @throws CtctException */ public function addRemoveContactsFromListsActivityFromFile($accessToken, $fileName, $fileLocation, $lists) { $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.remove_from_lists_activity'); $request = parent::createBaseRequest($accessToken, "POST", $baseUrl); $request->setHeader("Content-Type", "multipart/form-data"); $body = new PostBody(); $body->setField("lists", $lists); $body->setField("file_name", $fileName); $body->addFile(new PostFile("data", fopen($fileLocation, 'r'), $fileName)); $request->setBody($body); try { $response = parent::getClient()->send($request); } catch (ClientException $e) { throw parent::convertException($e); } return Activity::create($response->json()); }
/** * 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 - associative array of query parameters and values to append to the request. * Allowed parameters include: * action_by - Whether the contact is taking the action, or the account owner. Must be one of * ACTION_BY_OWNER or ACTION_BY_VISITOR * @return Contact * @throws CtctException */ public function updateContact($accessToken, Contact $contact, array $params = array()) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact'), $contact->id); $request = parent::createBaseRequest($accessToken, 'PUT', $baseUrl); if ($params) { $query = $request->getQuery(); foreach ($params as $name => $value) { $query->add($name, $value); } } $stream = Stream::factory(json_encode($contact)); $request->setBody($stream); try { $response = parent::getClient()->send($request); } catch (ClientException $e) { throw parent::convertException($e); } return Contact::create($response->json()); }
/** * Update information of the account. * @param string $accessToken - Constant Contact OAuth2 Access Token * @param AccountInfo $accountInfo - Updated AccountInfo * @return AccountInfo * @throws CtctException */ public function updateAccountInfo($accessToken, AccountInfo $accountInfo) { $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.account_info'); $request = parent::createBaseRequest($accessToken, 'PUT', $baseUrl); $stream = Stream::factory(json_encode($accountInfo)); $request->setBody($stream); try { $response = parent::getClient()->send($request); } catch (ClientException $e) { throw parent::convertException($e); } return AccountInfo::create($response->json()); }