CC_Utility
Class that is using REST to communicate with ConstantContact server This class currently supports actions performed using the contacts, lists, and campaigns APIs.
Defined (1)
The class is defined in the following location(s).
- /api/cc_class.php
- class CC_Utility {
- // FROM HERE YOU MAY MODIFY YOUR CREDENTIALS
- var $login = 'USERNAME'; //Username for your account
- var $password = 'PASSWORD'; //Password for your account
- var $apikey = 'a9f642af-8f34-43b2-8882-00e6aaebfa46'; // KWS API Key. Do not change.
- // CONTACT LIST OPTIONS
- var $contact_lists = array(); // Define which lists will be available for sign-up.
- var $force_lists = false; // Set this to true to take away the ability for users to select and de-select lists
- var $show_contact_lists = true; // Set this to false to hide the list name(s) on the sign-up form.
- // NOTE - Contact Lists will only be hidden if force_lists is set to true. This is to prevent available checkboxes form being hidden.
- // FORM OPT IN SOURCE - (Who is performing these actions?)
- var $actionBy = 'ACTION_BY_CONTACT'; // Values: ACTION_BY_CUSTOMER or ACTION_BY_CONTACT
- // ACTION_BY_CUSTOMER - Constant Contact Account holder. Used in internal applications.
- // ACTION_BY_CONTACT - Action by Site visitor. Used in web site sign-up forms.
- // DEBUGGING
- var $curl_debug = false; // Set this to true to see the response code returned by cURL
- // YOUR BASIC CHANGES SHOULD END HERE
- var $requestLogin; //this contains full authentication string.
- var $lastError = ''; // this variable will contain last error message (if any)
- var $apiPath = 'https://api.constantcontact.com/ws/customers/'; //is used for server calls.
- var $doNotIncludeLists = array('Removed', 'Do Not Mail', 'Active'); //define which lists shouldn't be returned.
- public function __construct() {
- //when the object is getting initialized, the login string must be created as API_KEY%LOGIN:PASSWORD
- $this->requestLogin = $this->apikey."%".$this->login.":".$this->password;
- $this->apiPath = $this->apiPath.$this->login;
- }
- /**
- * Method that returns a list with all states found in states.txt file
- * @return array with state codes and state names
- */
- public function getStates() {
- $returnArr = array();
- $lines = file("states.txt");
- foreach ($lines as $line) {
- $tmp = explode(" - ", $line);
- if (sizeof($tmp) == 2) {
- $returnArr[trim($tmp[1])] = trim($tmp[0]);
- }
- }
- return $returnArr;
- }
- /**
- * Returns a list with all countries found in countries.txt file
- * @return array with country codes and country names
- */
- public function getCountries() {
- $returnArr = array();
- $lines = file("countries.txt");
- foreach ($lines as $line) {
- $tmp = explode(" - ", $line);
- if (sizeof($tmp) == 2) {
- $returnArr[trim($tmp[1])] = trim($tmp[0]);
- }
- }
- return $returnArr;
- }
- /**
- * Validate an email address
- * @return TRUE if address is valid and FALSE if not.
- */
- protected function isValidEmail($email) {
- return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2, 3})$", $email);
- }
- /**
- * Private function used to send requests to ConstantContact server
- * @param string $request_url - is the URL where the request will be made
- * @param string $parameter - if it is not empty then this parameter will be sent using POST method
- * @param string $type - GET/POST/PUT/DELETE
- * @return string server output/response
- */
- protected function doServerCall($request_url, $parameter = '', $type = "GET") {
- $request_url = str_replace('http://', 'https://', $request_url);
- $request = array(
- 'method' => $type,
- 'sslverify' => false, // don't screw up with SSL requests
- 'timeout' => 10,
- 'user-agent' => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)",
- 'headers' => array(
- 'Authorization' => 'Basic ' . base64_encode( $this->requestLogin ),
- 'Content-Type' => 'application/atom+xml',
- 'Content-Length' => strlen($parameter)
- ),
- 'body' => $parameter,
- );
- $response = wp_remote_request( $request_url, $request );
- if( empty( $response ) || is_wp_error( $response ) ) {
- return false;
- } else if ( wp_remote_retrieve_response_code( $response ) > 299 ) {
- return false;
- } else {
- return wp_remote_retrieve_body( $response );
- }
- }
- }