';
+ echo 'File Uploaded!';
+ echo '';
foreach ($fileUploadStatus as $status) {
print_r($status);
}
diff --git a/src/Ctct/Auth/CtctDataStore.php b/src/Ctct/Auth/CtctDataStore.php
index c333bc1..58efef6 100644
--- a/src/Ctct/Auth/CtctDataStore.php
+++ b/src/Ctct/Auth/CtctDataStore.php
@@ -8,9 +8,7 @@
* @author Constant Contact
*/
-interface CtctDataStore
-{
-
+interface CtctDataStore {
/**
* Add a new user to the data store
* @param $id - unique identifier
diff --git a/src/Ctct/Auth/CtctOAuth2.php b/src/Ctct/Auth/CtctOAuth2.php
index 66eecd4..eb62138 100755
--- a/src/Ctct/Auth/CtctOAuth2.php
+++ b/src/Ctct/Auth/CtctOAuth2.php
@@ -13,16 +13,14 @@
* @package Auth
* @author Constant Contact
*/
-class CtctOAuth2
-{
+class CtctOAuth2 {
public $clientId;
public $clientSecret;
public $redirectUri;
public $client;
public $props;
- public function __construct($clientId, $clientSecret, $redirectUri)
- {
+ public function __construct($clientId, $clientSecret, $redirectUri) {
$this->clientId = $clientId;
$this->clientSecret = $clientSecret;
$this->redirectUri = $redirectUri;
@@ -35,8 +33,7 @@ public function __construct($clientId, $clientSecret, $redirectUri)
* @param string $state - An optional value used by the client to maintain state between the request and callback.
* @return string $url - The url to send a user to, to grant access to their account
*/
- public function getAuthorizationUrl($server = true, $state = null)
- {
+ public function getAuthorizationUrl($server = true, $state = null) {
$responseType = ($server) ? Config::get('auth.response_type_code') : Config::get("auth.response_type_token");
$params = array(
'response_type' => $responseType,
@@ -50,9 +47,8 @@ public function getAuthorizationUrl($server = true, $state = null)
}
$baseUrl = Config::get('auth.base_url') . Config::get('auth.authorization_endpoint');
- $request = $this->client->createRequest("GET", $baseUrl);
- $request->setQuery($params);
- return $request->getUrl();
+ $query = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
+ return $baseUrl . "?" . $query;
}
/**
@@ -61,8 +57,7 @@ public function getAuthorizationUrl($server = true, $state = null)
* @return array
* @throws OAuth2Exception
*/
- public function getAccessToken($code)
- {
+ public function getAccessToken($code) {
$params = array(
'grant_type' => Config::get('auth.authorization_code_grant_type'),
'client_id' => $this->clientId,
@@ -72,11 +67,10 @@ public function getAccessToken($code)
);
$baseUrl = Config::get('auth.base_url') . Config::get('auth.token_endpoint');
- $request = $this->client->createRequest("POST", $baseUrl);
- $request->setQuery($params);
-
try {
- $response = $this->client->send($request)->json();
+ $response = json_decode($this->client->request('POST', $baseUrl, [
+ 'query' => $params
+ ])->getBody(), true);
} catch (ClientException $e) {
throw $this->convertException($e);
}
@@ -84,34 +78,32 @@ public function getAccessToken($code)
return $response;
}
+ /**
+ * @param ClientException $exception
+ * @return OAuth2Exception
+ */
+ private function convertException($exception) {
+ $oauth2Exception = new OAuth2Exception($exception->getResponse()->getReasonPhrase(), $exception->getCode());
+ $oauth2Exception->setErrors(json_decode($exception->getResponse()->getBody()->getContents(), true));
+ return $oauth2Exception;
+ }
+
/**
* Get an information about an access token
* @param string $accessToken - Constant Contact OAuth2 access token
* @return array
* @throws CtctException
*/
- public function getTokenInfo($accessToken)
- {
+ public function getTokenInfo($accessToken) {
$baseUrl = Config::get('auth.base_url') . Config::get('auth.token_info');
- $request = $this->client->createRequest("POST", $baseUrl);
- $request->setQuery(array("access_token" => $accessToken));
try {
- $response = $this->client->send($request)->json();
+ $response = json_decode($this->client->request('POST', $baseUrl, [
+ 'query' => array("access_token" => $accessToken)
+ ])->getBody(), true);
} catch (ClientException $e) {
throw $this->convertException($e);
}
return $response;
}
-
- /**
- * @param ClientException $exception
- * @return OAuth2Exception
- */
- private function convertException($exception) {
- $oauth2Exception = new OAuth2Exception($exception->getResponse()->getReasonPhrase(), $exception->getCode());
- $oauth2Exception->setUrl($exception->getResponse()->getEffectiveUrl());
- $oauth2Exception->setErrors(json_decode($exception->getResponse()->getBody()->getContents()));
- return $oauth2Exception;
- }
}
diff --git a/src/Ctct/Auth/SessionDataStore.php b/src/Ctct/Auth/SessionDataStore.php
index b2ee0b0..bd79ed3 100755
--- a/src/Ctct/Auth/SessionDataStore.php
+++ b/src/Ctct/Auth/SessionDataStore.php
@@ -7,10 +7,8 @@
* @package Auth
* @author Constant Contact
*/
-class SessionDataStore implements CtctDataStore
-{
- public function __construct()
- {
+class SessionDataStore implements CtctDataStore {
+ public function __construct() {
session_start();
if (!isset($_SESSION['datastore'])) {
@@ -24,8 +22,7 @@ public function __construct()
* @param string $username - Constant Contact username
* @param array $params - additional parameters
*/
- public function addUser($username, array $params)
- {
+ public function addUser($username, array $params) {
$_SESSION['datastore'][$username] = $params;
}
@@ -34,8 +31,7 @@ public function addUser($username, array $params)
* @param string $username - Constant Contact username
* @return Array params of the username in the datastore, or false if the username doesn't exist
*/
- public function getUser($username)
- {
+ public function getUser($username) {
if (array_key_exists($username, $_SESSION['datastore'])) {
return $_SESSION['datastore'][$username];
} else {
@@ -48,8 +44,7 @@ public function getUser($username)
* @param string $username - Constant Contact username
* @param array $params - additional parameters
*/
- public function updateUser($username, array $params)
- {
+ public function updateUser($username, array $params) {
if (array_key_exists($username, $_SESSION['datastore'])) {
$_SESSION['datastore'][$username] = $params;
}
@@ -59,8 +54,7 @@ public function updateUser($username, array $params)
* Delete an existing user from the data store
* @param string $username - Constant Contact username
*/
- public function deleteUser($username)
- {
+ public function deleteUser($username) {
unset($_SESSION['datastore'][$username]);
}
}
diff --git a/src/Ctct/Components/Account/AccountInfo.php b/src/Ctct/Components/Account/AccountInfo.php
index 6aae3dd..2bd6797 100644
--- a/src/Ctct/Components/Account/AccountInfo.php
+++ b/src/Ctct/Components/Account/AccountInfo.php
@@ -10,8 +10,7 @@
* @subpackage Account
* @author ewaltman
*/
-class AccountInfo extends Component
-{
+class AccountInfo extends Component {
/**
* Website associated with the account
* @var string
@@ -83,8 +82,7 @@ class AccountInfo extends Component
* @param array $props - associative array of initial properties to set
* @return AccountInfo
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$accountInfo = new AccountInfo();
$accountInfo->website = parent::getValue($props, "website");
$accountInfo->organization_name = parent::getValue($props, "organization_name");
diff --git a/src/Ctct/Components/Account/VerifiedEmailAddress.php b/src/Ctct/Components/Account/VerifiedEmailAddress.php
index 1898f35..ab228dc 100644
--- a/src/Ctct/Components/Account/VerifiedEmailAddress.php
+++ b/src/Ctct/Components/Account/VerifiedEmailAddress.php
@@ -10,8 +10,7 @@
* @subpackage Account
* @author Constant Contact
*/
-class VerifiedEmailAddress extends Component
-{
+class VerifiedEmailAddress extends Component {
/**
* Email Address associated with the account
* @var string
@@ -29,8 +28,7 @@ class VerifiedEmailAddress extends Component
* @param array $props - associative array of initial properties to set
* @return VerifiedEmailAddress
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$verifiedAddress = new VerifiedEmailAddress();
$verifiedAddress->email_address = parent::getValue($props, "email_address");
$verifiedAddress->status = parent::getValue($props, "status");
diff --git a/src/Ctct/Components/Activities/Activity.php b/src/Ctct/Components/Activities/Activity.php
index 04a6029..8c4bc82 100644
--- a/src/Ctct/Components/Activities/Activity.php
+++ b/src/Ctct/Components/Activities/Activity.php
@@ -10,8 +10,7 @@
* @subpackage Activities
* @author Constant Contact
*/
-class Activity extends Component
-{
+class Activity extends Component {
public $id;
public $type;
public $status;
@@ -29,8 +28,7 @@ class Activity extends Component
* @param array $props - associative array of initial properties to set
* @return Activity
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$activity = new Activity();
$activity->id = parent::getValue($props, "id");
$activity->type = parent::getValue($props, "type");
@@ -73,8 +71,7 @@ public static function create(array $props)
* Create json used for a POST/PUT request, also handles removing attributes that will cause errors if sent
* @return string
*/
- public function toJson()
- {
+ public function toJson() {
return json_encode($this);
}
}
diff --git a/src/Ctct/Components/Activities/ActivityError.php b/src/Ctct/Components/Activities/ActivityError.php
index a1d1bed..ac4a82f 100644
--- a/src/Ctct/Components/Activities/ActivityError.php
+++ b/src/Ctct/Components/Activities/ActivityError.php
@@ -10,8 +10,7 @@
* @subpackage Activities
* @author Constant Contact
*/
-class ActivityError extends Component
-{
+class ActivityError extends Component {
public $message;
public $line_number;
public $email_address;
@@ -21,8 +20,7 @@ class ActivityError extends Component
* @param array $props - associative array of initial properties to set
* @return ActivityError
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$activityError = new ActivityError();
$activityError->message = parent::getValue($props, "message");
$activityError->line_number = parent::getValue($props, "line_number");
diff --git a/src/Ctct/Components/Activities/AddContacts.php b/src/Ctct/Components/Activities/AddContacts.php
index 585ca28..7e587a7 100644
--- a/src/Ctct/Components/Activities/AddContacts.php
+++ b/src/Ctct/Components/Activities/AddContacts.php
@@ -2,8 +2,8 @@
namespace Ctct\Components\Activities;
use Ctct\Components\Component;
-use Ctct\Util\Config;
use Ctct\Exceptions\IllegalArgumentException;
+use Ctct\Util\Config;
/**
* Represents an AddContacts Activity
@@ -12,14 +12,12 @@
* @subpackage Activities
* @author Constant Contact
*/
-class AddContacts extends Component
-{
+class AddContacts extends Component {
public $import_data = array();
public $lists = array();
public $column_names = array();
- public function __construct(Array $contacts, Array $lists, Array $columnNames = array())
- {
+ public function __construct(Array $contacts, Array $lists, Array $columnNames = array()) {
if (!empty($contacts)) {
if ($contacts[0] instanceof AddContactsImportData) {
$this->import_data = $contacts;
@@ -62,7 +60,7 @@ public function __construct(Array $contacts, Array $lists, Array $columnNames =
if (isset($contact->home_phone)) {
$usedColumns[] = Config::get('activities_columns.home_phone');
}
-
+
if (isset($contact->birthday_day)) {
$usedColumns[] = Config::get('activities_columns.birthday_day');
}
@@ -124,8 +122,7 @@ public function __construct(Array $contacts, Array $lists, Array $columnNames =
* Turn the object into json, removing any extra fields
* @return string
*/
- public function toJson()
- {
+ public function toJson() {
foreach ($this->import_data as $contact) {
foreach ($contact as $key => $value) {
if ($value == null) {
diff --git a/src/Ctct/Components/Activities/AddContactsImportData.php b/src/Ctct/Components/Activities/AddContactsImportData.php
index df79df2..3e53bc8 100644
--- a/src/Ctct/Components/Activities/AddContactsImportData.php
+++ b/src/Ctct/Components/Activities/AddContactsImportData.php
@@ -12,8 +12,7 @@
* @subpackage Activities
* @author Constant Contact
*/
-class AddContactsImportData extends Component
-{
+class AddContactsImportData extends Component {
public $first_name;
public $middle_name;
public $last_name;
@@ -21,11 +20,11 @@ class AddContactsImportData extends Component
public $company_name;
public $work_phone;
public $home_phone;
-
+
public $birthday_day;
public $birthday_month;
public $anniversary;
-
+
public $email_addresses = array();
public $addresses = array();
public $custom_fields = array();
@@ -34,20 +33,17 @@ class AddContactsImportData extends Component
* Factory method to create an Activity object from an array
* @param array $props - associative array of initial properties to set
*/
- public function __construct(array $props = array())
- {
+ public function __construct(array $props = array()) {
foreach ($this as $property => $value) {
$this->$property = parent::getValue($props, $property);
}
}
- public function addCustomField(CustomField $customField)
- {
+ public function addCustomField(CustomField $customField) {
$this->custom_fields[] = $customField;
}
- public function addAddress(Address $address)
- {
+ public function addAddress(Address $address) {
if (isset($address->state)) {
$address->state_code = $address->state;
unset($address->state);
@@ -61,13 +57,11 @@ public function addAddress(Address $address)
$this->addresses[] = $address;
}
- public function addEmail($emailAddress)
- {
+ public function addEmail($emailAddress) {
$this->email_addresses[] = $emailAddress;
}
- public function toJson()
- {
+ public function toJson() {
return json_encode($this);
}
}
diff --git a/src/Ctct/Components/Activities/ExportContacts.php b/src/Ctct/Components/Activities/ExportContacts.php
index 597b114..47f7d15 100644
--- a/src/Ctct/Components/Activities/ExportContacts.php
+++ b/src/Ctct/Components/Activities/ExportContacts.php
@@ -10,8 +10,7 @@
* @subpackage Activities
* @author Constant Contact
*/
-class ExportContacts extends Component
-{
+class ExportContacts extends Component {
public $file_type = "CSV";
public $sort_by = "EMAIL_ADDRESS";
public $export_date_added = true;
@@ -24,8 +23,7 @@ class ExportContacts extends Component
* @param array $lists - array of list id's to export from
* @return ExportContacts
*/
- public function __construct(Array $lists = null)
- {
+ public function __construct(Array $lists = null) {
if (!$lists == null) {
$this->lists = $lists;
}
@@ -35,8 +33,7 @@ public function __construct(Array $lists = null)
* Create json used for a POST/PUT request, also handles removing attributes that will cause errors if sent
* @return string
*/
- public function toJson()
- {
+ public function toJson() {
return json_encode($this);
}
}
diff --git a/src/Ctct/Components/Component.php b/src/Ctct/Components/Component.php
index dd86fb2..cb58c29 100755
--- a/src/Ctct/Components/Component.php
+++ b/src/Ctct/Components/Component.php
@@ -4,9 +4,7 @@
/**
* Super class for all components
*/
-abstract class Component
-{
-
+abstract class Component {
/**
* Get the requested value from an array, or return the default
* @param array $array - array to search for the provided array key
@@ -14,8 +12,7 @@ abstract class Component
* @param string $default - value to return if the item is not found, default is null
* @return mixed
*/
- protected static function getValue(array $array, $item, $default = null)
- {
+ protected static function getValue(array $array, $item, $default = null) {
return (isset($array[$item])) ? $array[$item] : $default;
}
}
diff --git a/src/Ctct/Components/Contacts/Address.php b/src/Ctct/Components/Contacts/Address.php
index 268b2a9..212fd14 100755
--- a/src/Ctct/Components/Contacts/Address.php
+++ b/src/Ctct/Components/Contacts/Address.php
@@ -10,9 +10,7 @@
* @subpackage Contacts
* @author Constant Contact
*/
-class Address extends Component
-{
-
+class Address extends Component {
/**
* Id of the address
* @var string
@@ -55,12 +53,12 @@ class Address extends Component
*/
public $state_code;
- /**
- * The state for this address (non-US/Canada)
- *
- */
- public $state;
-
+ /**
+ * The state for this address (non-US/Canada)
+ *
+ */
+ public $state;
+
/**
* The country code for this address
* @var string
@@ -84,8 +82,7 @@ class Address extends Component
* @param array $props - Associative array of initial properties to set
* @return Address
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$address = new Address();
$address->id = parent::getValue($props, "id");
$address->line1 = parent::getValue($props, "line1");
@@ -94,7 +91,7 @@ public static function create(array $props)
$address->city = parent::getValue($props, "city");
$address->address_type = parent::getValue($props, "address_type");
$address->state_code = parent::getValue($props, "state_code");
- $address->state = parent::getValue($props, "state");
+ $address->state = parent::getValue($props, "state");
$address->country_code = parent::getValue($props, "country_code");
$address->postal_code = parent::getValue($props, "postal_code");
$address->sub_postal_code = parent::getValue($props, "sub_postal_code");
diff --git a/src/Ctct/Components/Contacts/Contact.php b/src/Ctct/Components/Contacts/Contact.php
index 552efbf..9fa9efd 100755
--- a/src/Ctct/Components/Contacts/Contact.php
+++ b/src/Ctct/Components/Contacts/Contact.php
@@ -10,9 +10,7 @@
* @subpackage Contacts
* @author Constant Contact
*/
-class Contact extends Component
-{
-
+class Contact extends Component {
/**
* Unique identifier for the contact
* @var string
@@ -144,8 +142,7 @@ class Contact extends Component
* @param array $props - Associative array of initial properties to set
* @return Contact
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$contact = new Contact();
$contact->id = parent::getValue($props, "id");
$contact->status = parent::getValue($props, "status");
@@ -188,9 +185,9 @@ public static function create(array $props)
}
if (isset($props['lists'])) {
- foreach ($props['lists'] as $contact_list) {
- $contact->lists[] = ContactList::create($contact_list);
- }
+ foreach ($props['lists'] as $contact_list) {
+ $contact->lists[] = ContactList::create($contact_list);
+ }
}
$contact->created_date = parent::getValue($props, "created_date");
@@ -205,8 +202,7 @@ public static function create(array $props)
* Add a ContactList
* @param mixed $contactList - ContactList object or contact list id
*/
- public function addList($contactList)
- {
+ public function addList($contactList) {
if (!$contactList instanceof ContactList) {
$contactList = new ContactList($contactList);
}
@@ -218,8 +214,7 @@ public function addList($contactList)
* Add an EmailAddress
* @param mixed $emailAddress - EmailAddress object or email address
*/
- public function addEmail($emailAddress)
- {
+ public function addEmail($emailAddress) {
if (!$emailAddress instanceof EmailAddress) {
$emailAddress = new EmailAddress($emailAddress);
}
@@ -231,8 +226,7 @@ public function addEmail($emailAddress)
* Add a custom field to the contact object
* @param CustomField $customField - custom field to add to the contact
*/
- public function addCustomField(CustomField $customField)
- {
+ public function addCustomField(CustomField $customField) {
$this->custom_fields[] = $customField;
}
@@ -240,13 +234,11 @@ public function addCustomField(CustomField $customField)
* Add an address
* @param Address $address - Address to add
*/
- public function addAddress(Address $address)
- {
+ public function addAddress(Address $address) {
$this->addresses[] = $address;
}
- public function toJson()
- {
+ public function toJson() {
unset($this->last_update_date);
return json_encode($this);
}
diff --git a/src/Ctct/Components/Contacts/ContactList.php b/src/Ctct/Components/Contacts/ContactList.php
index 66c6207..19ea4a7 100755
--- a/src/Ctct/Components/Contacts/ContactList.php
+++ b/src/Ctct/Components/Contacts/ContactList.php
@@ -10,8 +10,7 @@
* @subpackage Contacts
* @author Constant Contact
*/
-class ContactList extends Component
-{
+class ContactList extends Component {
/**
* Unique identifier of the contact list
* @var string
@@ -48,8 +47,7 @@ class ContactList extends Component
*/
public $modified_date;
- public function __construct($list_id = null)
- {
+ public function __construct($list_id = null) {
if (!is_null($list_id)) {
$this->id = $list_id;
}
@@ -62,8 +60,7 @@ public function __construct($list_id = null)
* @param array $props - Associative array of initial properties to set
* @return ContactList
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$contact_list = new ContactList();
$contact_list->id = parent::getValue($props, "id");
$contact_list->name = parent::getValue($props, "name");
@@ -74,8 +71,7 @@ public static function create(array $props)
return $contact_list;
}
- public function toJson()
- {
+ public function toJson() {
return json_encode($this);
}
}
diff --git a/src/Ctct/Components/Contacts/CustomField.php b/src/Ctct/Components/Contacts/CustomField.php
index b8398c9..0e0770e 100755
--- a/src/Ctct/Components/Contacts/CustomField.php
+++ b/src/Ctct/Components/Contacts/CustomField.php
@@ -10,9 +10,7 @@
* @subpackage Contacts
* @author Constant Contact
*/
-class CustomField extends Component
-{
-
+class CustomField extends Component {
/**
* Name of the custom field
* @var string
@@ -30,8 +28,7 @@ class CustomField extends Component
* @param array $props - Associative array of initial properties to set
* @return CustomField
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$custom_field = new CustomField();
$custom_field->name = parent::getValue($props, "name");
$custom_field->value = parent::getValue($props, "value");
diff --git a/src/Ctct/Components/Contacts/EmailAddress.php b/src/Ctct/Components/Contacts/EmailAddress.php
index a5ddfc9..1506b5d 100755
--- a/src/Ctct/Components/Contacts/EmailAddress.php
+++ b/src/Ctct/Components/Contacts/EmailAddress.php
@@ -10,9 +10,7 @@
* @subpackage Contacts
* @author Constant Contact
*/
-class EmailAddress extends Component
-{
-
+class EmailAddress extends Component {
/**
* Id of the email address
* @var string
@@ -56,8 +54,7 @@ class EmailAddress extends Component
*/
public $email_address;
- public function __construct($email_address = null)
- {
+ public function __construct($email_address = null) {
if (!is_null($email_address)) {
$this->email_address = $email_address;
}
@@ -70,8 +67,7 @@ public function __construct($email_address = null)
* @param array $props - Associative array of initial properties to set
* @return EmailAddress
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$email_address = new EmailAddress();
$email_address->id = parent::getValue($props, "id");
$email_address->status = parent::getValue($props, "status");
diff --git a/src/Ctct/Components/Contacts/Note.php b/src/Ctct/Components/Contacts/Note.php
index f24ba81..48111ac 100755
--- a/src/Ctct/Components/Contacts/Note.php
+++ b/src/Ctct/Components/Contacts/Note.php
@@ -10,8 +10,7 @@
* @subpackage Contacts
* @author Constant Contact
*/
-class Note extends Component
-{
+class Note extends Component {
/**
* Id of the note
* @var string
@@ -35,8 +34,7 @@ class Note extends Component
* @param array $props - Associative array of initial properties to set
* @return Note
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$note = new Note();
$note->id = parent::getValue($props, "id");
$note->note = parent::getValue($props, "note");
diff --git a/src/Ctct/Components/EmailMarketing/Campaign.php b/src/Ctct/Components/EmailMarketing/Campaign.php
index 2fc44dd..c825bab 100755
--- a/src/Ctct/Components/EmailMarketing/Campaign.php
+++ b/src/Ctct/Components/EmailMarketing/Campaign.php
@@ -2,10 +2,10 @@
namespace Ctct\Components\EmailMarketing;
use Ctct\Components\Component;
-use Ctct\Util\Config;
-use Ctct\Components\Tracking\TrackingSummary;
use Ctct\Components\Contacts\ContactList;
+use Ctct\Components\Tracking\TrackingSummary;
use Ctct\Exceptions\IllegalArgumentException;
+use Ctct\Util\Config;
/**
* Represents a single Campaign in Constant Contact
@@ -14,8 +14,7 @@
* @subpackage EmailMarketing
* @author Constant Contact
*/
-class Campaign extends Component
-{
+class Campaign extends Component {
/**
* Unique identifier for the email campaign
* @var string
@@ -197,8 +196,7 @@ class Campaign extends Component
* @param array $props - associative array of initial properties to set
* @return Campaign
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$campaign = new Campaign();
$campaign->id = parent::getValue($props, "id");
$campaign->name = parent::getValue($props, "name");
@@ -255,8 +253,7 @@ public static function create(array $props)
* @param array $props - associative array of initial properties to set
* @return Campaign
*/
- public static function createSummary(array $props)
- {
+ public static function createSummary(array $props) {
$campaign = new Campaign();
$campaign->id = parent::getValue($props, "id");
$campaign->name = parent::getValue($props, "name");
@@ -278,8 +275,7 @@ public static function createSummary(array $props)
* @param mixed $contact_list - Contact list id, or ContactList object
* @throws IllegalArgumentException
*/
- public function addList($contact_list)
- {
+ public function addList($contact_list) {
if ($contact_list instanceof ContactList) {
$list = $contact_list;
} elseif (is_numeric($contact_list)) {
@@ -295,8 +291,7 @@ public function addList($contact_list)
* Create json used for a POST/PUT request, also handles removing attributes that will cause errors if sent
* @return string
*/
- public function toJson()
- {
+ public function toJson() {
$campaign = clone $this;
unset($campaign->id);
unset($campaign->created_date);
diff --git a/src/Ctct/Components/EmailMarketing/ClickThroughDetails.php b/src/Ctct/Components/EmailMarketing/ClickThroughDetails.php
index 29fe7e3..50d9d6b 100755
--- a/src/Ctct/Components/EmailMarketing/ClickThroughDetails.php
+++ b/src/Ctct/Components/EmailMarketing/ClickThroughDetails.php
@@ -10,8 +10,7 @@
* @subpackage Campaigns
* @author Constant Contact
*/
-class ClickThroughDetails extends Component
-{
+class ClickThroughDetails extends Component {
/**
* the actual url that was clicked on
* @var string
@@ -35,8 +34,7 @@ class ClickThroughDetails extends Component
* @param array $props - associative array of initial properties to set
* @return ClickThroughDetails
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$click_through_details = new ClickThroughDetails();
$click_through_details->url = parent::getValue($props, "url");
$click_through_details->url_uid = parent::getValue($props, "url_uid");
diff --git a/src/Ctct/Components/EmailMarketing/MessageFooter.php b/src/Ctct/Components/EmailMarketing/MessageFooter.php
index c984086..2287e5e 100755
--- a/src/Ctct/Components/EmailMarketing/MessageFooter.php
+++ b/src/Ctct/Components/EmailMarketing/MessageFooter.php
@@ -10,8 +10,7 @@
* @subpackage Campaigns
* @author Constant Contact
*/
-class MessageFooter extends Component
-{
+class MessageFooter extends Component {
public $city;
public $state;
public $country;
@@ -31,8 +30,7 @@ class MessageFooter extends Component
* @param array $props - associative array of initial properties to set
* @return MessageFooter
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$message_footer = new MessageFooter();
$message_footer->city = parent::getValue($props, "city");
$message_footer->state = parent::getValue($props, "state");
diff --git a/src/Ctct/Components/EmailMarketing/Schedule.php b/src/Ctct/Components/EmailMarketing/Schedule.php
index a0b5ec0..17f46ce 100755
--- a/src/Ctct/Components/EmailMarketing/Schedule.php
+++ b/src/Ctct/Components/EmailMarketing/Schedule.php
@@ -10,8 +10,7 @@
* @subpackage EmailMarketing
* @author Constant Contact
*/
-class Schedule extends Component
-{
+class Schedule extends Component {
/**
* unique id of the schedule
* @var string
@@ -30,8 +29,7 @@ class Schedule extends Component
* @param array $props - associative array of initial properties to set
* @return Schedule
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$schedule = new Schedule();
$schedule->id = parent::getValue($props, "id");
$schedule->scheduled_date = parent::getValue($props, "scheduled_date");
@@ -42,8 +40,7 @@ public static function create(array $props)
* Create json used for a POST/PUT request, also handles removing attributes that will cause errors if sent
* @return string
*/
- public function toJson()
- {
+ public function toJson() {
$schedule = clone $this;
unset($schedule->id);
return json_encode($schedule);
diff --git a/src/Ctct/Components/EmailMarketing/TestSend.php b/src/Ctct/Components/EmailMarketing/TestSend.php
index 551e2fd..2c31834 100755
--- a/src/Ctct/Components/EmailMarketing/TestSend.php
+++ b/src/Ctct/Components/EmailMarketing/TestSend.php
@@ -10,8 +10,7 @@
* @subpackage EmailMarketing
* @author Constant Contact
*/
-class TestSend extends Component
-{
+class TestSend extends Component {
/**
* Format of the email to send (HTML, TEXT, HTML_AND_TEXT)
* @var string
@@ -35,8 +34,7 @@ class TestSend extends Component
* @param array $props - associative array of initial properties to set
* @return TestSend
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$test_send = new TestSend();
$test_send->format = parent::getValue($props, "format");
$test_send->personal_message = parent::getValue($props, "personal_message");
@@ -52,8 +50,7 @@ public static function create(array $props)
* Add an email address to the set of addresses to send the test send too
* @param string $email_address
*/
- public function addEmail($email_address)
- {
+ public function addEmail($email_address) {
$this->email_addresses[] = $email_address;
}
@@ -61,8 +58,7 @@ public function addEmail($email_address)
* Create json used for a POST/PUT request, also handles removing attributes that will cause errors if sent
* @return string
*/
- public function toJson()
- {
+ public function toJson() {
$testSend = clone $this;
if ($testSend->personal_message == null) {
unset($testSend->personal_message);
diff --git a/src/Ctct/Components/EventSpot/Address.php b/src/Ctct/Components/EventSpot/Address.php
new file mode 100755
index 0000000..2762b69
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/Address.php
@@ -0,0 +1,103 @@
+id = parent::getValue($props, "id");
+ $address->line1 = parent::getValue($props, "line1");
+ $address->line2 = parent::getValue($props, "line2");
+ $address->line3 = parent::getValue($props, "line3");
+ $address->city = parent::getValue($props, "city");
+ $address->address_type = parent::getValue($props, "address_type");
+ $address->state_code = parent::getValue($props, "state_code");
+ $address->state = parent::getValue($props, "state");
+ $address->country_code = parent::getValue($props, "country_code");
+ $address->postal_code = parent::getValue($props, "postal_code");
+ $address->sub_postal_code = parent::getValue($props, "sub_postal_code");
+ return $address;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/Contact.php b/src/Ctct/Components/EventSpot/Contact.php
new file mode 100644
index 0000000..e493baa
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/Contact.php
@@ -0,0 +1,50 @@
+email_address = parent::getValue($props, "email_address");
+ $guest->name = parent::getValue($props, "name");
+ $guest->organization_name = parent::getValue($props, "organization_name");
+ $guest->phone_number = parent::getValue($props, "phone_number");
+
+ return $guest;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/EventFee.php b/src/Ctct/Components/EventSpot/EventFee.php
new file mode 100644
index 0000000..a8d9abc
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/EventFee.php
@@ -0,0 +1,84 @@
+id = parent::getValue($props, "id");
+ $event_fee->label = parent::getValue($props, "label");
+ $event_fee->fee = parent::getValue($props, "fee");
+ $event_fee->fee_scope = parent::getValue($props, "fee_scope");
+ $event_fee->early_fee = parent::getValue($props, "early_fee");
+ $event_fee->late_fee = parent::getValue($props, "late_fee");
+ $event_fee->has_restricted_access = parent::getValue($props, "has_restricted_access");
+
+ return $event_fee;
+ }
+
+ public function toJson()
+ {
+ return json_encode($this);
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/EventSpot.php b/src/Ctct/Components/EventSpot/EventSpot.php
new file mode 100644
index 0000000..6d7e6ee
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/EventSpot.php
@@ -0,0 +1,366 @@
+id = parent::getValue($props, "id");
+ $event->active_date = parent::getValue($props, "active_date");
+ if(!empty($props['address'])) {
+ $event->address = Address::create( parent::getValue( $props, "address" ) );
+ }
+ $event->are_registrants_public = parent::getValue($props, "are_registrants_public");
+ $event->cancelled_date = parent::getValue($props, "cancelled_date");
+ if(!empty( $props['contact'])) {
+ $event->contact = Contact::create( parent::getValue( $props, "contact" ) );
+ }
+ $event->created_date = parent::getValue($props, "created_date");
+ $event->currency_type = parent::getValue($props, "currency_type");
+ $event->deleted_date = parent::getValue($props, "deleted_date");
+ $event->description = parent::getValue($props, "description");
+ $event->end_date = parent::getValue($props, "end_date");
+ $event->event_detail_url = parent::getValue($props, "event_detail_url");
+ $event->google_analytics_key = parent::getValue($props, "google_analytics_key");
+ $event->google_merchant_id = parent::getValue($props, "google_merchant_id");
+ $event->is_calendar_displayed = parent::getValue($props, "is_calendar_displayed");
+ $event->is_checkin_available = parent::getValue($props, "is_checkin_available");
+ $event->is_home_page_displayed = parent::getValue($props, "is_home_page_displayed");
+ $event->is_listed_in_external_directory = parent::getValue($props, "is_listed_in_external_directory");
+ $event->is_map_displayed = parent::getValue($props, "is_map_displayed");
+ $event->is_virtual_event = parent::getValue($props, "is_virtual_event");
+ $event->location = parent::getValue($props, "location");
+ $event->meta_data_tags = parent::getValue($props, "meta_data_tags");
+ $event->name = parent::getValue($props, "name");
+ if( parent::getValue( $props, "notification_options" ) ) {
+ $event->notification_options = NotificationOption::create( parent::getValue( $props, "notification_options" ) );
+ }
+ $event->online_meeting = parent::getValue($props, "online_meeting");
+ $event->payable_to = parent::getValue($props, "payable_to");
+ $event->payable_to = parent::getValue($props, "payable_to");
+ if( parent::getValue( $props, "payment_address" ) ) {
+ $event->payment_address = Address::create( parent::getValue( $props, "payment_address" ) );
+ }
+ $event->payment_options = parent::getValue($props, "payment_options");
+ $event->paypal_account_email = parent::getValue($props, "paypal_account_email");
+ $event->registration_url = parent::getValue($props, "registration_url");
+ $event->start_date = parent::getValue($props, "start_date");
+ $event->status = parent::getValue($props, "status");
+ $event->theme_name = parent::getValue($props, "theme_name");
+ $event->time_zone_description = parent::getValue($props, "time_zone_description");
+ $event->time_zone_id = parent::getValue($props, "time_zone_id");
+ $event->title = parent::getValue($props, "title");
+ $event->total_registered_count = parent::getValue($props, "total_registered_count");
+ if( parent::getValue( $props, "track_information" ) ) {
+ $event->track_information = TrackInformation::create( parent::getValue( $props, "track_information" ) );
+ }
+ $event->twitter_hash_tag = parent::getValue($props, "twitter_hash_tag");
+ $event->type = parent::getValue($props, "type");
+ $event->updated_date = parent::getValue($props, "updated_date");
+
+ return $event;
+ }
+
+ public function toJson()
+ {
+ return json_encode($this);
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/EventSpotList.php b/src/Ctct/Components/EventSpot/EventSpotList.php
new file mode 100644
index 0000000..84eeb68
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/EventSpotList.php
@@ -0,0 +1,72 @@
+id = parent::getValue($props, "id");
+ $event_list->title = parent::getValue($props, "title");
+ $event_list->status = parent::getValue($props, "status");
+ $event_list->total_registered_count = parent::getValue($props, "total_registered_count");
+ $event_list->created_date = parent::getValue($props, "created_date");
+ $event_list->updated_date = parent::getValue($props, "updated_date");
+ return $event_list;
+ }
+
+ public function toJson()
+ {
+ return json_encode($this);
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/Guest.php b/src/Ctct/Components/EventSpot/Guest.php
new file mode 100644
index 0000000..eb2543e
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/Guest.php
@@ -0,0 +1,39 @@
+guest_id = parent::getValue($props, "guest_id");
+ $guest->guest_section = GuestSection::create(parent::getValue($props, "guest_section"));
+ return $guest;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/GuestSection.php b/src/Ctct/Components/EventSpot/GuestSection.php
new file mode 100644
index 0000000..f8e767f
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/GuestSection.php
@@ -0,0 +1,45 @@
+label = parent::getValue($props, "label");
+
+ if (isset($props['fields'])) {
+ foreach ($props['fields'] as $field) {
+ $guest_section->fields[] = GuestSectionField::create($field);
+ }
+ }
+ return $guest_section;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/GuestSectionField.php b/src/Ctct/Components/EventSpot/GuestSectionField.php
new file mode 100644
index 0000000..c38b682
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/GuestSectionField.php
@@ -0,0 +1,62 @@
+type = parent::getValue($props, "type");
+ $guest_section_field->name = parent::getValue($props, "name");
+ $guest_section_field->label = parent::getValue($props, "label");
+ $guest_section_field->value = parent::getValue($props, "value");
+ $guest_section_field->values = parent::getValue($props, "values");
+
+ return $guest_section_field;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/NotificationOption.php b/src/Ctct/Components/EventSpot/NotificationOption.php
new file mode 100644
index 0000000..1fdb084
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/NotificationOption.php
@@ -0,0 +1,39 @@
+is_opted_in = parent::getValue($props, "guest_id");
+ $notification_option->notification_type = parent::getValue($props, "notification_type");
+ return $notification_option;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/OnlineMeeting.php b/src/Ctct/Components/EventSpot/OnlineMeeting.php
new file mode 100644
index 0000000..4a1c3e7
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/OnlineMeeting.php
@@ -0,0 +1,51 @@
+is_opted_in = parent::getValue($props, "guest_id");
+ $online_meeting->notification_type = parent::getValue($props, "notification_type");
+ return $online_meeting;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/PaymentSummary.php b/src/Ctct/Components/EventSpot/PaymentSummary.php
new file mode 100644
index 0000000..e8889b6
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/PaymentSummary.php
@@ -0,0 +1,73 @@
+payment_status = parent::getValue($props, "payment_status");
+ $payment_summary->payment_type = parent::getValue($props, "payment_type");
+
+ if( isset($props["order"])) {
+ $payment_summary->order = RegistrantOrder::create( parent::getValue( $props, "order" ) );
+ }
+
+ if (!empty($props['promo_code'])) {
+ $payment_summary->promo_code = RegistrantPromoCode::create($props['promo_code']);
+ }
+
+ return $payment_summary;
+ }
+
+ public function toJson()
+ {
+ return json_encode($this);
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/Promocode.php b/src/Ctct/Components/EventSpot/Promocode.php
new file mode 100644
index 0000000..686bea3
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/Promocode.php
@@ -0,0 +1,127 @@
+code_name = parent::getValue($props, "code_name");
+ $promocode->code_type = parent::getValue($props, "code_type");
+ $promocode->discount_amount = parent::getValue($props, "discount_amount");
+ $promocode->discount_percent = parent::getValue($props, "discount_percent");
+ $promocode->discount_scope = parent::getValue($props, "discount_scope");
+ $promocode->discount_type = parent::getValue($props, "discount_type");
+ $promocode->id = parent::getValue($props, "id");
+ $promocode->fee_ids = parent::getValue($props, "fee_ids");
+ $promocode->is_paused = parent::getValue($props, "is_paused");
+ $promocode->quantity_available = parent::getValue($props, "quantity_available");
+ $promocode->quantity_total = parent::getValue($props, "quantity_total");
+ $promocode->quantity_used = parent::getValue($props, "quantity_used");
+ $promocode->status = parent::getValue($props, "status");
+
+ return $promocode;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/Registrant/Registrant.php b/src/Ctct/Components/EventSpot/Registrant/Registrant.php
new file mode 100644
index 0000000..5e8fad7
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/Registrant/Registrant.php
@@ -0,0 +1,188 @@
+attendance_status = parent::getValue($props, "attendance_status");
+ $event_registrant->id = parent::getValue($props, "id");
+ $event_registrant->registration_date = parent::getValue($props, "registration_date");
+ $event_registrant->registration_status = parent::getValue($props, "registration_status");
+ $event_registrant->ticket_id = parent::getValue($props, "ticket_id");
+ $event_registrant->updated_date = parent::getValue($props, "updated_date");
+
+ if ( isset( $props['payment_summary'] ) ) {
+ $event_registrant->payment_summary = PaymentSummary::create( $props['payment_summary'] );
+ $event_registrant->payment_status = $event_registrant->payment_summary->payment_status;
+ } else {
+ $event_registrant->payment_status = parent::getValue($props, "payment_status");
+ }
+
+
+ if ( !empty( $props['sections'] ) ) {
+ foreach ($props['sections'] as $section) {
+ $event_registrant->sections[] = RegistrantSection::create($section);
+ }
+ }
+
+ $event_registrant->email = isset( $props['email'] ) ? parent::getValue($props, "email") : $event_registrant->getFieldValue('EMAIL_ADDRESS');
+ $event_registrant->first_name = isset( $props['first_name'] ) ? parent::getValue($props, "first_name") : $event_registrant->getFieldValue('NAME_FIRST');
+ $event_registrant->last_name = isset( $props['last_name'] ) ? parent::getValue($props, "last_name") : $event_registrant->getFieldValue('NAME_LAST');
+
+ if (!empty($props['guests']) && isset( $props['guests']['guest_info'] ) ) {
+
+ $event_registrant->guest_count = $props['guests']['guest_count'];
+
+ foreach ($props['guests']['guest_info'] as $guest) {
+ $event_registrant->guests[] = Guest::create($guest);
+ }
+ } else {
+ $event_registrant->guest_count = parent::getValue($props, "guest_count");
+ }
+
+ return $event_registrant;
+ }
+
+ /**
+ * Get a field value from the RegistrantSection storage by field name
+ *
+ * @param string $fieldName Name of the field to get for the Registrant, like "NAME_LAST" or "CUSTOM1"
+ *
+ * @return string|array|null For single_value field types, returns string. For multiple_value field types, returns array. If not found, returns null
+ */
+ public function getFieldValue( $fieldName ) {
+
+ /** @var RegistrantSection $section */
+ foreach ( $this->sections as $section ) {
+
+ /** @var RegistrantSectionField $field */
+ foreach ( $section->fields as $field ) {
+ if( $fieldName === $field->name ) {
+ return is_null( $field->values ) ? $field->value : $field->values;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public function toJson()
+ {
+ return json_encode($this);
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/Registrant/RegistrantFee.php b/src/Ctct/Components/EventSpot/Registrant/RegistrantFee.php
new file mode 100644
index 0000000..8f67c7a
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/Registrant/RegistrantFee.php
@@ -0,0 +1,76 @@
+id = parent::getValue($props, "id");
+ $registrant_fee->name = parent::getValue($props, "name");
+ $registrant_fee->type = parent::getValue($props, "type");
+ $registrant_fee->quantity = parent::getValue($props, "quantity");
+ $registrant_fee->amount = parent::getValue($props, "amount");
+ $registrant_fee->fee_period_type = parent::getValue($props, "fee_period_type");
+ $registrant_fee->promo_type = parent::getValue($props, "promo_type");
+
+ return $registrant_fee;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/Registrant/RegistrantOrder.php b/src/Ctct/Components/EventSpot/Registrant/RegistrantOrder.php
new file mode 100644
index 0000000..9c42e88
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/Registrant/RegistrantOrder.php
@@ -0,0 +1,67 @@
+order_id = parent::getValue($props, "order_id");
+ $registrant_order->order_date = parent::getValue($props, "order_date");
+ $registrant_order->currency_type = parent::getValue($props, "currency_type");
+ $registrant_order->total = parent::getValue($props, "total");
+
+ if( isset($props['fees']) ) {
+ foreach ( $props['fees'] as $fee ) {
+ $registrant_order->fees[] = RegistrantFee::create($fee);
+ }
+ }
+
+ return $registrant_order;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/Registrant/RegistrantPromocode.php b/src/Ctct/Components/EventSpot/Registrant/RegistrantPromocode.php
new file mode 100644
index 0000000..06f8537
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/Registrant/RegistrantPromocode.php
@@ -0,0 +1,39 @@
+total_discount = parent::getValue($props, "total_discount");
+ $registrant_promo_code->promo_code_info = RegistrantPromoCodeInfo::create(parent::getValue($props, "promo_code_info"));
+ return $registrant_promo_code;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/Registrant/RegistrantPromocodeInfo.php b/src/Ctct/Components/EventSpot/Registrant/RegistrantPromocodeInfo.php
new file mode 100644
index 0000000..670cc1f
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/Registrant/RegistrantPromocodeInfo.php
@@ -0,0 +1,75 @@
+code_name = parent::getValue($props, "code_name");
+ $registrant_promo_code_info->code_type = parent::getValue($props, "code_type");
+ $registrant_promo_code_info->discount_amount = parent::getValue($props, "discount_amount");
+ $registrant_promo_code_info->discount_percent = parent::getValue($props, "discount_percent");
+ $registrant_promo_code_info->discount_scope = parent::getValue($props, "discount_scope");
+ $registrant_promo_code_info->discount_type = parent::getValue($props, "discount_type");
+ $registrant_promo_code_info->redemption_count = parent::getValue($props, "redemption_count");
+
+ return $registrant_promo_code_info;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/Registrant/RegistrantSection.php b/src/Ctct/Components/EventSpot/Registrant/RegistrantSection.php
new file mode 100644
index 0000000..813fed9
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/Registrant/RegistrantSection.php
@@ -0,0 +1,45 @@
+label = parent::getValue($props, "label");
+
+ if (isset($props['fields'])) {
+ foreach ($props['fields'] as $field) {
+ $registrant_section->fields[] = RegistrantSectionField::create($field);
+ }
+ }
+
+ return $registrant_section;
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/Registrant/RegistrantSectionField.php b/src/Ctct/Components/EventSpot/Registrant/RegistrantSectionField.php
new file mode 100644
index 0000000..b5fdd00
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/Registrant/RegistrantSectionField.php
@@ -0,0 +1,65 @@
+type = parent::getValue($props, "type");
+ $field->name = parent::getValue($props, "name");
+ $field->label = parent::getValue($props, "label");
+ $field->value = parent::getValue($props, "value");
+ $field->values = parent::getValue($props, "values");
+ return $field;
+ }
+
+ public function toJson()
+ {
+ return json_encode($this);
+ }
+}
diff --git a/src/Ctct/Components/EventSpot/TrackInformation.php b/src/Ctct/Components/EventSpot/TrackInformation.php
new file mode 100644
index 0000000..43a8639
--- /dev/null
+++ b/src/Ctct/Components/EventSpot/TrackInformation.php
@@ -0,0 +1,103 @@
+early_fee_date = parent::getValue($props, "early_fee_date");
+ $track_information->guest_display_label = parent::getValue($props, "guest_display_label");
+ $track_information->guest_limit = parent::getValue($props, "guest_limit");
+ $track_information->information_sections = parent::getValue($props, "information_sections");
+ $track_information->is_guest_anonymous_enabled = parent::getValue($props, "is_guest_anonymous_enabled");
+ $track_information->is_guest_name_required = parent::getValue($props, "is_guest_name_required");
+ $track_information->is_registration_closed_manually = parent::getValue($props, "is_registration_closed_manually");
+ $track_information->is_ticketing_link_displayed = parent::getValue($props, "is_ticketing_link_displayed");
+ $track_information->late_fee_date = parent::getValue($props, "late_fee_date");
+ $track_information->registration_limit_count = parent::getValue($props, "registration_limit_count");
+ $track_information->registration_limit_date = parent::getValue($props, "registration_limit_date");
+ return $track_information;
+ }
+}
diff --git a/src/Ctct/Components/Library/FileUploadStatus.php b/src/Ctct/Components/Library/FileUploadStatus.php
index 51b4d36..6c6281b 100644
--- a/src/Ctct/Components/Library/FileUploadStatus.php
+++ b/src/Ctct/Components/Library/FileUploadStatus.php
@@ -31,8 +31,7 @@ class FileUploadStatus extends Component {
*/
public $status;
- public static function create(Array $props)
- {
+ public static function create(Array $props) {
$fileUploadStatus = new FileUploadStatus();
$fileUploadStatus->description = parent::getValue($props, "description");
diff --git a/src/Ctct/Components/ResultSet.php b/src/Ctct/Components/ResultSet.php
index 075c871..4a5d88a 100644
--- a/src/Ctct/Components/ResultSet.php
+++ b/src/Ctct/Components/ResultSet.php
@@ -5,8 +5,7 @@
* Container for a get on a collection, such as Contacts, Campaigns, or TrackingData.
*
*/
-class ResultSet
-{
+class ResultSet {
/**
* array of result objects returned
* @var array
@@ -24,8 +23,7 @@ class ResultSet
* @param array $results - results array from request
* @param array $meta - meta array from request
*/
- public function __construct(array $results, array $meta)
- {
+ public function __construct(array $results, array $meta) {
$this->results = $results;
if (array_key_exists('next_link', $meta['pagination'])) {
diff --git a/src/Ctct/Components/Tracking/BounceActivity.php b/src/Ctct/Components/Tracking/BounceActivity.php
index 0b354f1..77cb1da 100755
--- a/src/Ctct/Components/Tracking/BounceActivity.php
+++ b/src/Ctct/Components/Tracking/BounceActivity.php
@@ -10,8 +10,7 @@
* @subpackage CampaignTracking
* @author Constant Contact
*/
-class BounceActivity extends Component
-{
+class BounceActivity extends Component {
public $activity_type;
public $bounce_code;
public $bounce_description;
@@ -26,8 +25,7 @@ class BounceActivity extends Component
* @param array $props - array of properties to create object from
* @return BounceActivity
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$bounceActivity = new BounceActivity();
$bounceActivity->activity_type = parent::getValue($props, "activity_type");
$bounceActivity->bounce_code = parent::getValue($props, "bounce_code");
diff --git a/src/Ctct/Components/Tracking/ClickActivity.php b/src/Ctct/Components/Tracking/ClickActivity.php
index 0a7b0e9..b41cfd0 100755
--- a/src/Ctct/Components/Tracking/ClickActivity.php
+++ b/src/Ctct/Components/Tracking/ClickActivity.php
@@ -10,13 +10,13 @@
* @subpackage CampaignTracking
* @author Constant Contact
*/
-class ClickActivity extends Component
-{
+class ClickActivity extends Component {
public $activity_type;
public $campaign_id;
public $contact_id;
public $email_address;
public $link_id;
+ public $link_uri;
public $click_date;
/**
@@ -24,14 +24,14 @@ class ClickActivity extends Component
* @param array $props - array of properties to create object from
* @return ClickActivity
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$click_activity = new ClickActivity();
$click_activity->activity_type = parent::getValue($props, "activity_type");
$click_activity->campaign_id = parent::getValue($props, "campaign_id");
$click_activity->contact_id = parent::getValue($props, "contact_id");
$click_activity->email_address = parent::getValue($props, "email_address");
$click_activity->link_id = parent::getValue($props, "link_id");
+ $click_activity->link_uri = parent::getValue($props, "link_uri");
$click_activity->click_date = parent::getValue($props, "click_date");
return $click_activity;
}
diff --git a/src/Ctct/Components/Tracking/ForwardActivity.php b/src/Ctct/Components/Tracking/ForwardActivity.php
index f2118e8..737d35b 100755
--- a/src/Ctct/Components/Tracking/ForwardActivity.php
+++ b/src/Ctct/Components/Tracking/ForwardActivity.php
@@ -10,8 +10,7 @@
* @subpackage CampaignTracking
* @author Constant Contact
*/
-class ForwardActivity extends Component
-{
+class ForwardActivity extends Component {
public $activity_type;
public $campaign_id;
public $contact_id;
@@ -23,8 +22,7 @@ class ForwardActivity extends Component
* @param array $props - array of properties to create object from
* @return ForwardActivity
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$forward_activity = new ForwardActivity();
$forward_activity->activity_type = parent::getValue($props, "activity_type");
$forward_activity->campaign_id = parent::getValue($props, "campaign_id");
diff --git a/src/Ctct/Components/Tracking/OpenActivity.php b/src/Ctct/Components/Tracking/OpenActivity.php
index 7e5f708..d63cdf8 100755
--- a/src/Ctct/Components/Tracking/OpenActivity.php
+++ b/src/Ctct/Components/Tracking/OpenActivity.php
@@ -11,8 +11,7 @@
* @subpackage CampaignTracking
* @author Constant Contact
*/
-class OpenActivity extends Component
-{
+class OpenActivity extends Component {
public $activity_type;
public $open_date;
public $contact_id;
@@ -24,8 +23,7 @@ class OpenActivity extends Component
* @param array $props - array of properties to create object from
* @return OpenActivity
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$open_activity = new OpenActivity();
$open_activity->activity_type = parent::getValue($props, "activity_type");
$open_activity->open_date = parent::getValue($props, "open_date");
diff --git a/src/Ctct/Components/Tracking/SendActivity.php b/src/Ctct/Components/Tracking/SendActivity.php
index 640c361..f0c96e2 100755
--- a/src/Ctct/Components/Tracking/SendActivity.php
+++ b/src/Ctct/Components/Tracking/SendActivity.php
@@ -10,8 +10,7 @@
* @subpackage CampaignTracking
* @author Constant Contact
*/
-class SendActivity extends Component
-{
+class SendActivity extends Component {
public $activity_type;
public $send_date;
public $contact_id;
@@ -23,8 +22,7 @@ class SendActivity extends Component
* @param array $props - array of properties to create object from
* @return SendActivity
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$sent_activity = new SendActivity();
$sent_activity->activity_type = parent::getValue($props, "activity_type");
$sent_activity->send_date = parent::getValue($props, "send_date");
diff --git a/src/Ctct/Components/Tracking/TrackingActivity.php b/src/Ctct/Components/Tracking/TrackingActivity.php
index 0363fff..d816f65 100755
--- a/src/Ctct/Components/Tracking/TrackingActivity.php
+++ b/src/Ctct/Components/Tracking/TrackingActivity.php
@@ -8,8 +8,7 @@
* @subpackage CampaignTracking
* @author Constant Contact
*/
-class TrackingActivity
-{
+class TrackingActivity {
public $results = array();
public $next;
@@ -18,8 +17,7 @@ class TrackingActivity
* @param array $results - results array from a tracking endpoint
* @param array $pagination - pagination array returned from a tracking endpoint
*/
- public function __construct(array $results, array $pagination)
- {
+ public function __construct(array $results, array $pagination) {
$this->results = $results;
if (array_key_exists('next', $pagination)) {
diff --git a/src/Ctct/Components/Tracking/TrackingSummary.php b/src/Ctct/Components/Tracking/TrackingSummary.php
index b093b6d..288393e 100755
--- a/src/Ctct/Components/Tracking/TrackingSummary.php
+++ b/src/Ctct/Components/Tracking/TrackingSummary.php
@@ -10,8 +10,7 @@
* @subpackage Campaigns
* @author Constant Contact
*/
-class TrackingSummary extends Component
-{
+class TrackingSummary extends Component {
public $sends;
public $opens;
public $clicks;
@@ -25,8 +24,7 @@ class TrackingSummary extends Component
* @param array $props - array of properties to create object from
* @return TrackingSummary
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$tracking_summary = new TrackingSummary();
$tracking_summary->sends = parent::getValue($props, "sends");
$tracking_summary->opens = parent::getValue($props, "opens");
@@ -37,10 +35,10 @@ public static function create(array $props)
$tracking_summary->spam_count = parent::getValue($props, "spam_count");
// Contacts don't have spam_count, only Campaigns
- if(is_null($tracking_summary->spam_count)) {
+ if (is_null($tracking_summary->spam_count)) {
unset($tracking_summary->spam_count);
}
-
+
return $tracking_summary;
}
}
diff --git a/src/Ctct/Components/Tracking/UnsubscribeActivity.php b/src/Ctct/Components/Tracking/UnsubscribeActivity.php
index 92e49cf..4436dd4 100755
--- a/src/Ctct/Components/Tracking/UnsubscribeActivity.php
+++ b/src/Ctct/Components/Tracking/UnsubscribeActivity.php
@@ -10,8 +10,7 @@
* @subpackage CampaignTracking
* @author Constant Contact
*/
-class UnsubscribeActivity extends Component
-{
+class UnsubscribeActivity extends Component {
public $activity_type;
public $campaign_id;
public $contact_id;
@@ -25,8 +24,7 @@ class UnsubscribeActivity extends Component
* @param array $props - array of properties to create object from
* @return UnsubscribeActivity
*/
- public static function create(array $props)
- {
+ public static function create(array $props) {
$opt_out_activity = new UnsubscribeActivity();
$opt_out_activity->activity_type = parent::getValue($props, "activity_type");
$opt_out_activity->unsubscribe_date = parent::getValue($props, "unsubscribe_date");
diff --git a/src/Ctct/ConstantContact.php b/src/Ctct/ConstantContact.php
index 6db9f0e..f415a1d 100755
--- a/src/Ctct/ConstantContact.php
+++ b/src/Ctct/ConstantContact.php
@@ -2,14 +2,16 @@
namespace Ctct;
use Ctct\Services\AccountService;
-use Ctct\Services\ContactService;
-use Ctct\Services\LibraryService;
-use Ctct\Services\ListService;
-use Ctct\Services\EmailMarketingService;
+use Ctct\Services\ActivityService;
use Ctct\Services\CampaignScheduleService;
use Ctct\Services\CampaignTrackingService;
+use Ctct\Services\ContactService;
use Ctct\Services\ContactTrackingService;
-use Ctct\Services\ActivityService;
+use Ctct\Services\EmailMarketingService;
+use Ctct\Services\LibraryService;
+use Ctct\Services\ListService;
+use GuzzleHttp\Client;
+use GuzzleHttp\ClientInterface;
/**
* Exposes all implemented Constant Contact API functionality
@@ -19,8 +21,7 @@
* @author Constant Contact
* @link https://developer.constantcontact.com
*/
-class ConstantContact
-{
+class ConstantContact {
/**
* Handles interaction with contact management
* @var ContactService
@@ -79,17 +80,19 @@ class ConstantContact
* Class constructor
* Registers the API key with the ConstantContact class that will be used for all API calls.
* @param string $apiKey - Constant Contact API Key
+ * @param ClientInterface|null $client - GuzzleHttp Client
*/
- public function __construct($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);
- $this->libraryService = new LibraryService($apiKey);
+ public function __construct($apiKey, ClientInterface $client = null) {
+ $client = $client ?: new Client();
+
+ $this->contactService = new ContactService($apiKey, $client);
+ $this->emailMarketingService = new EmailMarketingService($apiKey, $client);
+ $this->activityService = new ActivityService($apiKey, $client);
+ $this->campaignTrackingService = new CampaignTrackingService($apiKey, $client);
+ $this->contactTrackingService = new ContactTrackingService($apiKey, $client);
+ $this->campaignScheduleService = new CampaignScheduleService($apiKey, $client);
+ $this->listService = new ListService($apiKey, $client);
+ $this->accountService = new AccountService($apiKey, $client);
+ $this->libraryService = new LibraryService($apiKey, $client);
}
}
diff --git a/src/Ctct/Exceptions/CtctException.php b/src/Ctct/Exceptions/CtctException.php
index 978849f..d7dde11 100644
--- a/src/Ctct/Exceptions/CtctException.php
+++ b/src/Ctct/Exceptions/CtctException.php
@@ -9,29 +9,24 @@
* @package exceptions
* @author djellesma
*/
-class CtctException extends Exception
-{
+class CtctException extends Exception {
private $errors;
private $url;
- public function setErrors(array $errors)
- {
- $this->errors = $errors;
+ public function getErrors() {
+ return $this->errors;
}
- public function getErrors()
- {
- return $this->errors;
+ public function setErrors(array $errors) {
+ $this->errors = $errors;
}
- public function setUrl($url)
- {
+ public function setUrl($url) {
$this->url = $url;
}
- public function getCurlInfo()
- {
+ public function getCurlInfo() {
return $this->url;
}
}
diff --git a/src/Ctct/Exceptions/IllegalArgumentException.php b/src/Ctct/Exceptions/IllegalArgumentException.php
index 5ffa639..99985f4 100755
--- a/src/Ctct/Exceptions/IllegalArgumentException.php
+++ b/src/Ctct/Exceptions/IllegalArgumentException.php
@@ -9,6 +9,5 @@
* @package exceptions
* @author djellesma
*/
-class IllegalArgumentException extends Exception
-{
+class IllegalArgumentException extends Exception {
}
diff --git a/src/Ctct/Exceptions/OAuth2Exception.php b/src/Ctct/Exceptions/OAuth2Exception.php
index c1c2c85..a3a8091 100755
--- a/src/Ctct/Exceptions/OAuth2Exception.php
+++ b/src/Ctct/Exceptions/OAuth2Exception.php
@@ -7,6 +7,5 @@
* @package exceptions
* @author djellesma
*/
-class OAuth2Exception extends CtctException
-{
+class OAuth2Exception extends CtctException {
}
diff --git a/src/Ctct/Services/AccountService.php b/src/Ctct/Services/AccountService.php
index a18cb8f..59c330b 100644
--- a/src/Ctct/Services/AccountService.php
+++ b/src/Ctct/Services/AccountService.php
@@ -1,12 +1,12 @@
getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
+ $request = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
try {
$response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
$verifiedAddresses = array();
- foreach ($response->json() as $verifiedAddress) {
+ foreach (json_decode($response->getBody(), true) as $verifiedAddress) {
$verifiedAddresses[] = VerifiedEmailAddress::create($verifiedAddress);
}
@@ -59,22 +50,18 @@ public function getVerifiedEmailAddresses($accessToken, Array $params = array())
* @return array - array of VerifiedEmailAddress created
* @throws CtctException
*/
- public function createVerifiedEmailAddress($accessToken, $emailAddress)
- {
+ public function createVerifiedEmailAddress($accessToken, $emailAddress) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.account_verified_addresses');
-
- $request = parent::createBaseRequest($accessToken, 'POST', $baseUrl);
- $stream = Stream::factory(json_encode(array(array("email_address" => $emailAddress))));
- $request->setBody($stream);
+ $request = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, array(array("email_address" => $emailAddress)));
try {
$response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
$verifiedAddresses = array();
- foreach ($response->json() as $verifiedAddress) {
+ foreach (json_decode($response->getBody(), true) as $verifiedAddress) {
$verifiedAddresses[] = VerifiedEmailAddress::create($verifiedAddress);
}
@@ -87,19 +74,18 @@ public function createVerifiedEmailAddress($accessToken, $emailAddress)
* @return AccountInfo
* @throws CtctException
*/
- public function getAccountInfo($accessToken)
- {
+ public function getAccountInfo($accessToken) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.account_info');
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
+ $request = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
try {
$response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return AccountInfo::create($response->json());
+ return AccountInfo::create(json_decode($response->getBody(), true));
}
/**
@@ -109,20 +95,17 @@ public function getAccountInfo($accessToken)
* @return AccountInfo
* @throws CtctException
*/
- public function updateAccountInfo($accessToken, AccountInfo $accountInfo)
- {
+ 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);
+ $request = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, $accountInfo);
try {
$response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return AccountInfo::create($response->json());
+ return AccountInfo::create(json_decode($response->getBody(), true));
}
}
diff --git a/src/Ctct/Services/ActivityService.php b/src/Ctct/Services/ActivityService.php
index 646cf37..94ce077 100644
--- a/src/Ctct/Services/ActivityService.php
+++ b/src/Ctct/Services/ActivityService.php
@@ -1,15 +1,13 @@
getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
$activities = array();
- foreach ($response->json() as $activity) {
+ foreach (json_decode($response->getBody(), true) as $activity) {
$activities[] = Activity::create($activity);
}
return $activities;
@@ -62,19 +50,16 @@ public function getActivities($accessToken, Array $params = array())
* @return array - Array of all ActivitySummaryReports
* @throws CtctException
*/
- public function getActivity($accessToken, $activityId)
- {
+ public function getActivity($accessToken, $activityId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.activity'), $activityId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Activity::create($response->json());
+ return Activity::create(json_decode($response->getBody(), true));
}
/**
@@ -84,21 +69,16 @@ public function getActivity($accessToken, $activityId)
* @return array - Array of all ActivitySummaryReports
* @throws CtctException
*/
- public function createAddContactsActivity($accessToken, AddContacts $addContacts)
- {
+ public function createAddContactsActivity($accessToken, AddContacts $addContacts) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.add_contacts_activity');
- $request = parent::createBaseRequest($accessToken, 'POST', $baseUrl);
- $stream = Stream::factory(json_encode($addContacts));
- $request->setBody($stream);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $addContacts);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Activity::create($response->json());
+ return Activity::create(json_decode($response->getBody(), true));
}
/**
@@ -110,25 +90,27 @@ public function createAddContactsActivity($accessToken, AddContacts $addContacts
* @return Activity
* @throws CtctException
*/
- public function createAddContactsActivityFromFile($accessToken, $fileName, $fileLocation, $lists)
- {
+ public function createAddContactsActivityFromFile($accessToken, $fileName, $fileLocation, $lists) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.add_contacts_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);
+ $request = new Request('POST', $baseUrl, [
+ parent::getHeadersForMultipart($accessToken)
+ ]);
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = $this->getClient()->send($request, [
+ 'multipart' => [
+ [
+ 'lists' => $lists,
+ 'file_name' => $fileName,
+ 'data' => fopen($fileLocation, 'r')
+ ]
+ ]
+ ]);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Activity::create($response->json());
+ return Activity::create(json_decode($response->getBody(), true));
}
/**
@@ -139,20 +121,16 @@ public function createAddContactsActivityFromFile($accessToken, $fileName, $file
* @return Activity
* @throws CtctException
*/
- public function addClearListsActivity($accessToken, Array $lists)
- {
+ public function addClearListsActivity($accessToken, Array $lists) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.clear_lists_activity');
- $request = parent::createBaseRequest($accessToken, "POST", $baseUrl);
- $stream = Stream::factory(json_encode(array("lists" => $lists)));
- $request->setBody($stream);
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, "POST", $baseUrl, array("lists" => $lists));
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Activity::create($response->json());
+ return Activity::create(json_decode($response->getBody(), true));
}
/**
@@ -162,21 +140,16 @@ public function addClearListsActivity($accessToken, Array $lists)
* @return array - Array of all ActivitySummaryReports
* @throws CtctException
*/
- public function addExportContactsActivity($accessToken, ExportContacts $exportContacts)
- {
+ public function addExportContactsActivity($accessToken, ExportContacts $exportContacts) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.export_contacts_activity');
- $request = parent::createBaseRequest($accessToken, 'POST', $baseUrl);
- $stream = Stream::factory(json_encode($exportContacts));
- $request->setBody($stream);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $exportContacts);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Activity::create($response->json());
+ return Activity::create(json_decode($response->getBody(), true));
}
/**
@@ -187,29 +160,23 @@ public function addExportContactsActivity($accessToken, ExportContacts $exportCo
* @return Activity
* @throws CtctException
*/
- public function addRemoveContactsFromListsActivity($accessToken, Array $emailAddresses, Array $lists)
- {
+ public function addRemoveContactsFromListsActivity($accessToken, Array $emailAddresses, Array $lists) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.remove_from_lists_activity');
- $request = parent::createBaseRequest($accessToken, "POST", $baseUrl);
-
$payload = array(
'import_data' => array(),
'lists' => $lists
);
- foreach($emailAddresses as $emailAddress) {
+ foreach ($emailAddresses as $emailAddress) {
$payload['import_data'][] = array('email_addresses' => array($emailAddress));
}
- $stream = Stream::factory(json_encode($payload));
- $request->setBody($stream);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, "POST", $baseUrl, $payload);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Activity::create($response->json());
+ return Activity::create(json_decode($response->getBody(), true));
}
/**
@@ -221,24 +188,26 @@ public function addRemoveContactsFromListsActivity($accessToken, Array $emailAdd
* @return Activity
* @throws CtctException
*/
- public function addRemoveContactsFromListsActivityFromFile($accessToken, $fileName, $fileLocation, $lists)
- {
+ 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);
+ $request = new Request('POST', $baseUrl, [
+ parent::getHeadersForMultipart($accessToken)
+ ]);
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = $this->getClient()->send($request, [
+ 'multipart' => [
+ [
+ 'lists' => $lists,
+ 'file_name' => $fileName,
+ 'data' => fopen($fileLocation, 'r')
+ ]
+ ]
+ ]);;
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Activity::create($response->json());
+ return Activity::create(json_decode($response->getBody(), true));
}
}
diff --git a/src/Ctct/Services/BaseService.php b/src/Ctct/Services/BaseService.php
index f236a08..7f7e666 100755
--- a/src/Ctct/Services/BaseService.php
+++ b/src/Ctct/Services/BaseService.php
@@ -4,7 +4,11 @@
use Ctct\Exceptions\CtctException;
use Ctct\Util\Config;
use GuzzleHttp\Client;
+use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ClientException;
+use GuzzleHttp\Exception\ServerException;
+use GuzzleHttp\Exception\TransferException;
+use GuzzleHttp\Psr7\Request;
/**
* Super class for all services
@@ -12,30 +16,12 @@
* @package Services
* @author Constant Contact
*/
-abstract class BaseService
-{
- /**
- * Helper function to return required headers for making an http request with constant contact
- * @param $accessToken - OAuth2 access token to be placed into the Authorization header
- * @return array - authorization headers
- */
- private static function getHeaders($accessToken)
- {
- return array(
- 'User-Agent' => 'ConstantContact AppConnect PHP Library v' . Config::get('settings.version'),
- 'Content-Type' => 'application/json',
- 'Accept' => 'application/json',
- 'Authorization' => 'Bearer ' . $accessToken,
- 'x-ctct-request-source' => 'sdk.php' . Config::get('settings.version')
- );
- }
-
+abstract class BaseService {
/**
* GuzzleHTTP Client Implementation to use for HTTP requests
* @var Client
*/
private $client;
-
/**
* ApiKey for the application
* @var string
@@ -45,38 +31,77 @@ private static function getHeaders($accessToken)
/**
* Constructor with the option to to supply an alternative rest client to be used
* @param string $apiKey - Constant Contact API Key
+ * @param ClientInterface|null $client - GuzzleHttp Client
*/
- public function __construct($apiKey)
- {
+ public function __construct($apiKey, ClientInterface $client = null) {
$this->apiKey = $apiKey;
- $this->client = new Client();
+ $this->client = $client ?: new Client();
+ }
+
+ protected static function getHeadersForMultipart($accessToken) {
+ return array(
+ 'User-Agent' => 'ConstantContact AppConnect PHP Library v' . Config::get('settings.version'),
+ 'Content-Type' => 'multipart/form-data',
+ 'Authorization' => 'Bearer ' . $accessToken
+ );
}
/**
* Get the rest client being used by the service
* @return Client - GuzzleHTTP Client implementation being used
*/
- protected function getClient()
- {
+ protected function getClient() {
return $this->client;
}
- protected function createBaseRequest($accessToken, $method, $baseUrl) {
- $request = $this->client->createRequest($method, $baseUrl);
- $request->getQuery()->set("api_key", $this->apiKey);
- $request->setHeaders($this->getHeaders($accessToken));
- return $request;
+ protected function sendRequestWithBody($accessToken, $method, $baseUrl, $body, Array $queryParams = array()) {
+ $queryParams["api_key"] = $this->apiKey;
+ $request = new Request($method, $baseUrl);
+ return $this->client->send($request, [
+ 'query' => $queryParams,
+ 'json' => $body,
+ 'headers' => self::getHeaders($accessToken)
+ ]);
+ }
+
+ /**
+ * Helper function to return required headers for making an http request with constant contact
+ * @param $accessToken - OAuth2 access token to be placed into the Authorization header
+ * @return array - authorization headers
+ */
+ private static function getHeaders($accessToken) {
+ return array(
+ 'User-Agent' => 'ConstantContact AppConnect PHP Library v' . Config::get('settings.version'),
+ 'Content-Type' => 'application/json',
+ 'Accept' => 'application/json',
+ 'Authorization' => 'Bearer ' . $accessToken,
+ 'x-ctct-request-source' => 'sdk.php.' . Config::get('settings.version')
+ );
+ }
+
+ protected function sendRequestWithoutBody($accessToken, $method, $baseUrl, Array $queryParams = array()) {
+ $queryParams["api_key"] = $this->apiKey;
+ $request = new Request($method, $baseUrl);
+
+ return $this->client->send($request, [
+ 'query' => $queryParams,
+ 'headers' => self::getHeaders($accessToken)
+ ]);
}
/**
* Turns a ClientException into a CtctException - like magic.
- * @param ClientException $exception - Guzzle ClientException
+ * @param TransferException $exception - Guzzle TransferException can be one of RequestException,
+ * ConnectException, ClientException, ServerException
* @return CtctException
*/
- protected function convertException($exception)
- {
- $ctctException = new CtctException($exception->getResponse()->getReasonPhrase(), $exception->getCode());
- $ctctException->setUrl($exception->getResponse()->getEffectiveUrl());
+ protected function convertException($exception) {
+ if ($exception instanceof ClientException || $exception instanceof ServerException) {
+ $ctctException = new CtctException($exception->getResponse()->getReasonPhrase(), $exception->getCode());
+ } else {
+ $ctctException = new CtctException("Something went wrong", $exception->getCode());
+ }
+ $ctctException->setUrl($exception->getRequest()->getUri());
$ctctException->setErrors(json_decode($exception->getResponse()->getBody()->getContents()));
return $ctctException;
}
diff --git a/src/Ctct/Services/CampaignScheduleService.php b/src/Ctct/Services/CampaignScheduleService.php
index d81fca0..210b9a2 100755
--- a/src/Ctct/Services/CampaignScheduleService.php
+++ b/src/Ctct/Services/CampaignScheduleService.php
@@ -1,12 +1,11 @@
setBody($stream);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $schedule);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Schedule::create($response->json());
+ return Schedule::create(json_decode($response->getBody(), true));
}
/**
@@ -48,20 +41,17 @@ public function addSchedule($accessToken, $campaignId, Schedule $schedule)
* @return array
* @throws CtctException
*/
- public function getSchedules($accessToken, $campaignId)
- {
+ public function getSchedules($accessToken, $campaignId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_schedules'), $campaignId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
$schedules = array();
- foreach ($response->json() as $schedule) {
+ foreach (json_decode($response->getBody(), true) as $schedule) {
$schedules[] = Schedule::create($schedule);
}
return $schedules;
@@ -75,19 +65,16 @@ public function getSchedules($accessToken, $campaignId)
* @return Schedule
* @throws CtctException
*/
- public function getSchedule($accessToken, $campaignId, $scheduleId)
- {
+ public function getSchedule($accessToken, $campaignId, $scheduleId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_schedule'), $campaignId, $scheduleId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Schedule::create($response->json());
+ return Schedule::create(json_decode($response->getBody(), true));
}
/**
@@ -98,21 +85,16 @@ public function getSchedule($accessToken, $campaignId, $scheduleId)
* @return Schedule
* @throws CtctException
*/
- public function updateSchedule($accessToken, $campaignId, Schedule $schedule)
- {
+ public function updateSchedule($accessToken, $campaignId, Schedule $schedule) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_schedule'), $campaignId, $schedule->id);
- $request = parent::createBaseRequest($accessToken, 'PUT', $baseUrl);
- $stream = Stream::factory(json_encode($schedule));
- $request->setBody($stream);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, $schedule);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Schedule::create($response->json());
+ return Schedule::create(json_decode($response->getBody(), true));
}
/**
@@ -123,15 +105,12 @@ public function updateSchedule($accessToken, $campaignId, Schedule $schedule)
* @return True if successful
* @throws CtctException
*/
- public function deleteSchedule($accessToken, $campaignId, $scheduleId)
- {
+ public function deleteSchedule($accessToken, $campaignId, $scheduleId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_schedule'), $campaignId, $scheduleId);
- $request = parent::createBaseRequest($accessToken, 'DELETE', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'DELETE', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
@@ -146,20 +125,15 @@ public function deleteSchedule($accessToken, $campaignId, $scheduleId)
* @return TestSend
* @throws CtctException
*/
- public function sendTest($accessToken, $campaignId, TestSend $testSend)
- {
+ 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) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'POST', $baseUrl, $testSend);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return TestSend::create($response->json());
+ return TestSend::create(json_decode($response->getBody(), true));
}
}
diff --git a/src/Ctct/Services/CampaignTrackingService.php b/src/Ctct/Services/CampaignTrackingService.php
index 577f894..9be3c0f 100755
--- a/src/Ctct/Services/CampaignTrackingService.php
+++ b/src/Ctct/Services/CampaignTrackingService.php
@@ -1,18 +1,18 @@
getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$bounces = array();
foreach ($body['results'] as $bounceActivity) {
$bounces[] = BounceActivity::create($bounceActivity);
@@ -73,25 +62,16 @@ public function getBounces($accessToken, $campaignId, Array $params = array())
* @return ResultSet - Containing a results array of {@link ClickActivity}
* @throws CtctException
*/
- public function getClicks($accessToken, $campaignId, Array $params = array())
- {
+ public function getClicks($accessToken, $campaignId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_tracking_clicks'), $campaignId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$clicks = array();
foreach ($body['results'] as $click_activity) {
$clicks[] = ClickActivity::create($click_activity);
@@ -112,25 +92,16 @@ public function getClicks($accessToken, $campaignId, Array $params = array())
* @return ResultSet - Containing a results array of {@link ForwardActivity}
* @throws CtctException
*/
- public function getForwards($accessToken, $campaignId, Array $params = array())
- {
+ public function getForwards($accessToken, $campaignId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_tracking_forwards'), $campaignId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$forwards = array();
foreach ($body['results'] as $forward_activity) {
$forwards[] = ForwardActivity::create($forward_activity);
@@ -151,25 +122,16 @@ public function getForwards($accessToken, $campaignId, Array $params = array())
* @return ResultSet - Containing a results array of {@link OpenActivity}
* @throws CtctException
*/
- public function getOpens($accessToken, $campaignId, Array $params = array())
- {
+ public function getOpens($accessToken, $campaignId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_tracking_opens'), $campaignId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$opens = array();
foreach ($body['results'] as $open_activity) {
$opens[] = OpenActivity::create($open_activity);
@@ -182,7 +144,7 @@ public function getOpens($accessToken, $campaignId, Array $params = array())
* Get sends for a given campaign
* @param string $accessToken - Constant Contact OAuth2 access token
* @param string $campaignId - Campaign id
- * @param Array $params = array() - associative array of query parameters and values to append to the request.
+ * @param array $params - associative array of query parameters and values to append to the request.
* Allowed parameters include:
* limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
* created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
@@ -190,25 +152,16 @@ public function getOpens($accessToken, $campaignId, Array $params = array())
* @return TrackingActivity - Containing a results array of {@link SendActivity}
* @throws CtctException
*/
- public function getSends($accessToken, $campaignId, Array $params = array())
- {
+ public function getSends($accessToken, $campaignId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_tracking_sends'), $campaignId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$sends = array();
foreach ($body['results'] as $send_activity) {
$sends[] = SendActivity::create($send_activity);
@@ -229,25 +182,16 @@ public function getSends($accessToken, $campaignId, Array $params = array())
* @return ResultSet - Containing a results array of {@link UnsubscribeActivity}
* @throws CtctException
*/
- public function getUnsubscribes($accessToken, $campaignId, Array $params = array())
- {
+ public function getUnsubscribes($accessToken, $campaignId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_tracking_unsubscribes'), $campaignId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$optOuts = array();
foreach ($body['results'] as $opt_out_activity) {
$optOuts[] = UnsubscribeActivity::create($opt_out_activity);
@@ -263,18 +207,15 @@ public function getUnsubscribes($accessToken, $campaignId, Array $params = array
* @return TrackingSummary
* @throws CtctException
*/
- public function getSummary($accessToken, $campaignId)
- {
+ public function getSummary($accessToken, $campaignId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_tracking_summary'), $campaignId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return TrackingSummary::create($response->json());
+ return TrackingSummary::create(json_decode($response->getBody(), true));
}
}
diff --git a/src/Ctct/Services/ContactService.php b/src/Ctct/Services/ContactService.php
index fdb042e..ae3fb57 100755
--- a/src/Ctct/Services/ContactService.php
+++ b/src/Ctct/Services/ContactService.php
@@ -1,12 +1,11 @@
getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$contacts = array();
foreach ($body['results'] as $contact) {
$contacts[] = Contact::create($contact);
@@ -69,25 +58,16 @@ public function getContacts($accessToken, Array $params = array())
* @return ResultSet
* @throws CtctException
*/
- public function getContactsFromList($accessToken, $listId, Array $params = array())
- {
+ public function getContactsFromList($accessToken, $listId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list_contacts'), $listId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$contacts = array();
foreach ($body['results'] as $contact) {
$contacts[] = Contact::create($contact);
@@ -102,107 +82,76 @@ public function getContactsFromList($accessToken, $listId, Array $params = array
* @return Contact
* @throws CtctException
*/
- public function getContact($accessToken, $contactId)
- {
+ public function getContact($accessToken, $contactId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact'), $contactId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Contact::create($response->json());
+ return Contact::create(json_decode($response->getBody(), true));
}
/**
- * Add a new contact to the Constant Contact account
+ * Opt out a contact
* @param string $accessToken - Constant Contact OAuth2 access token
- * @param Contact $contact - Contact to add
- * @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
+ * @param int $contactId - Unique contact id
+ * @return boolean
* @throws CtctException
*/
- public function addContact($accessToken, Contact $contact, Array $params = array())
- {
- $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.contacts');
-
- $request = parent::createBaseRequest($accessToken, 'POST', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
- $stream = Stream::factory(json_encode($contact));
- $request->setBody($stream);
+ public function unsubscribeContact($accessToken, $contactId) {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact'), $contactId);
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'DELETE', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Contact::create($response->json());
+ return ($response->getStatusCode() == 204) ? true : false;
}
/**
- * Opt out a contact
+ * Add a new contact to the Constant Contact account
* @param string $accessToken - Constant Contact OAuth2 access token
- * @param int $contactId - Unique contact id
- * @return boolean
+ * @param Contact $contact - Contact to add
+ * @param boolean $actionByContact - true if the creation is being made by the owner of the email address
+ * @return Contact
* @throws CtctException
*/
- public function unsubscribeContact($accessToken, $contactId) {
- $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact'), $contactId);
-
- $request = parent::createBaseRequest($accessToken, 'DELETE', $baseUrl);
+ public function addContact($accessToken, Contact $contact, $actionByContact) {
+ $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.contacts');
+ $params["action_by"] = ($actionByContact ? "ACTION_BY_VISITOR" : "ACTION_BY_OWNER");
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $contact, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return ($response->getStatusCode() == 204) ? true : false;
+ return Contact::create(json_decode($response->getBody(), 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 - 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
+ * @param boolean $actionByContact - true if the update is being made by the owner of the email address
* @return Contact
* @throws CtctException
*/
- public function updateContact($accessToken, Contact $contact, Array $params = array())
- {
+ public function updateContact($accessToken, Contact $contact, $actionByContact) {
$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);
+ $params["action_by"] = ($actionByContact ? "ACTION_BY_VISITOR" : "ACTION_BY_OWNER");
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, $contact, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Contact::create($response->json());
+ return Contact::create(json_decode($response->getBody(), true));
}
}
diff --git a/src/Ctct/Services/ContactTrackingService.php b/src/Ctct/Services/ContactTrackingService.php
index d4ae8c7..6a241c6 100755
--- a/src/Ctct/Services/ContactTrackingService.php
+++ b/src/Ctct/Services/ContactTrackingService.php
@@ -1,17 +1,17 @@
getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$bounces = array();
foreach ($body['results'] as $bounceActivity) {
$bounces[] = BounceActivity::create($bounceActivity);
@@ -72,25 +62,16 @@ public function getBounces($accessToken, $contactId, Array $params = array())
* @return ResultSet - Containing a results array of {@link ClickActivity}
* @throws CtctException
*/
- public function getClicks($accessToken, $contactId, Array $params = array())
- {
+ public function getClicks($accessToken, $contactId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact_tracking_clicks'), $contactId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$clicks = array();
foreach ($body['results'] as $click_activity) {
$clicks[] = ClickActivity::create($click_activity);
@@ -111,25 +92,16 @@ public function getClicks($accessToken, $contactId, Array $params = array())
* @return ResultSet - Containing a results array of {@link ForwardActivity}
* @throws CtctException
*/
- public function getForwards($accessToken, $contactId, Array $params = array())
- {
+ public function getForwards($accessToken, $contactId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact_tracking_forwards'), $contactId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$forwards = array();
foreach ($body['results'] as $forward_activity) {
$forwards[] = ForwardActivity::create($forward_activity);
@@ -150,25 +122,16 @@ public function getForwards($accessToken, $contactId, Array $params = array())
* @return ResultSet - Containing a results array of {@link OpenActivity}
* @throws CtctException
*/
- public function getOpens($accessToken, $contactId, Array $params = array())
- {
+ public function getOpens($accessToken, $contactId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact_tracking_opens'), $contactId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$opens = array();
foreach ($body['results'] as $open_activity) {
$opens[] = OpenActivity::create($open_activity);
@@ -189,25 +152,16 @@ public function getOpens($accessToken, $contactId, Array $params = array())
* @return ResultSet - Containing a results array of {@link SendActivity}
* @throws CtctException
*/
- public function getSends($accessToken, $contactId, Array $params = array())
- {
+ public function getSends($accessToken, $contactId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact_tracking_sends'), $contactId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$sends = array();
foreach ($body['results'] as $send_activity) {
$sends[] = SendActivity::create($send_activity);
@@ -228,25 +182,16 @@ public function getSends($accessToken, $contactId, Array $params = array())
* @return ResultSet - Containing a results array of {@link UnsubscribeActivity}
* @throws CtctException
*/
- public function getUnsubscribes($accessToken, $contactId, Array $params = array())
- {
+ public function getUnsubscribes($accessToken, $contactId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact_tracking_unsubscribes'), $contactId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$opt_outs = array();
foreach ($body['results'] as $opt_out_activity) {
$opt_outs[] = UnsubscribeActivity::create($opt_out_activity);
@@ -262,18 +207,15 @@ public function getUnsubscribes($accessToken, $contactId, Array $params = array(
* @return TrackingSummary
* @throws CtctException
*/
- public function getSummary($accessToken, $contactId)
- {
+ public function getSummary($accessToken, $contactId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact_tracking_summary'), $contactId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return TrackingSummary::create($response->json());
+ return TrackingSummary::create(json_decode($response->getBody(), true));
}
}
diff --git a/src/Ctct/Services/EmailMarketingService.php b/src/Ctct/Services/EmailMarketingService.php
index d3b7e3c..8712c7d 100755
--- a/src/Ctct/Services/EmailMarketingService.php
+++ b/src/Ctct/Services/EmailMarketingService.php
@@ -1,13 +1,12 @@
message_footer == null) {
// API doesn't work well with a null message footer, so omit it entirely.
unset($campaign->message_footer);
}
- $request = parent::createBaseRequest($accessToken, 'POST', $baseUrl);
- $stream = Stream::factory(json_encode($campaign));
- $request->setBody($stream);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $campaign);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Campaign::create($response->json());
+ return Campaign::create(json_decode($response->getBody(), true));
}
/**
@@ -56,25 +49,16 @@ public function addCampaign($accessToken, Campaign $campaign)
* @return ResultSet
* @throws CtctException
*/
- public function getCampaigns($accessToken, Array $params = array())
- {
+ public function getCampaigns($accessToken, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.campaigns');
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$campaigns = array();
foreach ($body['results'] as $contact) {
$campaigns[] = Campaign::createSummary($contact);
@@ -90,19 +74,16 @@ public function getCampaigns($accessToken, Array $params = array())
* @return Campaign
* @throws CtctException
*/
- public function getCampaign($accessToken, $campaignId)
- {
+ public function getCampaign($accessToken, $campaignId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign'), $campaignId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Campaign::create($response->json());
+ return Campaign::create(json_decode($response->getBody(), true));
}
/**
@@ -112,15 +93,12 @@ public function getCampaign($accessToken, $campaignId)
* @return boolean
* @throws CtctException
*/
- public function deleteCampaign($accessToken, $campaignId)
- {
+ public function deleteCampaign($accessToken, $campaignId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign'), $campaignId);
- $request = parent::createBaseRequest($accessToken, 'DELETE', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'DELETE', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
@@ -134,21 +112,16 @@ public function deleteCampaign($accessToken, $campaignId)
* @return Campaign
* @throws CtctException
*/
- public function updateCampaign($accessToken, Campaign $campaign)
- {
+ public function updateCampaign($accessToken, Campaign $campaign) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign'), $campaign->id);
- $request = parent::createBaseRequest($accessToken, 'PUT', $baseUrl);
- $stream = Stream::factory(json_encode($campaign));
- $request->setBody($stream);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, $campaign);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return Campaign::create($response->json());
+ return Campaign::create(json_decode($response->getBody(), true));
}
/**
@@ -161,13 +134,12 @@ public function updateCampaign($accessToken, Campaign $campaign)
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) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return CampaignPreview::create($response->json());
+ return CampaignPreview::create(json_decode($response->getBody(), true));
}
}
diff --git a/src/Ctct/Services/EventSpotService.php b/src/Ctct/Services/EventSpotService.php
new file mode 100644
index 0000000..3f02359
--- /dev/null
+++ b/src/Ctct/Services/EventSpotService.php
@@ -0,0 +1,329 @@
+getBody(), true);
+
+ $events = array();
+ if( ! empty( $body['results'] ) ) {
+ foreach ( $body['results'] as $event ) {
+ $events[] = EventSpot::create( $event );
+ }
+ }
+
+ return new ResultSet($events, $body['meta']);
+ }
+
+ /**
+ * Create a new Event
+ * @param string $accessToken Constant Contact OAuth2 access token
+ * @param EventSpot $event
+ * @return EventSpot
+ * @throws CtctException
+ */
+ public function addEvent($accessToken, EventSpot $event)
+ {
+ $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.events');
+
+ try {
+ $response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $event);
+ } catch (ClientException $e) {
+ throw parent::convertException($e);
+ }
+
+ return EventSpot::create(json_decode($response->getBody(), true));
+ }
+
+ /**
+ * Update an EventSpot Event
+ * @param string $accessToken Constant Contact OAuth2 access token
+ * @param EventSpot $event - EventSpot to be updated
+ * @return EventSpot
+ * @throws CtctException
+ */
+ public function updateEvent($accessToken, EventSpot $event)
+ {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.event'), $event->id);
+
+ try {
+ $response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, $event);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ return EventSpot::create(json_decode($response->getBody(), true));
+ }
+
+ /**
+ * Delete an Event
+ * @param string $accessToken Constant Contact OAuth2 access token
+ * @param string|int $eventId - event id
+ * @return boolean
+ * @throws CtctException
+ */
+ public function deleteEvent($accessToken, $eventId)
+ {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.event'), $eventId);
+
+ try {
+ $response = parent::sendRequestWithoutBody($accessToken, 'DELETE', $baseUrl);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ return ($response->getStatusCode() == 204) ? true : false;
+ }
+
+ /**
+ * Get an individual Event
+ * @param $accessToken - Constant Contact OAuth2 access token
+ * @param $eventId - event id
+ * @return EventSpot
+ * @throws CtctException
+ */
+ public function getEvent($accessToken, $eventId)
+ {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.event'), $eventId);
+
+ try {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ $event_array = json_decode($response->getBody(), true);
+ $event_array['id'] = $eventId;
+
+ return EventSpot::create($event_array);
+ }
+
+ /**
+ * Get lists within an account
+ * @param string $accessToken Constant Contact OAuth2 access token
+ * @param string $eventId Unique ID of the event for which to retrieve the promocode
+ * @param array $params - associative array of query parameters and values to append to the request.
+ * Allowed parameters include:
+ * limit - Default: 50, up to 500
+ * @return EventSpot[]
+ * @throws CtctException
+ */
+ public function getRegistrants($accessToken, $eventId, Array $params = array())
+ {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf( Config::get('endpoints.event_registrants'), $eventId );
+
+ try {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ $body = json_decode($response->getBody(), true);
+ $registrants = array();
+ foreach ($body['results'] as $registrant) {
+ $registrants[] = Registrant::create($registrant);
+ }
+
+ return new ResultSet($registrants, $body['meta']);
+ }
+
+ /**
+ * Create a new Event
+ * @param string $accessToken Constant Contact OAuth2 access token
+ * @param string $eventId Unique ID of the event for which to retrieve the promocode
+ * @param string $registrantId ID of the registrant
+ * @return Registrant
+ * @throws CtctException
+ */
+ public function getRegistrant($accessToken, $eventId, $registrantId )
+ {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf( Config::get('endpoints.event_registrant'), $eventId, $registrantId );
+
+ try {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ return Registrant::create(json_decode($response->getBody(), true));
+ }
+
+ /**
+ * Create a new Event
+ * @param string $accessToken Constant Contact OAuth2 access token
+ * @param string $eventId Unique ID of the event for which to retrieve the promocode
+ * @param EventFee $eventFee EventFee object to create
+ * @return EventFee Created EventFee object
+ * @throws CtctException
+ */
+ public function addFee($accessToken, $eventId, $eventFee )
+ {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf( Config::get('endpoints.event_fees'), $eventId );
+
+ try {
+ $response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $eventFee);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ return EventFee::create(json_decode($response->getBody(), true));
+ }
+
+ /**
+ * Get fees for an event
+ * @param string $accessToken Constant Contact OAuth2 access token
+ * @param string $eventId Unique ID of the event for which to retrieve the promocode
+ * @return EventFee[]
+ * @throws CtctException
+ */
+ public function getFees($accessToken, $eventId )
+ {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf( Config::get('endpoints.event_fees'), $eventId );
+
+ try {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ $body = json_decode($response->getBody(), true);
+ $fees = array();
+ foreach ($body['results'] as $fee) {
+ $fees[] = EventFee::create($fee);
+ }
+
+ return $fees;
+ }
+
+ /**
+ * Get an individual Event fee
+ * @param string $accessToken Constant Contact OAuth2 access token
+ * @param string $eventId Unique ID of the event for which to retrieve the promocode
+ * @param string $feeId Unique ID of the fee to retrieve
+ * @return EventSpot
+ * @throws CtctException
+ */
+ public function getFee($accessToken, $eventId, $feeId)
+ {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.event_fee'), $eventId, $feeId);
+
+
+ try {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ return EventFee::create(json_decode($response->getBody(), true));
+ }
+
+ /**
+ * Create a new Promocode
+ * @param string $accessToken Constant Contact OAuth2 access token
+ * @param string $eventId Unique ID of the event for which to retrieve the promocode
+ * @param Promocode $promoCode Promocode object to add
+ * @return Promocode Created promocode object
+ * @throws CtctException
+ */
+ public function addPromocode($accessToken, $eventId, $promoCode )
+ {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf( Config::get('endpoints.event_promocodes'), $eventId );
+
+ try {
+ $response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $promoCode);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ return Promocode::create(json_decode($response->getBody(), true));
+ }
+
+ /**
+ * Get promocodes for an event
+ * @param string $accessToken Constant Contact OAuth2 access token
+ * @param string $eventId Unique ID of the event for which to retrieve the promocode
+ * @return Promocode[]
+ * @throws CtctException
+ */
+ public function getPromocodes($accessToken, $eventId )
+ {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf( Config::get('endpoints.event_promocodes'), $eventId );
+
+ try {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ $body = json_decode($response->getBody(), true);
+ $promocodes = array();
+ foreach ($body['results'] as $promocode) {
+ $promocodes[] = Promocode::create($promocode);
+ }
+
+ return $promocodes;
+ }
+
+ /**
+ * Get an individual Promocode fee
+ * @param string $accessToken Constant Contact OAuth2 access token
+ * @param string $eventId Unique ID of the event for which to retrieve the promocode
+ * @param string $promocodeId Unique ID of the promocode to retrieve
+ * @return Promocode
+ * @throws CtctException
+ */
+ public function getPromocode($accessToken, $eventId, $promocodeId)
+ {
+ $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.event_promocode'), $eventId, $promocodeId);
+
+
+ try {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ return Promocode::create(json_decode($response->getBody(), true));
+ }
+
+}
diff --git a/src/Ctct/Services/LibraryService.php b/src/Ctct/Services/LibraryService.php
index 719f635..0ca6a8c 100644
--- a/src/Ctct/Services/LibraryService.php
+++ b/src/Ctct/Services/LibraryService.php
@@ -1,20 +1,17 @@
getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$libraryFiles = array();
foreach ($body['results'] as $file) {
$libraryFiles[] = File::create($file);
@@ -71,25 +59,16 @@ public function getLibraryFiles($accessToken, Array $params = array())
* @return ResultSet
* @throws CtctException
*/
- public function getLibraryFilesByFolder($accessToken, $folderId, Array $params = array())
- {
+ public function getLibraryFilesByFolder($accessToken, $folderId, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.library_files_by_folder'), $folderId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$libraryFiles = array();
foreach ($body['results'] as $file) {
$libraryFiles[] = File::create($file);
@@ -105,19 +84,16 @@ public function getLibraryFilesByFolder($accessToken, $folderId, Array $params =
* @return File
* @throws CtctException
*/
- public function getLibraryFile($accessToken, $fileId)
- {
+ public function getLibraryFile($accessToken, $fileId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.library_file'), $fileId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return File::create($response->json());
+ return File::create(json_decode($response->getBody(), true));
}
/**
@@ -127,15 +103,12 @@ public function getLibraryFile($accessToken, $fileId)
* @return boolean
* @throws CtctException
*/
- public function deleteLibraryFile($accessToken, $fileId)
- {
+ public function deleteLibraryFile($accessToken, $fileId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.library_file'), $fileId);
- $request = parent::createBaseRequest($accessToken, 'DELETE', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'DELETE', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
@@ -153,25 +126,16 @@ public function deleteLibraryFile($accessToken, $fileId)
* @return ResultSet
* @throws CtctException
*/
- public function getLibraryFolders($accessToken, Array $params = array())
- {
+ public function getLibraryFolders($accessToken, Array $params = array()) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.library_folders');
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
- if ($params) {
- $query = $request->getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
$libraryFolders = array();
foreach ($body['results'] as $folder) {
$libraryFolders[] = Folder::create($folder);
@@ -187,19 +151,16 @@ public function getLibraryFolders($accessToken, Array $params = array())
* @return Folder
* @throws CtctException
*/
- public function getLibraryFolder($accessToken, $folderId)
- {
+ public function getLibraryFolder($accessToken, $folderId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.library_folder'), $folderId);
- $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- $body = $response->json();
+ $body = json_decode($response->getBody(), true);
return Folder::create($body);
}
@@ -210,15 +171,12 @@ public function getLibraryFolder($accessToken, $folderId)
* @return boolean
* @throws CtctException
*/
- public function deleteLibraryFolder($accessToken, $folderId)
- {
+ public function deleteLibraryFolder($accessToken, $folderId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.library_folder'), $folderId);
- $request = parent::createBaseRequest($accessToken, 'DELETE', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'DELETE', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
@@ -238,10 +196,9 @@ public function deleteLibraryFolder($accessToken, $folderId)
* @return string File upload status ID
* @throws CtctException
*/
- public function uploadFile($accessToken, $fileName, $fileLocation, $description, $source, $folderId)
- {
+ public function uploadFile($accessToken, $fileName, $fileLocation, $description, $source, $folderId) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
- $mime = finfo_file($finfo, $fileLocation);
+ $mime = finfo_file($finfo, $fileLocation);
finfo_close($finfo);
if ($mime == "image/png") {
$fileType = "PNG";
@@ -249,29 +206,32 @@ public function uploadFile($accessToken, $fileName, $fileLocation, $description,
$fileType = "JPG";
} elseif ($mime == "image/gif") {
$fileType = "GIF";
- } elseif ($mime =="application/pdf") {
+ } elseif ($mime == "application/pdf") {
$fileType = "PDF";
} else {
throw new IllegalArgumentException(sprintf(Config::get('errors.file_extension'), "PNG, JPG, JPEG, GIF, PDF was " . $mime));
}
-
+
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.library_files');
- $request = parent::createBaseRequest($accessToken, "POST", $baseUrl);
- $request->setHeader("Content-Type", "multipart/form-data");
-
- $body = new PostBody();
- $body->setField("folder_id", $folderId);
- $body->setField("file_name", $fileName);
- $body->setField("file_type", $fileType);
- $body->setField("description", $description);
- $body->setField("source", $source);
- $body->addFile(new PostFile("data", fopen($fileLocation, 'r'), $fileName));
- $request->setBody($body);
+ $request = new Request('POST', $baseUrl, [
+ parent::getHeadersForMultipart($accessToken)
+ ]);
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::getClient()->send($request, [
+ 'multipart' => [
+ [
+ 'folder_id' => $folderId,
+ 'file_name' => $fileName,
+ 'file_type' => $fileType,
+ 'description' => $description,
+ 'source' => $source,
+ 'data' => fopen($fileLocation, 'r')
+ ]
+ ]
+ ]);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
@@ -285,24 +245,19 @@ public function uploadFile($accessToken, $fileName, $fileLocation, $description,
* @return \Ctct\Components\Library\Folder - Newly created folder
* @throws CtctException
*/
- public function createLibraryFolder($accessToken, Folder $folder){
- $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.library_folders');
-
- $request = parent::createBaseRequest($accessToken, "POST", $baseUrl);
-
- $stream = Stream::factory(json_encode($folder));
- $request->setBody($stream);
-
- try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
- throw parent::convertException($e);
- }
-
- $body = $response->json();
- return Folder::create($body);
+ public function createLibraryFolder($accessToken, Folder $folder) {
+ $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.library_folders');
+
+ try {
+ $response = parent::sendRequestWithBody($accessToken, "POST", $baseUrl, $folder);
+ } catch (TransferException $e) {
+ throw parent::convertException($e);
+ }
+
+ $body = json_decode($response->getBody(), true);
+ return Folder::create($body);
}
-
+
/**
* Get the status of a File upload
* @param string $accessToken - Constant Contact OAuth2 token
@@ -310,19 +265,17 @@ public function createLibraryFolder($accessToken, Folder $folder){
* @return FileUploadStatus[] - Array of FileUploadStatus
* @throws CtctException
*/
- public function getFileUploadStatus($accessToken, $uploadStatusIds)
- {
+ 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) {
+ $response = parent::sendRequestWithoutBody($accessToken, "GET", $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
$fileUploadStatuses = array();
- foreach ($response->json() as $fileUploadStatus) {
+ foreach (json_decode($response->getBody(), true) as $fileUploadStatus) {
$fileUploadStatuses[] = FileUploadStatus::create($fileUploadStatus);
}
return $fileUploadStatuses;
diff --git a/src/Ctct/Services/ListService.php b/src/Ctct/Services/ListService.php
index ddab1af..b442f81 100755
--- a/src/Ctct/Services/ListService.php
+++ b/src/Ctct/Services/ListService.php
@@ -1,11 +1,10 @@
getQuery();
- foreach ($params as $name => $value) {
- $query->add($name, $value);
- }
- }
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl, $params);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
$lists = array();
- foreach ($response->json() as $contact) {
+ foreach (json_decode($response->getBody(), true) as $contact) {
$lists[] = ContactList::create($contact);
}
@@ -57,21 +46,16 @@ public function getLists($accessToken, Array $params = array())
* @return ContactList
* @throws CtctException
*/
- public function addList($accessToken, ContactList $list)
- {
+ public function addList($accessToken, ContactList $list) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.lists');
- $request = parent::createBaseRequest($accessToken, 'POST', $baseUrl);
- $stream = Stream::factory(json_encode($list));
- $request->setBody($stream);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $list);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return ContactList::create($response->json());
+ return ContactList::create(json_decode($response->getBody(), true));
}
/**
@@ -81,21 +65,16 @@ public function addList($accessToken, ContactList $list)
* @return ContactList
* @throws CtctException
*/
- public function updateList($accessToken, ContactList $list)
- {
+ public function updateList($accessToken, ContactList $list) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list'), $list->id);
- $request = parent::createBaseRequest($accessToken, 'PUT', $baseUrl);
- $stream = Stream::factory(json_encode($list));
- $request->setBody($stream);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, $list);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return ContactList::create($response->json());
+ return ContactList::create(json_decode($response->getBody(), true));
}
/**
@@ -105,15 +84,12 @@ public function updateList($accessToken, ContactList $list)
* @return ContactList
* @throws CtctException
*/
- public function deleteList($accessToken, $listId)
- {
+ public function deleteList($accessToken, $listId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list'), $listId);
- $request = parent::createBaseRequest($accessToken, 'DELETE', $baseUrl);
-
try {
- $response = parent::getClient()->send($request);
- } catch (ClientException $e) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'DELETE', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
@@ -127,18 +103,15 @@ public function deleteList($accessToken, $listId)
* @return ContactList
* @throws CtctException
*/
- public function getList($accessToken, $listId)
- {
+ 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) {
+ $response = parent::sendRequestWithoutBody($accessToken, 'GET', $baseUrl);
+ } catch (TransferException $e) {
throw parent::convertException($e);
}
- return ContactList::create($response->json());
+ return ContactList::create(json_decode($response->getBody(), true));
}
}
diff --git a/src/Ctct/SplClassLoader.php b/src/Ctct/SplClassLoader.php
index 0c811c8..419f0ac 100644
--- a/src/Ctct/SplClassLoader.php
+++ b/src/Ctct/SplClassLoader.php
@@ -19,8 +19,7 @@
* @author Fabien Potencier
*/
-class SplClassLoader
-{
+class SplClassLoader {
private $fileExtension = '.php';
private $namespace;
private $includePath;
@@ -33,40 +32,27 @@ class SplClassLoader
* @param string $ns The namespace to use.
* @param string $includePath The include path to use.
*/
- public function __construct($ns = null, $includePath = null)
- {
+ public function __construct($ns = null, $includePath = null) {
$this->namespace = $ns;
$this->includePath = $includePath;
}
- /**
- * Sets the namespace separator used by classes in the namespace of this class loader.
- *
- * @param string $sep The separator to use.
- */
- public function setNamespaceSeparator($sep)
- {
- $this->namespaceSeparator = $sep;
- }
-
/**
* Gets the namespace separator used by classes in the namespace of this class loader.
*
* @return string $namespaceSeparator
*/
- public function getNamespaceSeparator()
- {
+ public function getNamespaceSeparator() {
return $this->namespaceSeparator;
}
/**
- * Sets the base include path for all class files in the namespace of this class loader.
+ * Sets the namespace separator used by classes in the namespace of this class loader.
*
- * @param string $includePath
+ * @param string $sep The separator to use.
*/
- public function setIncludePath($includePath)
- {
- $this->includePath = $includePath;
+ public function setNamespaceSeparator($sep) {
+ $this->namespaceSeparator = $sep;
}
/**
@@ -74,19 +60,17 @@ public function setIncludePath($includePath)
*
* @return string $includePath
*/
- public function getIncludePath()
- {
+ public function getIncludePath() {
return $this->includePath;
}
/**
- * Sets the file extension of class files in the namespace of this class loader.
+ * Sets the base include path for all class files in the namespace of this class loader.
*
- * @param string $fileExtension
+ * @param string $includePath
*/
- public function setFileExtension($fileExtension)
- {
- $this->fileExtension = $fileExtension;
+ public function setIncludePath($includePath) {
+ $this->includePath = $includePath;
}
/**
@@ -94,24 +78,30 @@ public function setFileExtension($fileExtension)
*
* @return string $fileExtension
*/
- public function getFileExtension()
- {
+ public function getFileExtension() {
return $this->fileExtension;
}
+ /**
+ * Sets the file extension of class files in the namespace of this class loader.
+ *
+ * @param string $fileExtension
+ */
+ public function setFileExtension($fileExtension) {
+ $this->fileExtension = $fileExtension;
+ }
+
/**
* Installs this class loader on the SPL autoload stack.
*/
- public function register()
- {
+ public function register() {
spl_autoload_register(array($this, 'loadClass'));
}
/**
* Uninstalls this class loader from the SPL autoloader stack.
*/
- public function unregister()
- {
+ public function unregister() {
spl_autoload_unregister(array($this, 'loadClass'));
}
@@ -121,8 +111,7 @@ public function unregister()
* @param string $className The name of the class to load.
* @return void
*/
- public function loadClass($className)
- {
+ public function loadClass($className) {
if (null === $this->namespace || $this->namespace . $this->namespaceSeparator ===
substr($className, 0, strlen($this->namespace . $this->namespaceSeparator))
) {
diff --git a/src/Ctct/Util/Config.php b/src/Ctct/Util/Config.php
index 1776c13..a989f1c 100755
--- a/src/Ctct/Util/Config.php
+++ b/src/Ctct/Util/Config.php
@@ -7,8 +7,7 @@
* @package Util
* @author Constant Contact
*/
-class Config
-{
+class Config {
/**
* @var array - array of configuration properties
*/
@@ -55,6 +54,18 @@ class Config
'contact_tracking_sends' => 'contacts/%s/tracking/sends',
'contact_tracking_unsubscribes' => 'contacts/%s/tracking/unsubscribes',
'contact_tracking_link' => 'contacts/%s/tracking/clicks/%s',
+ 'events' => 'eventspot/events',
+ 'event' => 'eventspot/events/%s',
+ 'event_fees' => 'eventspot/events/%s/fees',
+ 'event_fee' => 'eventspot/events/%s/fees/%s',
+ 'event_registrants' => 'eventspot/events/%s/registrants',
+ 'event_registrant' => 'eventspot/events/%s/registrants/%s',
+ 'event_promocodes' => 'eventspot/events/%s/promocodes',
+ 'event_promocode' => 'eventspot/events/%s/promocodes/%s',
+ 'event_items' => 'eventspot/events/%s/items',
+ 'event_item' => 'eventspot/events/%s/items/%s',
+ 'event_item_attributes' => 'eventspot/events/%s/items/%s/attributes',
+ 'event_item_attribute' => 'eventspot/events/%s/items/%s/attributes/%s',
'library_files' => 'library/files',
'library_file' => 'library/files/%s',
'library_folders' => 'library/folders',
@@ -116,16 +127,16 @@ class Config
/**
* Errors to be returned for various exceptions
*/
- 'errors' => array(
- 'id_or_object' => 'Only an id or %s object are allowed for this method.',
- 'file_extension' => 'Only file extensions of the following are allowed: %s'
+ 'errors' => array(
+ 'id_or_object' => 'Only an id or %s object are allowed for this method.',
+ 'file_extension' => 'Only file extensions of the following are allowed: %s'
),
-
+
/**
* Setting the version fo the application used in Rest Calls when setting the version header
*/
- 'settings' => array(
- 'version' => '2.1.3'
+ 'settings' => array(
+ 'version' => '3.x.x'
),
);
@@ -134,8 +145,7 @@ class Config
* @param $index - location of the property to obtain
* @return string
*/
- public static function get($index)
- {
+ public static function get($index) {
$index = explode('.', $index);
return self::getValue($index, self::$props);
}
@@ -146,8 +156,7 @@ public static function get($index)
* @param array $value The portion of the config array to process
* @return mixed
*/
- private static function getValue($index, $value)
- {
+ private static function getValue($index, $value) {
if (is_array($index) && count($index)) {
$current_index = array_shift($index);
}
diff --git a/src/Ctct/WebHooks/CTCTWebhookUtil.php b/src/Ctct/WebHooks/CTCTWebhookUtil.php
index b17a363..5405c89 100644
--- a/src/Ctct/WebHooks/CTCTWebhookUtil.php
+++ b/src/Ctct/WebHooks/CTCTWebhookUtil.php
@@ -10,54 +10,26 @@
* @package WebHooks
* @author Constant Contact
*/
-class CTCTWebhookUtil
-{
-
+class CTCTWebhookUtil {
/**
* The client secret associated with the api key
*/
private $clientSecret = '';
-
/**
* Constructor that creates a validation Object for WebHooks.
- *
+ *
* @param string $clientSecret - The client secret associated with the api key
* @return CTCTWebhookUtil
*/
- function __construct($clientSecret='')
- {
+ function __construct($clientSecret = '') {
$this->setClientSecret($clientSecret);
}
-
- /**
- * CTCTWebhookUtil::getClientSecret()
- *
- * @return string - the secret API key
- */
- public function getClientSecret()
- {
- return $this->clientSecret;
- }
-
-
- /**
- * CTCTWebhookUtil::setClientSecret()
- * Set the clientSecret
- *
- * @param string $clientSecret - The client secret associated with the api key
- * @return void
- */
- public function setClientSecret($clientSecret)
- {
- $this->clientSecret = $clientSecret;
- }
-
/**
* Get Billing Change Notification.
*
- * Validates and parses the bodyMessage into
+ * Validates and parses the bodyMessage into
*
* @param xCtctHmacSHA256 The value in the x-ctct-hmac-sha256 header.
* @param bodyMessage The body message from the POST received from ConstantContact in Webhook callback.
@@ -69,13 +41,10 @@ public function setClientSecret($clientSecret)
*
*
*/
- public function getBillingChangeNotification($xCtctHmacSHA256, $bodyMessage)
- {
- if ($this->isValidWebhook($xCtctHmacSHA256, $bodyMessage))
- {
- return json_decode($bodyMessage);
- } else
- {
+ public function getBillingChangeNotification($xCtctHmacSHA256, $bodyMessage) {
+ if ($this->isValidWebhook($xCtctHmacSHA256, $bodyMessage)) {
+ return json_decode($bodyMessage);
+ } else {
throw new CtctException("Invalid WebHook");
}
}
@@ -83,19 +52,40 @@ public function getBillingChangeNotification($xCtctHmacSHA256, $bodyMessage)
/**
* Check if a Webhook message is valid or not.
*
- * @param xCtctHmacSHA256 The value in the x-ctct-hmac-sha256 header.
- * @param bodyMessage The body message from the POST received from ConstantContact in Webhook callback.
+ * @param $xCtctHmacSHA256
+ * @param $bodyMessage
* @return true if in case of success; false if the Webhook is invalid.
- *
+ *
+ * @throws CtctException
+ * @internal param The $xCtctHmacSHA256 value in the x-ctct-hmac-sha256 header.
+ * @internal param The $bodyMessage body message from the POST received from ConstantContact in Webhook callback.
*/
- public function isValidWebhook($xCtctHmacSHA256, $bodyMessage)
- {
- if ($this->getClientSecret() == null)
- {
+ public function isValidWebhook($xCtctHmacSHA256, $bodyMessage) {
+ if ($this->getClientSecret() == null) {
throw new CtctException("NO_CLIENT_SECRET");
}
$encodedString = hash_hmac("sha256", $bodyMessage, $this->clientSecret);
-
- return ($encodedString == $xCtctHmacSHA256)?true:false;
+
+ return ($encodedString == $xCtctHmacSHA256) ? true : false;
+ }
+
+ /**
+ * CTCTWebhookUtil::getClientSecret()
+ *
+ * @return string - the secret API key
+ */
+ public function getClientSecret() {
+ return $this->clientSecret;
+ }
+
+ /**
+ * CTCTWebhookUtil::setClientSecret()
+ * Set the clientSecret
+ *
+ * @param string $clientSecret - The client secret associated with the api key
+ * @return void
+ */
+ public function setClientSecret($clientSecret) {
+ $this->clientSecret = $clientSecret;
}
}
diff --git a/standalone/vendor.zip b/standalone/vendor.zip
new file mode 100644
index 0000000..a2926ef
Binary files /dev/null and b/standalone/vendor.zip differ
diff --git a/test/Auth/CtctOAuth2UnitTest.php b/test/Auth/CtctOAuth2UnitTest.php
index 70d9c82..504ee46 100644
--- a/test/Auth/CtctOAuth2UnitTest.php
+++ b/test/Auth/CtctOAuth2UnitTest.php
@@ -3,12 +3,11 @@
use Ctct\Auth\CtctOAuth2;
use Ctct\Util\Config;
use GuzzleHttp\Client;
-use GuzzleHttp\Message\Response;
-use GuzzleHttp\Stream\Stream;
-use GuzzleHttp\Subscriber\Mock;
+use GuzzleHttp\Handler\MockHandler;
+use GuzzleHttp\HandlerStack;
+use GuzzleHttp\Psr7\Response;
-class CtctOAuth2UnitTest extends PHPUnit_Framework_TestCase
-{
+class CtctOAuth2UnitTest extends PHPUnit_Framework_TestCase {
/**
* @var Client
*/
@@ -23,39 +22,33 @@ class CtctOAuth2UnitTest extends PHPUnit_Framework_TestCase
private $clientSecret = "clientSecret";
private $redirectUri = "redirectUri";
- public static function setUpBeforeClass()
- {
- self::$client = new Client();
- $tokenInfoStream = Stream::factory(JsonLoader::getTokenInfoJson());
- $accessTokenStream = Stream::factory(JsonLoader::getAccessTokenJson());
- $mock = new Mock([
- new Response(200, array(), $tokenInfoStream),
- new Response(200, array(), $accessTokenStream)
+ public static function setUpBeforeClass() {
+ $mock = new MockHandler([
+ new Response(200, array(), JsonLoader::getTokenInfoJson()),
+ new Response(200, array(), JsonLoader::getAccessTokenJson())
]);
- self::$client->getEmitter()->attach($mock);
+ $handler = HandlerStack::create($mock);
+ self::$client = new Client(['handler' => $handler]);
}
- public function setUp()
- {
+ public function setUp() {
$this->ctctOAuth2 = new CtctOAuth2($this->apiKey, $this->clientSecret, $this->redirectUri);
}
- public function testGetTokenInfo()
- {
+ public function testGetTokenInfo() {
$response = self::$client->post('/');
- $token = $response->json();
+ $token = json_decode($response->getBody(), true);
$this->assertEquals("f98b207c-ta99b-4938-b523-3cc2895f5420", $token['client_id']);
$this->assertEquals("ctcttest", $token['user_name']);
$this->assertEquals("315110295", $token['expires_in']);
}
- public function testGetAccessToken()
- {
+ public function testGetAccessToken() {
$response = self::$client->post('/');
- $token = $response->json();
+ $token = json_decode($response->getBody(), true);
$this->assertEquals("v6574b42-a5bc-4574-a87f-5c9d1202e316", $token['access_token']);
$this->assertEquals("308874923", $token['expires_in']);
@@ -65,13 +58,11 @@ public function testGetAccessToken()
/**
* @dataProvider authorizationUrlProvider
*/
- public function testGetAuthorizationUrl($server, $expectedResponse)
- {
+ public function testGetAuthorizationUrl($server, $expectedResponse) {
$this->assertEquals($expectedResponse, $this->ctctOAuth2->getAuthorizationUrl($server));
}
- public function testGetAuthorizationUrlServer()
- {
+ public function testGetAuthorizationUrlServer() {
$authUrl = $this->ctctOAuth2->getAuthorizationUrl();
$baseUrl = Config::get('auth.base_url') . Config::get('auth.authorization_endpoint');
$params = array(
@@ -83,8 +74,7 @@ public function testGetAuthorizationUrlServer()
$this->assertEquals($expectedUrl, $authUrl);
}
- public function testGetAuthorizationUrlClient()
- {
+ public function testGetAuthorizationUrlClient() {
$authUrl = $this->ctctOAuth2->getAuthorizationUrl(false);
$baseUrl = Config::get('auth.base_url') . Config::get('auth.authorization_endpoint');
$params = array(
@@ -96,8 +86,7 @@ public function testGetAuthorizationUrlClient()
$this->assertEquals($expectedUrl, $authUrl);
}
- public function testGetAuthorizationUrlServerWithState()
- {
+ public function testGetAuthorizationUrlServerWithState() {
$state = 'this is my state';
$authUrl = $this->ctctOAuth2->getAuthorizationUrl(true, $state);
$baseUrl = Config::get('auth.base_url') . Config::get('auth.authorization_endpoint');
@@ -111,8 +100,7 @@ public function testGetAuthorizationUrlServerWithState()
$this->assertEquals($expectedUrl, $authUrl);
}
- public function testGetAuthorizationUrlClientWithState()
- {
+ public function testGetAuthorizationUrlClientWithState() {
$state = 'this is my state';
$authUrl = $this->ctctOAuth2->getAuthorizationUrl(false, $state);
$baseUrl = Config::get('auth.base_url') . Config::get('auth.authorization_endpoint');
@@ -126,8 +114,7 @@ public function testGetAuthorizationUrlClientWithState()
$this->assertEquals($expectedUrl, $authUrl);
}
- public function authorizationUrlProvider()
- {
+ public function authorizationUrlProvider() {
$requestParams = "&client_id=apiKey&redirect_uri=redirectUri";
$serverParams = "?response_type=" . Config::get('auth.response_type_code') . $requestParams;
$clientParams = "?response_type=" . Config::get('auth.response_type_token') . $requestParams;
diff --git a/test/Json/Account/get_account_info.json b/test/Json/Account/get_account_info.json
index 4aa3805..847f693 100644
--- a/test/Json/Account/get_account_info.json
+++ b/test/Json/Account/get_account_info.json
@@ -1,21 +1,21 @@
{
- "website":"http://www.example.com",
- "organization_name":"My Company",
- "time_zone":"US/Eastern",
- "first_name":"Mary Jane",
- "last_name":"Doe",
- "email":"mjdoe@example.com",
- "phone":"5555555555",
- "company_logo":"https://ih.constantcontact.com/fs137/1100371573368/img/90.jpg",
- "country_code":"US",
- "state_code":"MA",
- "organization_addresses":[
+ "website": "http://www.example.com",
+ "organization_name": "My Company",
+ "time_zone": "US/Eastern",
+ "first_name": "Mary Jane",
+ "last_name": "Doe",
+ "email": "mjdoe@example.com",
+ "phone": "5555555555",
+ "company_logo": "https://ih.constantcontact.com/fs137/1100371573368/img/90.jpg",
+ "country_code": "US",
+ "state_code": "MA",
+ "organization_addresses": [
{
"city": "Anytown",
- "line1":"123 Maple Street",
- "postal_code":"11111",
- "country_code":"US",
- "state_code":"MA"
+ "line1": "123 Maple Street",
+ "postal_code": "11111",
+ "country_code": "US",
+ "state_code": "MA"
}
]
}
\ No newline at end of file
diff --git a/test/Json/Account/get_verified_email_addresses.json b/test/Json/Account/get_verified_email_addresses.json
index 876f27d..f1ea352 100644
--- a/test/Json/Account/get_verified_email_addresses.json
+++ b/test/Json/Account/get_verified_email_addresses.json
@@ -1,6 +1,6 @@
[
- {
- "email_address": "test123@roving.com",
- "status": "CONFIRMED"
- }
+ {
+ "email_address": "test123@roving.com",
+ "status": "CONFIRMED"
+ }
]
\ No newline at end of file
diff --git a/test/Json/Activities/get_activities.json b/test/Json/Activities/get_activities.json
index 4be113c..6c9eeb6 100644
--- a/test/Json/Activities/get_activities.json
+++ b/test/Json/Activities/get_activities.json
@@ -1,52 +1,52 @@
[
- {
- "id": "a07e1ikxwuphd4nwjxl",
- "type": "EXPORT_CONTACTS",
- "status": "COMPLETE",
- "start_date": "2013-02-13T15:57:03.627Z",
- "finish_date": "2013-02-13T15:57:03.649Z",
- "created_date": "2013-02-13T15:56:14.697Z",
- "error_count": 0,
- "contact_count": 0
- },
- {
- "id": "a07e1ikxwuohd4ni3no",
- "type": "EXPORT_CONTACTS",
- "status": "COMPLETE",
- "start_date": "2013-02-13T15:45:02.959Z",
- "finish_date": "2013-02-13T15:45:03.146Z",
- "created_date": "2013-02-13T15:45:00.420Z",
- "error_count": 0,
- "contact_count": 0
- },
- {
- "id": "a07e1ikxyomhd4la0o9",
- "type": "REMOVE_CONTACTS_FROM_LISTS",
- "status": "COMPLETE",
- "start_date": "2013-02-13T14:43:01.635Z",
- "finish_date": "2013-02-13T14:43:01.662Z",
- "created_date": "2013-02-13T14:42:44.073Z",
- "error_count": 2,
- "contact_count": 2
- },
- {
- "id": "a07e1ikxwujhd4j5dpm",
- "type": "CLEAR_CONTACTS_FROM_LISTS",
- "status": "COMPLETE",
- "start_date": "2013-02-13T13:44:01.186Z",
- "finish_date": "2013-02-13T13:44:03.330Z",
- "created_date": "2013-02-13T13:43:08.458Z",
- "error_count": 0,
- "contact_count": 352
- },
- {
- "id": "a07e1ikqlv6hcxbe11w",
- "type": "REMOVE_CONTACTS_FROM_LISTS",
- "status": "COMPLETE",
- "start_date": "2013-02-08T12:31:56.472Z",
- "finish_date": "2013-02-08T12:31:56.525Z",
- "created_date": "2013-02-08T12:31:31.796Z",
- "error_count": 2,
- "contact_count": 2
- }
+ {
+ "id": "a07e1ikxwuphd4nwjxl",
+ "type": "EXPORT_CONTACTS",
+ "status": "COMPLETE",
+ "start_date": "2013-02-13T15:57:03.627Z",
+ "finish_date": "2013-02-13T15:57:03.649Z",
+ "created_date": "2013-02-13T15:56:14.697Z",
+ "error_count": 0,
+ "contact_count": 0
+ },
+ {
+ "id": "a07e1ikxwuohd4ni3no",
+ "type": "EXPORT_CONTACTS",
+ "status": "COMPLETE",
+ "start_date": "2013-02-13T15:45:02.959Z",
+ "finish_date": "2013-02-13T15:45:03.146Z",
+ "created_date": "2013-02-13T15:45:00.420Z",
+ "error_count": 0,
+ "contact_count": 0
+ },
+ {
+ "id": "a07e1ikxyomhd4la0o9",
+ "type": "REMOVE_CONTACTS_FROM_LISTS",
+ "status": "COMPLETE",
+ "start_date": "2013-02-13T14:43:01.635Z",
+ "finish_date": "2013-02-13T14:43:01.662Z",
+ "created_date": "2013-02-13T14:42:44.073Z",
+ "error_count": 2,
+ "contact_count": 2
+ },
+ {
+ "id": "a07e1ikxwujhd4j5dpm",
+ "type": "CLEAR_CONTACTS_FROM_LISTS",
+ "status": "COMPLETE",
+ "start_date": "2013-02-13T13:44:01.186Z",
+ "finish_date": "2013-02-13T13:44:03.330Z",
+ "created_date": "2013-02-13T13:43:08.458Z",
+ "error_count": 0,
+ "contact_count": 352
+ },
+ {
+ "id": "a07e1ikqlv6hcxbe11w",
+ "type": "REMOVE_CONTACTS_FROM_LISTS",
+ "status": "COMPLETE",
+ "start_date": "2013-02-08T12:31:56.472Z",
+ "finish_date": "2013-02-08T12:31:56.525Z",
+ "created_date": "2013-02-08T12:31:31.796Z",
+ "error_count": 2,
+ "contact_count": 2
+ }
]
\ No newline at end of file
diff --git a/test/Json/Activities/get_activity.json b/test/Json/Activities/get_activity.json
index 20c9168..7570046 100644
--- a/test/Json/Activities/get_activity.json
+++ b/test/Json/Activities/get_activity.json
@@ -1,24 +1,24 @@
{
- "id": "a07e1ikxyomhd4la0o9",
- "type": "REMOVE_CONTACTS_FROM_LISTS",
- "status": "COMPLETE",
- "errors": [
- {
- "message": "test@roving.com (not found in subscriber list)",
- "line_number": 0,
- "email_address": ""
- },
- {
- "message": "test1@roving.com (not found in subscriber list)",
- "line_number": 0,
- "email_address": ""
- }
- ],
- "warnings": [],
- "file_name": "",
- "start_date": "2013-02-13T14:43:01.635Z",
- "finish_date": "2013-02-13T14:43:01.662Z",
- "created_date": "2013-02-13T14:42:44.073Z",
- "error_count": 2,
- "contact_count": 2
+ "id": "a07e1ikxyomhd4la0o9",
+ "type": "REMOVE_CONTACTS_FROM_LISTS",
+ "status": "COMPLETE",
+ "errors": [
+ {
+ "message": "test@roving.com (not found in subscriber list)",
+ "line_number": 0,
+ "email_address": ""
+ },
+ {
+ "message": "test1@roving.com (not found in subscriber list)",
+ "line_number": 0,
+ "email_address": ""
+ }
+ ],
+ "warnings": [],
+ "file_name": "",
+ "start_date": "2013-02-13T14:43:01.635Z",
+ "finish_date": "2013-02-13T14:43:01.662Z",
+ "created_date": "2013-02-13T14:42:44.073Z",
+ "error_count": 2,
+ "contact_count": 2
}
\ No newline at end of file
diff --git a/test/Json/Activities/post_add_contacts.json b/test/Json/Activities/post_add_contacts.json
index 4cf422f..7b80e90 100644
--- a/test/Json/Activities/post_add_contacts.json
+++ b/test/Json/Activities/post_add_contacts.json
@@ -1,6 +1,6 @@
{
- "id": "a07e1il69qzhdby44ro",
- "type": "ADD_CONTACTS",
- "error_count": 0,
- "contact_count": 1
+ "id": "a07e1il69qzhdby44ro",
+ "type": "ADD_CONTACTS",
+ "error_count": 0,
+ "contact_count": 1
}
\ No newline at end of file
diff --git a/test/Json/Activities/post_clear_lists.json b/test/Json/Activities/post_clear_lists.json
index fa26f76..a9c17db 100644
--- a/test/Json/Activities/post_clear_lists.json
+++ b/test/Json/Activities/post_clear_lists.json
@@ -1,6 +1,6 @@
{
- "id": "a07e1il69fwhd7uan9h",
- "type": "CLEAR_CONTACTS_FROM_LISTS",
- "error_count": 0,
- "contact_count": 0
+ "id": "a07e1il69fwhd7uan9h",
+ "type": "CLEAR_CONTACTS_FROM_LISTS",
+ "error_count": 0,
+ "contact_count": 0
}
\ No newline at end of file
diff --git a/test/Json/Activities/post_export_contacts.json b/test/Json/Activities/post_export_contacts.json
index 0a1e9c3..121461a 100644
--- a/test/Json/Activities/post_export_contacts.json
+++ b/test/Json/Activities/post_export_contacts.json
@@ -1,6 +1,6 @@
{
- "id": "a07e1i5nqamhcfeuu0h",
- "type": "EXPORT_CONTACTS",
- "error_count": 0,
- "contacts_count": 0
+ "id": "a07e1i5nqamhcfeuu0h",
+ "type": "EXPORT_CONTACTS",
+ "error_count": 0,
+ "contacts_count": 0
}
\ No newline at end of file
diff --git a/test/Json/Activities/post_remove_contacts_from_lists.json b/test/Json/Activities/post_remove_contacts_from_lists.json
index acebde1..e3b6eae 100644
--- a/test/Json/Activities/post_remove_contacts_from_lists.json
+++ b/test/Json/Activities/post_remove_contacts_from_lists.json
@@ -1,6 +1,6 @@
{
- "id": "a07e1i5nqamhcfeuu0h",
- "type": "REMOVE_CONTACTS_FROM_LISTS",
- "error_count": 0,
- "contacts_count": 0
+ "id": "a07e1i5nqamhcfeuu0h",
+ "type": "REMOVE_CONTACTS_FROM_LISTS",
+ "error_count": 0,
+ "contacts_count": 0
}
\ No newline at end of file
diff --git a/test/Json/Auth/get_access_token.json b/test/Json/Auth/get_access_token.json
index c80bc18..64be2f9 100644
--- a/test/Json/Auth/get_access_token.json
+++ b/test/Json/Auth/get_access_token.json
@@ -1,5 +1,5 @@
{
- "access_token": "v6574b42-a5bc-4574-a87f-5c9d1202e316",
- "expires_in": "308874923",
- "token_type": "Bearer"
+ "access_token": "v6574b42-a5bc-4574-a87f-5c9d1202e316",
+ "expires_in": "308874923",
+ "token_type": "Bearer"
}
\ No newline at end of file
diff --git a/test/Json/Auth/token_info.json b/test/Json/Auth/token_info.json
index 4d0a0de..85ccc18 100644
--- a/test/Json/Auth/token_info.json
+++ b/test/Json/Auth/token_info.json
@@ -1,5 +1,5 @@
{
- "client_id": "f98b207c-ta99b-4938-b523-3cc2895f5420",
- "user_name": "ctcttest",
- "expires_in": "315110295"
+ "client_id": "f98b207c-ta99b-4938-b523-3cc2895f5420",
+ "user_name": "ctcttest",
+ "expires_in": "315110295"
}
\ No newline at end of file
diff --git a/test/Json/Campaigns/get_campaign.json b/test/Json/Campaigns/get_campaign.json
index c521287..e638e94 100755
--- a/test/Json/Campaigns/get_campaign.json
+++ b/test/Json/Campaigns/get_campaign.json
@@ -1,63 +1,63 @@
{
- "id": "1100394165290",
- "name": "CampaignName-05965ddb-12d2-43e5-b8f3-0c22ca487c3a",
- "subject": "CampaignSubject",
- "status": "SENT",
- "from_name": "From WSPI",
- "from_email": "wiz-20121206130519@l1.snoopy.roving.com",
- "reply_to_email": "wiz-20121206130519@l1.snoopy.roving.com",
- "template_type": "CUSTOM",
- "created_date": "2012-12-06T18:06:05.255Z",
- "last_edit_date": "2012-12-06T18:06:05.255Z",
- "last_run_date": "2012-12-06T18:06:40.342Z",
- "is_permission_reminder_enabled": false,
- "permission_reminder_text": "",
- "permalink_url": "http://www.constantcontact.com",
- "is_view_as_webpage_enabled": false,
- "view_as_web_page_text": "Having trouble viewing this email?",
- "view_as_web_page_link_text": "Click Here",
- "greeting_salutations": "Hi",
- "greeting_name": "FIRST_NAME",
- "greeting_string": "",
- "email_content": "Hi Visit ConstantContact.com! ",
- "text_content": "Something to test",
- "email_content_format": "HTML",
- "style_sheet": "",
- "message_footer": {
- "city": "Waltham",
- "state": "MA",
- "country": "US",
- "organization_name": "WSPIOrgName",
- "address_line_1": "1601 Trapelo RD",
- "address_line_2": "suite 2",
- "address_line_3": "box 4",
- "international_state": "",
- "postal_code": "02451",
- "include_forward_email": true,
- "forward_email_link_text": "WSPIForwardThisEmail",
- "include_subscribe_link": true,
- "subscribe_link_text": "WSPISubscribeLinkText"
- },
- "tracking_summary": {
- "sends": 15,
- "opens": 10,
- "clicks": 10,
- "forwards": 3,
- "unsubscribes": 2,
- "bounces": 18,
- "spam_count": 1
- },
- "is_visible_in_ui": false,
- "sent_to_contact_lists": [
- {
- "id": 3
- }
- ],
- "click_through_details": [
- {
- "url": "http://www.constantcontact.com",
- "url_uid": "1100394163874",
- "click_count": 10
- }
- ]
+ "id": "1100394165290",
+ "name": "CampaignName-05965ddb-12d2-43e5-b8f3-0c22ca487c3a",
+ "subject": "CampaignSubject",
+ "status": "SENT",
+ "from_name": "From WSPI",
+ "from_email": "wiz-20121206130519@l1.snoopy.roving.com",
+ "reply_to_email": "wiz-20121206130519@l1.snoopy.roving.com",
+ "template_type": "CUSTOM",
+ "created_date": "2012-12-06T18:06:05.255Z",
+ "last_edit_date": "2012-12-06T18:06:05.255Z",
+ "last_run_date": "2012-12-06T18:06:40.342Z",
+ "is_permission_reminder_enabled": false,
+ "permission_reminder_text": "",
+ "permalink_url": "http://www.constantcontact.com",
+ "is_view_as_webpage_enabled": false,
+ "view_as_web_page_text": "Having trouble viewing this email?",
+ "view_as_web_page_link_text": "Click Here",
+ "greeting_salutations": "Hi",
+ "greeting_name": "FIRST_NAME",
+ "greeting_string": "",
+ "email_content": "Hi Visit ConstantContact.com! ",
+ "text_content": "Something to test",
+ "email_content_format": "HTML",
+ "style_sheet": "",
+ "message_footer": {
+ "city": "Waltham",
+ "state": "MA",
+ "country": "US",
+ "organization_name": "WSPIOrgName",
+ "address_line_1": "1601 Trapelo RD",
+ "address_line_2": "suite 2",
+ "address_line_3": "box 4",
+ "international_state": "",
+ "postal_code": "02451",
+ "include_forward_email": true,
+ "forward_email_link_text": "WSPIForwardThisEmail",
+ "include_subscribe_link": true,
+ "subscribe_link_text": "WSPISubscribeLinkText"
+ },
+ "tracking_summary": {
+ "sends": 15,
+ "opens": 10,
+ "clicks": 10,
+ "forwards": 3,
+ "unsubscribes": 2,
+ "bounces": 18,
+ "spam_count": 1
+ },
+ "is_visible_in_ui": false,
+ "sent_to_contact_lists": [
+ {
+ "id": 3
+ }
+ ],
+ "click_through_details": [
+ {
+ "url": "http://www.constantcontact.com",
+ "url_uid": "1100394163874",
+ "click_count": 10
+ }
+ ]
}
\ No newline at end of file
diff --git a/test/Json/Campaigns/get_campaigns.json b/test/Json/Campaigns/get_campaigns.json
index ef8a630..be1d6a8 100755
--- a/test/Json/Campaigns/get_campaigns.json
+++ b/test/Json/Campaigns/get_campaigns.json
@@ -1,57 +1,57 @@
{
- "meta": {
- "pagination": {
- "next_link": "/v2/emailcampaigns?next=cGFnZU51bT0yJnBhZ2VTaXplPTM"
- }
+ "meta": {
+ "pagination": {
+ "next_link": "/v2/emailcampaigns?next=cGFnZU51bT0yJnBhZ2VTaXplPTM"
+ }
+ },
+ "results": [
+ {
+ "id": "1100371240640",
+ "name": "Email Created 2012/11/29, 4:13 PM",
+ "status": "SENT",
+ "modified_date": "2012-11-29T16:15:17.468Z"
},
- "results": [
- {
- "id": "1100371240640",
- "name": "Email Created 2012/11/29, 4:13 PM",
- "status": "SENT",
- "modified_date": "2012-11-29T16:15:17.468Z"
- },
- {
- "id": "1100368835463",
- "name": "CampaignNdddasdsdme2",
- "status": "DRAFT",
- "modified_date": "2012-10-16T16:14:34.221Z"
- },
- {
- "id": "1100368834956",
- "name": "CampaignNasdsdme2",
- "status": "DRAFT",
- "modified_date": "2012-10-16T15:44:45.341Z"
- },
- {
- "id": "1100368605465",
- "name": "CampaignName2dddfdf",
- "status": "DRAFT",
- "modified_date": "2012-10-10T12:34:33.702Z"
- },
- {
- "id": "1100368605462",
- "name": "CampaignName2dfdf",
- "status": "DRAFT",
- "modified_date": "2012-10-10T12:33:39.402Z"
- },
- {
- "id": "1100367933663",
- "name": "CampaignName-cfd9b733-a4a3-40b0-ab92-8ad66d954c7f",
- "status": "DRAFT",
- "modified_date": "2012-09-25T18:29:43.259Z"
- },
- {
- "id": "1100367567199",
- "name": "u8cf32jeirb2",
- "status": "DRAFT",
- "modified_date": "2012-09-19T14:03:06.774Z"
- },
- {
- "id": "1100367567187",
- "name": "6qgk3d0opqgb",
- "status": "DRAFT",
- "modified_date": "2012-09-19T13:54:15.316Z"
- }
- ]
+ {
+ "id": "1100368835463",
+ "name": "CampaignNdddasdsdme2",
+ "status": "DRAFT",
+ "modified_date": "2012-10-16T16:14:34.221Z"
+ },
+ {
+ "id": "1100368834956",
+ "name": "CampaignNasdsdme2",
+ "status": "DRAFT",
+ "modified_date": "2012-10-16T15:44:45.341Z"
+ },
+ {
+ "id": "1100368605465",
+ "name": "CampaignName2dddfdf",
+ "status": "DRAFT",
+ "modified_date": "2012-10-10T12:34:33.702Z"
+ },
+ {
+ "id": "1100368605462",
+ "name": "CampaignName2dfdf",
+ "status": "DRAFT",
+ "modified_date": "2012-10-10T12:33:39.402Z"
+ },
+ {
+ "id": "1100367933663",
+ "name": "CampaignName-cfd9b733-a4a3-40b0-ab92-8ad66d954c7f",
+ "status": "DRAFT",
+ "modified_date": "2012-09-25T18:29:43.259Z"
+ },
+ {
+ "id": "1100367567199",
+ "name": "u8cf32jeirb2",
+ "status": "DRAFT",
+ "modified_date": "2012-09-19T14:03:06.774Z"
+ },
+ {
+ "id": "1100367567187",
+ "name": "6qgk3d0opqgb",
+ "status": "DRAFT",
+ "modified_date": "2012-09-19T13:54:15.316Z"
+ }
+ ]
}
\ No newline at end of file
diff --git a/test/Json/Campaigns/get_preview.json b/test/Json/Campaigns/get_preview.json
index 45b6ff6..65b5e58 100644
--- a/test/Json/Campaigns/get_preview.json
+++ b/test/Json/Campaigns/get_preview.json
@@ -1,7 +1,7 @@
{
- "subject":"Subject Test",
- "from_email":"myemail@example.com",
- "reply_to_email":"myemail@example.com",
- "preview_email_content":"As a reminder, you're receiving this email because you have expressed an interest in MyCompany. Don't forget to add from_email@example.com to your address book so we'll be sure to land in your inbox! You may unsubscribe if you no longer wish to receive our emails. You may unsubscribe if you no longer wish to receive our emails. |
![]()
This is text of the email message.
\n\n
\n</body>",
- "preview_text_content":"View this message as a web page\nClick here\nhttp://campaign.r20.l1.constantcontact.com/render?ca=025eff86-6378-4f53-9301-5897ecf50b30&c={Contact Id}&ch={Contact Id}\n\nAs a reminder, you're receiving this email because you have expressed an interest in MyCompany. Don't forget to add from_email@example.com to your address book so we'll be sure to land in your inbox! You may unsubscribe if you no longer wish to receive our emails. You may unsubscribe\nhttp://visitor.l1.constantcontact.com/do?p=un&m=001JZtDyxcvPiye1EthMqSLGA%3D%3D&ch={Contact Id}&ca=025eff86-6378-4f53-9301-5897ecf50b30\n if you no longer wish to receive our emails.\n------------------------------------------------------------\nThis is the text of the email message.\n\nClick here to forward this message\nhttp://ui.l1.constantcontact.com/sa/fwtf.jsp?llr=cqmhk9aab&m=1100394770946&ea=rmarcucella%40constantcontact.com&a=1100400205633\n\n\n\n\n\nThis email was sent to {Email Address} by rmarcucella@constantcontact.com.\n\nUpdate Profile/Email Address\nhttp://visitor.l1.constantcontact.com/do?p=oo&m=001JZtDyxcvPiye1EthMqSLGA%3D%3D&ch={Contact Id}&ca=025eff86-6378-4f53-9301-5897ecf50b30\n\n\nInstant removal with SafeUnsubscribe(TM)\nhttp://visitor.l1.constantcontact.com/do?p=un&m=001JZtDyxcvPiye1EthMqSLGA%3D%3D&ch={Contact Id}&ca=025eff86-6378-4f53-9301-5897ecf50b30\n\n\nPrivacy Policy:\nhttp://ui.l1.constantcontact.com/roving/CCPrivacyPolicy.jsp\n\n\n\n\n\nOnline Marketing by\nhttp://img.l1.constantcontact.com/letters/images/cc-logo-color-sm.gif\nhttp://www.constantcontact.com\n\n\n\nMy Organization | 123 Maple Street | Suite 1 | Anytown | MA | 01444\n\n\n\n\n\n\n\n\n"
+ "subject": "Subject Test",
+ "from_email": "myemail@example.com",
+ "reply_to_email": "myemail@example.com",
+ "preview_email_content": "As a reminder, you're receiving this email because you have expressed an interest in MyCompany. Don't forget to add from_email@example.com to your address book so we'll be sure to land in your inbox! You may unsubscribe if you no longer wish to receive our emails. You may unsubscribe if you no longer wish to receive our emails. |
![]()
This is text of the email message.
\n\n
\n</body>",
+ "preview_text_content": "View this message as a web page\nClick here\nhttp://campaign.r20.l1.constantcontact.com/render?ca=025eff86-6378-4f53-9301-5897ecf50b30&c={Contact Id}&ch={Contact Id}\n\nAs a reminder, you're receiving this email because you have expressed an interest in MyCompany. Don't forget to add from_email@example.com to your address book so we'll be sure to land in your inbox! You may unsubscribe if you no longer wish to receive our emails. You may unsubscribe\nhttp://visitor.l1.constantcontact.com/do?p=un&m=001JZtDyxcvPiye1EthMqSLGA%3D%3D&ch={Contact Id}&ca=025eff86-6378-4f53-9301-5897ecf50b30\n if you no longer wish to receive our emails.\n------------------------------------------------------------\nThis is the text of the email message.\n\nClick here to forward this message\nhttp://ui.l1.constantcontact.com/sa/fwtf.jsp?llr=cqmhk9aab&m=1100394770946&ea=rmarcucella%40constantcontact.com&a=1100400205633\n\n\n\n\n\nThis email was sent to {Email Address} by rmarcucella@constantcontact.com.\n\nUpdate Profile/Email Address\nhttp://visitor.l1.constantcontact.com/do?p=oo&m=001JZtDyxcvPiye1EthMqSLGA%3D%3D&ch={Contact Id}&ca=025eff86-6378-4f53-9301-5897ecf50b30\n\n\nInstant removal with SafeUnsubscribe(TM)\nhttp://visitor.l1.constantcontact.com/do?p=un&m=001JZtDyxcvPiye1EthMqSLGA%3D%3D&ch={Contact Id}&ca=025eff86-6378-4f53-9301-5897ecf50b30\n\n\nPrivacy Policy:\nhttp://ui.l1.constantcontact.com/roving/CCPrivacyPolicy.jsp\n\n\n\n\n\nOnline Marketing by\nhttp://img.l1.constantcontact.com/letters/images/cc-logo-color-sm.gif\nhttp://www.constantcontact.com\n\n\n\nMy Organization | 123 Maple Street | Suite 1 | Anytown | MA | 01444\n\n\n\n\n\n\n\n\n"
}
diff --git a/test/Json/Campaigns/get_schedule.json b/test/Json/Campaigns/get_schedule.json
index 4eeeee7..146fdd0 100755
--- a/test/Json/Campaigns/get_schedule.json
+++ b/test/Json/Campaigns/get_schedule.json
@@ -1,4 +1,4 @@
{
- "id": 1,
- "scheduled_date": "2012-12-16T11:07:43.626Z"
+ "id": 1,
+ "scheduled_date": "2012-12-16T11:07:43.626Z"
}
\ No newline at end of file
diff --git a/test/Json/Campaigns/get_schedules.json b/test/Json/Campaigns/get_schedules.json
index b6cfccb..60c7252 100755
--- a/test/Json/Campaigns/get_schedules.json
+++ b/test/Json/Campaigns/get_schedules.json
@@ -1,10 +1,10 @@
[
- {
- "id": 1,
- "scheduled_date": "2012-12-16T11:07:43.626Z"
- },
- {
- "id": 2,
- "scheduled_date": "2012-12-17T11:08:00.000Z"
- }
+ {
+ "id": 1,
+ "scheduled_date": "2012-12-16T11:07:43.626Z"
+ },
+ {
+ "id": 2,
+ "scheduled_date": "2012-12-17T11:08:00.000Z"
+ }
]
diff --git a/test/Json/Campaigns/post_test_send.json b/test/Json/Campaigns/post_test_send.json
index ef9f265..99fb939 100755
--- a/test/Json/Campaigns/post_test_send.json
+++ b/test/Json/Campaigns/post_test_send.json
@@ -1,7 +1,7 @@
{
- "format": "HTML",
- "personal_message": "oh hai there",
- "email_addresses": [
- "test@roving.com"
- ]
+ "format": "HTML",
+ "personal_message": "oh hai there",
+ "email_addresses": [
+ "test@roving.com"
+ ]
}
\ No newline at end of file
diff --git a/test/Json/Contacts/error_response.json b/test/Json/Contacts/error_response.json
new file mode 100644
index 0000000..e5551dd
--- /dev/null
+++ b/test/Json/Contacts/error_response.json
@@ -0,0 +1,6 @@
+[
+ {
+ "error_key": "http.status.error",
+ "error_message": "Error message."
+ }
+]
diff --git a/test/Json/Contacts/get_contact.json b/test/Json/Contacts/get_contact.json
index ecd132b..793e0b5 100755
--- a/test/Json/Contacts/get_contact.json
+++ b/test/Json/Contacts/get_contact.json
@@ -1,63 +1,63 @@
{
- "id": 238,
- "status": "ACTIVE",
- "fax": "555-1212",
- "addresses": [
- {
- "line1": "1601 Trapelo Rd",
- "line2": "Suite 329",
- "line3": "Line 3",
- "city": "Waltham",
- "address_type": "PERSONAL",
- "state_code": "MA",
- "country_code": "us",
- "postal_code": "01720",
- "sub_postal_code": "7885"
- }
- ],
- "notes": [
- {
- "id": 1,
- "note": "Here are some cool notes to add",
- "created_date": "2012-12-03T17:09:22.702Z"
- }
- ],
- "confirmed": false,
- "lists": [
- {
- "id": 9,
- "status": "ACTIVE"
- }
- ],
- "source": "API",
- "email_addresses": [
- {
- "status": "ACTIVE",
- "confirm_status": "NO_CONFIRMATION_REQUIRED",
- "opt_in_source": "ACTION_BY_VISITOR",
- "opt_in_date": "2012-09-17T14:40:41.271Z",
- "opt_out_date": "2012-03-29T14:59:25.427Z",
- "email_address": "john+smith@gmail.com"
- }
- ],
- "prefix_name": "Mr.",
- "first_name": "John",
- "last_name": "Smith",
- "job_title": "Software Engineer",
- "company_name": "Constant Contact",
- "home_phone": "555-1212",
- "work_phone": "555-1213",
- "cell_phone": "555-1214",
- "custom_fields": [
- {
- "name": "CustomField1",
- "value": "3/28/2011 11:09 AM EDT"
- },
- {
- "name": "CustomField2",
- "value": "Site owner"
- }
- ],
- "source_details": "69f9d72b-0a5e-479d-b844-722b1da9595f",
- "source_is_url": false
+ "id": 238,
+ "status": "ACTIVE",
+ "fax": "555-1212",
+ "addresses": [
+ {
+ "line1": "1601 Trapelo Rd",
+ "line2": "Suite 329",
+ "line3": "Line 3",
+ "city": "Waltham",
+ "address_type": "PERSONAL",
+ "state_code": "MA",
+ "country_code": "us",
+ "postal_code": "01720",
+ "sub_postal_code": "7885"
+ }
+ ],
+ "notes": [
+ {
+ "id": 1,
+ "note": "Here are some cool notes to add",
+ "created_date": "2012-12-03T17:09:22.702Z"
+ }
+ ],
+ "confirmed": false,
+ "lists": [
+ {
+ "id": 9,
+ "status": "ACTIVE"
+ }
+ ],
+ "source": "API",
+ "email_addresses": [
+ {
+ "status": "ACTIVE",
+ "confirm_status": "NO_CONFIRMATION_REQUIRED",
+ "opt_in_source": "ACTION_BY_VISITOR",
+ "opt_in_date": "2012-09-17T14:40:41.271Z",
+ "opt_out_date": "2012-03-29T14:59:25.427Z",
+ "email_address": "john+smith@gmail.com"
+ }
+ ],
+ "prefix_name": "Mr.",
+ "first_name": "John",
+ "last_name": "Smith",
+ "job_title": "Software Engineer",
+ "company_name": "Constant Contact",
+ "home_phone": "555-1212",
+ "work_phone": "555-1213",
+ "cell_phone": "555-1214",
+ "custom_fields": [
+ {
+ "name": "CustomField1",
+ "value": "3/28/2011 11:09 AM EDT"
+ },
+ {
+ "name": "CustomField2",
+ "value": "Site owner"
+ }
+ ],
+ "source_details": "69f9d72b-0a5e-479d-b844-722b1da9595f",
+ "source_is_url": false
}
\ No newline at end of file
diff --git a/test/Json/Contacts/get_contacts.json b/test/Json/Contacts/get_contacts.json
index f49915f..179399d 100755
--- a/test/Json/Contacts/get_contacts.json
+++ b/test/Json/Contacts/get_contacts.json
@@ -1,111 +1,111 @@
{
- "meta": {
- "pagination": {
- "next_link": "/v2/contacts?next=c3RhcnRBdD0zJmxpbWl0PTI"
+ "meta": {
+ "pagination": {
+ "next_link": "/v2/contacts?next=c3RhcnRBdD0zJmxpbWl0PTI"
+ }
+ },
+ "results": [
+ {
+ "id": 230,
+ "status": "REMOVED",
+ "fax": "",
+ "addresses": [
+ {
+ "line1": "Addr1",
+ "line2": "",
+ "line3": "",
+ "city": "Boston",
+ "address_type": "PERSONAL",
+ "state_code": "MA",
+ "country_code": "us",
+ "postal_code": "00112",
+ "sub_postal_code": ""
+ },
+ {
+ "line1": "",
+ "line2": "",
+ "line3": "",
+ "city": "",
+ "address_type": "BUSINESS",
+ "state_code": "",
+ "country_code": "",
+ "postal_code": "",
+ "sub_postal_code": ""
}
+ ],
+ "notes": [],
+ "confirmed": false,
+ "lists": [],
+ "source": "",
+ "email_addresses": [
+ {
+ "status": "REMOVED",
+ "confirm_status": "NO_CONFIRMATION_REQUIRED",
+ "opt_in_source": "ACTION_BY_VISITOR",
+ "opt_in_date": "2012-05-29T16:26:36.915Z",
+ "opt_out_date": "2012-06-18T13:13:46.974Z",
+ "email_address": "test@roving.com"
+ }
+ ],
+ "prefix_name": "",
+ "first_name": "",
+ "last_name": "",
+ "job_title": "",
+ "department_name": "",
+ "company_name": "",
+ "custom_fields": [],
+ "source_details": "",
+ "action_by": "ACTION_BY_VISITOR"
},
- "results": [
+ {
+ "id": 231,
+ "status": "ACTIVE",
+ "fax": "",
+ "addresses": [
{
- "id": 230,
- "status": "REMOVED",
- "fax": "",
- "addresses": [
- {
- "line1": "Addr1",
- "line2": "",
- "line3": "",
- "city": "Boston",
- "address_type": "PERSONAL",
- "state_code": "MA",
- "country_code": "us",
- "postal_code": "00112",
- "sub_postal_code": ""
- },
- {
- "line1": "",
- "line2": "",
- "line3": "",
- "city": "",
- "address_type": "BUSINESS",
- "state_code": "",
- "country_code": "",
- "postal_code": "",
- "sub_postal_code": ""
- }
- ],
- "notes": [],
- "confirmed": false,
- "lists": [],
- "source": "",
- "email_addresses": [
- {
- "status": "REMOVED",
- "confirm_status": "NO_CONFIRMATION_REQUIRED",
- "opt_in_source": "ACTION_BY_VISITOR",
- "opt_in_date": "2012-05-29T16:26:36.915Z",
- "opt_out_date": "2012-06-18T13:13:46.974Z",
- "email_address": "test@roving.com"
- }
- ],
- "prefix_name": "",
- "first_name": "",
- "last_name": "",
- "job_title": "",
- "department_name": "",
- "company_name": "",
- "custom_fields": [],
- "source_details": "",
- "action_by": "ACTION_BY_VISITOR"
- },
+ "line1": "Suite 101",
+ "line2": "line2",
+ "line3": "line3",
+ "city": "Brookfield",
+ "address_type": "PERSONAL",
+ "state_code": "WI",
+ "country_code": "us",
+ "postal_code": "53027",
+ "sub_postal_code": ""
+ }
+ ],
+ "notes": [],
+ "confirmed": false,
+ "lists": [
+ {
+ "id": 1,
+ "status": "ACTIVE"
+ }
+ ],
+ "source": "",
+ "email_addresses": [
+ {
+ "status": "ACTIVE",
+ "confirm_status": "NO_CONFIRMATION_REQUIRED",
+ "opt_in_source": "ACTION_BY_OWNER",
+ "opt_in_date": "2012-06-22T10:29:09.976Z",
+ "opt_out_date": "",
+ "email_address": "anothertest@roving.com"
+ }
+ ],
+ "prefix_name": "",
+ "first_name": "Jimmy",
+ "last_name": "Roving",
+ "job_title": "Bear Tamer",
+ "department_name": "Animals",
+ "company_name": "Animal Trainer Pro",
+ "custom_fields": [
{
- "id": 231,
- "status": "ACTIVE",
- "fax": "",
- "addresses": [
- {
- "line1": "Suite 101",
- "line2": "line2",
- "line3": "line3",
- "city": "Brookfield",
- "address_type": "PERSONAL",
- "state_code": "WI",
- "country_code": "us",
- "postal_code": "53027",
- "sub_postal_code": ""
- }
- ],
- "notes": [],
- "confirmed": false,
- "lists": [
- {
- "id": 1,
- "status": "ACTIVE"
- }
- ],
- "source": "",
- "email_addresses": [
- {
- "status": "ACTIVE",
- "confirm_status": "NO_CONFIRMATION_REQUIRED",
- "opt_in_source": "ACTION_BY_OWNER",
- "opt_in_date": "2012-06-22T10:29:09.976Z",
- "opt_out_date": "",
- "email_address": "anothertest@roving.com"
- }
- ],
- "prefix_name": "",
- "first_name": "Jimmy",
- "last_name": "Roving",
- "job_title": "Bear Tamer",
- "department_name": "Animals",
- "company_name": "Animal Trainer Pro",
- "custom_fields": [
- {
- "name": "CustomField1",
- "value": "1"
- }
- ],
- "source_details": "details"
+ "name": "CustomField1",
+ "value": "1"
}
- ]
+ ],
+ "source_details": "details"
+ }
+ ]
}
\ No newline at end of file
diff --git a/test/Json/Contacts/get_contacts_no_next.json b/test/Json/Contacts/get_contacts_no_next.json
index 5c06864..5ae812d 100644
--- a/test/Json/Contacts/get_contacts_no_next.json
+++ b/test/Json/Contacts/get_contacts_no_next.json
@@ -1,108 +1,108 @@
{
- "meta": {
- "pagination": {}
- },
- "results": [
+ "meta": {
+ "pagination": {}
+ },
+ "results": [
+ {
+ "id": 230,
+ "status": "REMOVED",
+ "fax": "",
+ "addresses": [
{
- "id": 230,
- "status": "REMOVED",
- "fax": "",
- "addresses": [
- {
- "line1": "Addr1",
- "line2": "",
- "line3": "",
- "city": "Boston",
- "address_type": "PERSONAL",
- "state_code": "MA",
- "country_code": "us",
- "postal_code": "00112",
- "sub_postal_code": ""
- },
- {
- "line1": "",
- "line2": "",
- "line3": "",
- "city": "",
- "address_type": "BUSINESS",
- "state_code": "",
- "country_code": "",
- "postal_code": "",
- "sub_postal_code": ""
- }
- ],
- "notes": [],
- "confirmed": false,
- "lists": [],
- "source": "",
- "email_addresses": [
- {
- "status": "REMOVED",
- "confirm_status": "NO_CONFIRMATION_REQUIRED",
- "opt_in_source": "ACTION_BY_VISITOR",
- "opt_in_date": "2012-05-29T16:26:36.915Z",
- "opt_out_date": "2012-06-18T13:13:46.974Z",
- "email_address": "test@roving.com"
- }
- ],
- "prefix_name": "",
- "first_name": "",
- "last_name": "",
- "job_title": "",
- "department_name": "",
- "company_name": "",
- "custom_fields": [],
- "source_details": ""
+ "line1": "Addr1",
+ "line2": "",
+ "line3": "",
+ "city": "Boston",
+ "address_type": "PERSONAL",
+ "state_code": "MA",
+ "country_code": "us",
+ "postal_code": "00112",
+ "sub_postal_code": ""
},
{
- "id": 231,
- "status": "ACTIVE",
- "fax": "",
- "addresses": [
- {
- "line1": "Suite 101",
- "line2": "line2",
- "line3": "line3",
- "city": "Brookfield",
- "address_type": "PERSONAL",
- "state_code": "WI",
- "country_code": "us",
- "postal_code": "53027",
- "sub_postal_code": ""
- }
- ],
- "notes": [],
- "confirmed": false,
- "lists": [
- {
- "id": 1,
- "status": "ACTIVE"
- }
- ],
- "source": "",
- "email_addresses": [
- {
- "status": "ACTIVE",
- "confirm_status": "NO_CONFIRMATION_REQUIRED",
- "opt_in_source": "ACTION_BY_OWNER",
- "opt_in_date": "2012-06-22T10:29:09.976Z",
- "opt_out_date": "",
- "email_address": "anothertest@roving.com"
- }
- ],
- "prefix_name": "",
- "first_name": "Jimmy",
- "last_name": "Roving",
- "job_title": "Bear Tamer",
- "department_name": "Animals",
- "company_name": "Animal Trainer Pro",
- "custom_fields": [
- {
- "name": "CustomField1",
- "value": "1"
- }
- ],
- "source_details": "details"
+ "line1": "",
+ "line2": "",
+ "line3": "",
+ "city": "",
+ "address_type": "BUSINESS",
+ "state_code": "",
+ "country_code": "",
+ "postal_code": "",
+ "sub_postal_code": ""
+ }
+ ],
+ "notes": [],
+ "confirmed": false,
+ "lists": [],
+ "source": "",
+ "email_addresses": [
+ {
+ "status": "REMOVED",
+ "confirm_status": "NO_CONFIRMATION_REQUIRED",
+ "opt_in_source": "ACTION_BY_VISITOR",
+ "opt_in_date": "2012-05-29T16:26:36.915Z",
+ "opt_out_date": "2012-06-18T13:13:46.974Z",
+ "email_address": "test@roving.com"
+ }
+ ],
+ "prefix_name": "",
+ "first_name": "",
+ "last_name": "",
+ "job_title": "",
+ "department_name": "",
+ "company_name": "",
+ "custom_fields": [],
+ "source_details": ""
+ },
+ {
+ "id": 231,
+ "status": "ACTIVE",
+ "fax": "",
+ "addresses": [
+ {
+ "line1": "Suite 101",
+ "line2": "line2",
+ "line3": "line3",
+ "city": "Brookfield",
+ "address_type": "PERSONAL",
+ "state_code": "WI",
+ "country_code": "us",
+ "postal_code": "53027",
+ "sub_postal_code": ""
+ }
+ ],
+ "notes": [],
+ "confirmed": false,
+ "lists": [
+ {
+ "id": 1,
+ "status": "ACTIVE"
+ }
+ ],
+ "source": "",
+ "email_addresses": [
+ {
+ "status": "ACTIVE",
+ "confirm_status": "NO_CONFIRMATION_REQUIRED",
+ "opt_in_source": "ACTION_BY_OWNER",
+ "opt_in_date": "2012-06-22T10:29:09.976Z",
+ "opt_out_date": "",
+ "email_address": "anothertest@roving.com"
+ }
+ ],
+ "prefix_name": "",
+ "first_name": "Jimmy",
+ "last_name": "Roving",
+ "job_title": "Bear Tamer",
+ "department_name": "Animals",
+ "company_name": "Animal Trainer Pro",
+ "custom_fields": [
+ {
+ "name": "CustomField1",
+ "value": "1"
}
- ]
+ ],
+ "source_details": "details"
+ }
+ ]
}
\ No newline at end of file
diff --git a/test/Json/JsonLoader.php b/test/Json/JsonLoader.php
index 39de9b4..00c7d48 100755
--- a/test/Json/JsonLoader.php
+++ b/test/Json/JsonLoader.php
@@ -1,7 +1,6 @@
getEmitter()->attach($mock);
+ $handler = HandlerStack::create($mock);
+ self::$client = new Client(['handler' => $handler]);
}
public function testGetVerifiedAddresses() {
- $response = self::$client->get('/');
+ $response = self::$client->request('GET', '/');
$verifiedAddresses = array();
- foreach ($response->json() as $verifiedAddress) {
+ foreach (json_decode($response->getBody(), true) as $verifiedAddress) {
$verifiedAddresses[] = VerifiedEmailAddress::create($verifiedAddress);
}
@@ -40,10 +36,9 @@ public function testGetVerifiedAddresses() {
}
}
- public function testGetAccountInfo()
- {
- $response = self::$client->get('/');
- $result = AccountInfo::create($response->json());
+ public function testGetAccountInfo() {
+ $response = self::$client->request('GET', '/');
+ $result = AccountInfo::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Account\AccountInfo', $result);
$this->assertEquals("http://www.example.com", $result->website);
diff --git a/test/Services/ActivityServiceUnitTest.php b/test/Services/ActivityServiceUnitTest.php
index 8874639..e0140ca 100644
--- a/test/Services/ActivityServiceUnitTest.php
+++ b/test/Services/ActivityServiceUnitTest.php
@@ -1,42 +1,33 @@
getEmitter()->attach($mock);
+ $handler = HandlerStack::create($mock);
+ self::$client = new Client(['handler' => $handler]);
}
- public function testGetActivity()
- {
- $response = self::$client->get('/');
+ public function testGetActivity() {
+ $response = self::$client->request('GET', '/');
- $activity = Activity::create($response->json());
+ $activity = Activity::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Activities\Activity', $activity);
$this->assertEquals("a07e1ikxyomhd4la0o9", $activity->id);
$this->assertEquals("REMOVE_CONTACTS_FROM_LISTS", $activity->type);
@@ -50,11 +41,10 @@ public function testGetActivity()
$this->assertEquals(0, $activity->errors[0]->line_number);
}
- public function testGetActivities()
- {
- $response = self::$client->get('/');
+ public function testGetActivities() {
+ $response = self::$client->request('GET', '/');
$activities = array();
- foreach ($response->json() as $activityResponse) {
+ foreach (json_decode($response->getBody(), true) as $activityResponse) {
$activities[] = Activity::create($activityResponse);
}
$activity = $activities[0];
@@ -69,11 +59,10 @@ public function testGetActivities()
$this->assertEquals(0, $activity->contact_count);
}
- public function testAddClearListsActivity()
- {
- $response = self::$client->post('/');
+ public function testAddClearListsActivity() {
+ $response = self::$client->request('POST', '/');
- $activity = Activity::create($response->json());
+ $activity = Activity::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Activities\Activity', $activity);
$this->assertEquals("a07e1il69fwhd7uan9h", $activity->id);
$this->assertEquals("CLEAR_CONTACTS_FROM_LISTS", $activity->type);
@@ -81,11 +70,10 @@ public function testAddClearListsActivity()
$this->assertEquals(0, $activity->contact_count);
}
- public function testAddExportContactsActivity()
- {
- $response = self::$client->post('/');
+ public function testAddExportContactsActivity() {
+ $response = self::$client->request('POST', '/');
- $activity = Activity::create($response->json());
+ $activity = Activity::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Activities\Activity', $activity);
$this->assertEquals("a07e1i5nqamhcfeuu0h", $activity->id);
$this->assertEquals("EXPORT_CONTACTS", $activity->type);
@@ -93,11 +81,10 @@ public function testAddExportContactsActivity()
$this->assertEquals(0, $activity->contact_count);
}
- public function testAddRemoveContactsFromListsActivity()
- {
- $response = self::$client->post('/');
+ public function testAddRemoveContactsFromListsActivity() {
+ $response = self::$client->request('POST', '/');
- $activity = Activity::create($response->json());
+ $activity = Activity::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Activities\Activity', $activity);
$this->assertEquals("a07e1i5nqamhcfeuu0h", $activity->id);
$this->assertEquals("REMOVE_CONTACTS_FROM_LISTS", $activity->type);
@@ -105,11 +92,10 @@ public function testAddRemoveContactsFromListsActivity()
$this->assertEquals(0, $activity->contact_count);
}
- public function testAddCreateContactsActivity()
- {
- $response = self::$client->post('/');
+ public function testAddCreateContactsActivity() {
+ $response = self::$client->request('POST', '/');
- $activity = Activity::create($response->json());
+ $activity = Activity::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Activities\Activity', $activity);
$this->assertEquals("a07e1il69qzhdby44ro", $activity->id);
$this->assertEquals("ADD_CONTACTS", $activity->type);
diff --git a/test/Services/CampaignScheduleServiceUnitTest.php b/test/Services/CampaignScheduleServiceUnitTest.php
index 2cdbc6c..bae62fd 100755
--- a/test/Services/CampaignScheduleServiceUnitTest.php
+++ b/test/Services/CampaignScheduleServiceUnitTest.php
@@ -2,44 +2,39 @@
use Ctct\Components\EmailMarketing\Schedule;
use Ctct\Components\EmailMarketing\TestSend;
-
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
-use GuzzleHttp\Subscriber\Mock;
-use GuzzleHttp\Stream\Stream;
-use GuzzleHttp\Message\Response;
+use GuzzleHttp\Handler\MockHandler;
+use GuzzleHttp\HandlerStack;
+use GuzzleHttp\Psr7\Response;
-class CampaignScheduleServiceUnitTest extends PHPUnit_Framework_TestCase
-{
+class CampaignScheduleServiceUnitTest extends PHPUnit_Framework_TestCase {
/**
* @var Client
*/
private static $client;
- public static function setUpBeforeClass()
- {
+ public static function setUpBeforeClass() {
self::$client = new Client();
- $schedulesStream = Stream::factory(JsonLoader::getCampaignSchedulesJson());
- $scheduleStream = Stream::factory(JsonLoader::getCampaignScheduleJson());
- $testSendStream = Stream::factory(JsonLoader::getTestSendJson());
- $mock = new Mock([
- new Response(200, array(), $schedulesStream),
- new Response(200, array(), $scheduleStream),
- new Response(201, array(), $scheduleStream),
- new Response(200, array(), $scheduleStream),
+ $scheduleJson = JsonLoader::getCampaignScheduleJson();
+ $mock = new MockHandler([
+ new Response(200, array(), JsonLoader::getCampaignSchedulesJson()),
+ new Response(200, array(), $scheduleJson),
+ new Response(201, array(), $scheduleJson),
+ new Response(200, array(), $scheduleJson),
new Response(204, array()),
new Response(400, array()),
- new Response(200, array(), $testSendStream)
+ new Response(200, array(), JsonLoader::getTestSendJson())
]);
- self::$client->getEmitter()->attach($mock);
+ $handler = HandlerStack::create($mock);
+ self::$client = new Client(['handler' => $handler]);
}
- public function testGetSchedules()
- {
- $response = self::$client->get('/');
+ public function testGetSchedules() {
+ $response = self::$client->request('GET', '/');
$schedules = array();
- foreach ($response->json() as $responseSchedule) {
+ foreach (json_decode($response->getBody(), true) as $responseSchedule) {
$schedules[] = $responseSchedule;
}
@@ -53,58 +48,52 @@ public function testGetSchedules()
$this->assertEquals("2012-12-17T11:08:00.000Z", $schedule2->scheduled_date);
}
- public function testGetSchedule()
- {
- $response = self::$client->get('/');
+ public function testGetSchedule() {
+ $response = self::$client->request('GET', '/');
- $schedule = Schedule::create($response->json());
+ $schedule = Schedule::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\EmailMarketing\Schedule', $schedule);
$this->assertEquals(1, $schedule->id);
$this->assertEquals("2012-12-16T11:07:43.626Z", $schedule->scheduled_date);
}
- public function testAddSchedule()
- {
- $response = self::$client->post('/');
+ public function testAddSchedule() {
+ $response = self::$client->request('POST', '/');
- $createdSchedule = Schedule::create($response->json());
+ $createdSchedule = Schedule::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\EmailMarketing\Schedule', $createdSchedule);
$this->assertEquals(1, $createdSchedule->id);
$this->assertEquals("2012-12-16T11:07:43.626Z", $createdSchedule->scheduled_date);
}
- public function testUpdateSchedule()
- {
- $response = self::$client->put('/');
+ public function testUpdateSchedule() {
+ $response = self::$client->request('PUT', '/');
- $updatedSchedule = Schedule::create($response->json());
+ $updatedSchedule = Schedule::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\EmailMarketing\Schedule', $updatedSchedule);
$this->assertEquals(1, $updatedSchedule->id);
$this->assertEquals("2012-12-16T11:07:43.626Z", $updatedSchedule->scheduled_date);
}
- public function testDeleteSchedule()
- {
- $response = self::$client->delete('/');
+ public function testDeleteSchedule() {
+ $response = self::$client->request('DELETE', '/');
$this->assertEquals(204, $response->getStatusCode());
}
- public function testDeleteScheduleFailed()
- {
+ public function testDeleteScheduleFailed() {
try {
- self::$client->delete('/');
+ self::$client->request('DELETE', '/');
$this->fail("Call did not fail");
} catch (ClientException $e) {
$this->assertEquals(400, $e->getCode());
}
}
- public function testSendTest()
- {
- $response = self::$client->post('/');
+ public function testSendTest() {
+ $response = self::$client->request('POST', '/');
- $testSend = TestSend::create($response->json());
+ $testSend = TestSend::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\EmailMarketing\TestSend', $testSend);
$this->assertEquals("HTML", $testSend->format);
$this->assertEquals("oh hai there", $testSend->personal_message);
diff --git a/test/Services/CampaignTrackingServiceUnitTest.php b/test/Services/CampaignTrackingServiceUnitTest.php
index c3a3e20..7bc5d9f 100755
--- a/test/Services/CampaignTrackingServiceUnitTest.php
+++ b/test/Services/CampaignTrackingServiceUnitTest.php
@@ -8,46 +8,35 @@
use Ctct\Components\Tracking\SendActivity;
use Ctct\Components\Tracking\TrackingSummary;
use Ctct\Components\Tracking\UnsubscribeActivity;
-
use GuzzleHttp\Client;
-use GuzzleHttp\Subscriber\Mock;
-use GuzzleHttp\Stream\Stream;
-use GuzzleHttp\Message\Response;
+use GuzzleHttp\Handler\MockHandler;
+use GuzzleHttp\HandlerStack;
+use GuzzleHttp\Psr7\Response;
-class CampaignTrackingServiceUnitTest extends PHPUnit_Framework_TestCase
-{
+class CampaignTrackingServiceUnitTest extends PHPUnit_Framework_TestCase {
/**
* @var Client
*/
private static $client;
- public static function setUpBeforeClass()
- {
- self::$client = new Client();
- $bouncesStream = Stream::factory(JsonLoader::getBounces());
- $clicksStream = Stream::factory(JsonLoader::getClicks());
- $forwardsStream = Stream::factory(JsonLoader::getForwards());
- $unsubscribesStream = Stream::factory(JsonLoader::getOptOuts());
- $sendsStream = Stream::factory(JsonLoader::getSends());
- $opensStream = Stream::factory(JsonLoader::getOpens());
- $summaryStream = Stream::factory(JsonLoader::getSummary());
- $mock = new Mock([
- new Response(200, array(), $bouncesStream),
- new Response(200, array(), $clicksStream),
- new Response(200, array(), $forwardsStream),
- new Response(200, array(), $unsubscribesStream),
- new Response(200, array(), $sendsStream),
- new Response(200, array(), $opensStream),
- new Response(200, array(), $summaryStream)
+ public static function setUpBeforeClass() {
+ $mock = new MockHandler([
+ new Response(200, array(), JsonLoader::getBounces()),
+ new Response(200, array(), JsonLoader::getClicks()),
+ new Response(200, array(), JsonLoader::getForwards()),
+ new Response(200, array(), JsonLoader::getOptOuts()),
+ new Response(200, array(), JsonLoader::getSends()),
+ new Response(200, array(), JsonLoader::getOpens()),
+ new Response(200, array(), JsonLoader::getSummary())
]);
- self::$client->getEmitter()->attach($mock);
+ $handler = HandlerStack::create($mock);
+ self::$client = new Client(['handler' => $handler]);
}
- public function testGetBounces()
- {
- $response = self::$client->get('/');
+ public function testGetBounces() {
+ $response = self::$client->request('GET', '/');
- $responseJson = $response->json();
+ $responseJson = json_decode($response->getBody(), true);
$resultSet = new ResultSet($responseJson['results'], $responseJson['meta']);
$bounceActivity = BounceActivity::create($resultSet->results[0]);
@@ -69,11 +58,10 @@ public function testGetBounces()
$this->assertEquals("2012-12-06T13:05:24.844Z", $bounceActivity->bounce_date);
}
- public function testGetClicks()
- {
- $response = self::$client->get('/');
+ public function testGetClicks() {
+ $response = self::$client->request('GET', '/');
- $responseJson = $response->json();
+ $responseJson = json_decode($response->getBody(), true);
$resultSet = new ResultSet($responseJson['results'], $responseJson['meta']);
$clickActivity = ClickActivity::create($resultSet->results[0]);
@@ -93,11 +81,10 @@ public function testGetClicks()
$this->assertEquals("2012-12-06T13:07:01.701Z", $clickActivity->click_date);
}
- public function testGetForwards()
- {
- $response = self::$client->get('/');
+ public function testGetForwards() {
+ $response = self::$client->request('GET', '/');
- $responseJson = $response->json();
+ $responseJson = json_decode($response->getBody(), true);
$resultSet = new ResultSet($responseJson['results'], $responseJson['meta']);
$forwardActivity = ForwardActivity::create($resultSet->results[0]);
@@ -116,11 +103,10 @@ public function testGetForwards()
$this->assertEquals("2012-12-06T13:07:06.810Z", $forwardActivity->forward_date);
}
- public function testGetUnsubscribes()
- {
- $response = self::$client->get('/');
+ public function testGetUnsubscribes() {
+ $response = self::$client->request('GET', '/');
- $responseJson = $response->json();
+ $responseJson = json_decode($response->getBody(), true);
$resultSet = new ResultSet($responseJson['results'], $responseJson['meta']);
$unsubscribeActivity = UnsubscribeActivity::create($resultSet->results[0]);
@@ -141,11 +127,10 @@ public function testGetUnsubscribes()
$this->assertEquals("", $unsubscribeActivity->unsubscribe_reason);
}
- public function testGetSends()
- {
- $response = self::$client->get('/');
+ public function testGetSends() {
+ $response = self::$client->request('GET', '/');
- $responseJson = $response->json();
+ $responseJson = json_decode($response->getBody(), true);
$resultSet = new ResultSet($responseJson['results'], $responseJson['meta']);
$sendActivity = SendActivity::create($resultSet->results[0]);
@@ -164,11 +149,10 @@ public function testGetSends()
$this->assertEquals("2012-12-06T18:06:50.650Z", $sendActivity->send_date);
}
- public function testGetOpens()
- {
- $response = self::$client->get('/');
+ public function testGetOpens() {
+ $response = self::$client->request('GET', '/');
- $responseJson = $response->json();
+ $responseJson = json_decode($response->getBody(), true);
$resultSet = new ResultSet($responseJson['results'], $responseJson['meta']);
$openActivity = OpenActivity::create($resultSet->results[0]);
@@ -187,11 +171,10 @@ public function testGetOpens()
$this->assertEquals("2012-12-06T13:07:11.839Z", $openActivity->open_date);
}
- public function testGetSummary()
- {
- $response = self::$client->get('/');
+ public function testGetSummary() {
+ $response = self::$client->request('GET', '/');
- $summary = TrackingSummary::create($response->json());
+ $summary = TrackingSummary::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Tracking\TrackingSummary', $summary);
$this->assertEquals(15, $summary->sends);
$this->assertEquals(10, $summary->opens);
diff --git a/test/Services/ContactServiceUnitTest.php b/test/Services/ContactServiceUnitTest.php
index 48cc217..6f3cdeb 100755
--- a/test/Services/ContactServiceUnitTest.php
+++ b/test/Services/ContactServiceUnitTest.php
@@ -1,48 +1,41 @@
getEmitter()->attach($mock);
+ $handler = HandlerStack::create($mock);
+ $client = new Client(['handler' => $handler]);
+ self::$constantContact = new ConstantContact('API_KEY', $client);
}
- public function testGetContacts()
- {
- $response = self::$client->get('/')->json();
- $result = new ResultSet($response['results'], $response['meta']);
-
+ public function testGetContacts() {
+ $result = self::$constantContact->contactService->getContacts('ACCESS_TOKEN');
$this->assertInstanceOf('Ctct\Components\ResultSet', $result);
$this->assertEquals('c3RhcnRBdD0zJmxpbWl0PTI', $result->next);
- $contact = Contact::create($result->results[1]);
+ $contact = $result->results[1];
$this->assertInstanceOf('Ctct\Components\Contacts\Contact', $contact);
$this->assertEquals(231, $contact->id);
$this->assertEquals("ACTIVE", $contact->status);
@@ -93,15 +86,13 @@ public function testGetContacts()
$this->assertEquals("anothertest@roving.com", $emailAddress->email_address);
}
- public function testGetContactsNoNextLink()
- {
- $response = self::$client->get('/')->json();
- $result = new ResultSet($response['results'], $response['meta']);
+ public function testGetContactsNoNextLink() {
+ $result = self::$constantContact->contactService->getContacts('ACCESS_TOKEN');
$this->assertInstanceOf('Ctct\Components\ResultSet', $result);
$this->assertEquals(null, $result->next);
- $contact = Contact::create($result->results[1]);
+ $contact = $result->results[1];
$this->assertInstanceOf('Ctct\Components\Contacts\Contact', $contact);
$this->assertEquals(231, $contact->id);
$this->assertEquals("ACTIVE", $contact->status);
@@ -152,11 +143,9 @@ public function testGetContactsNoNextLink()
$this->assertEquals("anothertest@roving.com", $emailAddress->email_address);
}
- public function testGetContact()
- {
- $response = self::$client->get('/');
+ public function testGetContact() {
+ $contact = self::$constantContact->contactService->getContact('ACCESS_TOKEN', 238);
- $contact = Contact::create($response->json());
$this->assertInstanceOf('Ctct\Components\Contacts\Contact', $contact);
$this->assertEquals(238, $contact->id);
$this->assertEquals("ACTIVE", $contact->status);
@@ -213,11 +202,10 @@ public function testGetContact()
$this->assertEquals("john+smith@gmail.com", $contact->email_addresses[0]->email_address);
}
- public function testAddContact()
- {
- $response = self::$client->post('/');
+ public function testAddContact() {
+ $sourceContact = Contact::create((array) JsonLoader::getContactJson());
+ $contact = self::$constantContact->contactService->addContact('ACCESS_TOKEN', $sourceContact, true);
- $contact = Contact::create($response->json());
$this->assertInstanceOf('Ctct\Components\Contacts\Contact', $contact);
$this->assertEquals(238, $contact->id);
$this->assertEquals("ACTIVE", $contact->status);
@@ -274,27 +262,25 @@ public function testAddContact()
$this->assertEquals("john+smith@gmail.com", $contact->email_addresses[0]->email_address);
}
- public function testDeleteContact()
- {
- $response = self::$client->delete('/');
+ public function testDeleteContact() {
+ $success = self::$constantContact->contactService->unsubscribeContact('ACCESS_TOKEN', 238);
- $this->assertEquals(204, $response->getStatusCode());
+ $this->assertTrue($success);
}
public function testDeleteContactFailed() {
try {
- self::$client->delete('/');
+ self::$constantContact->contactService->unsubscribeContact('ACCESS_TOKEN', 238);
$this->fail("Delete call didn't fail");
- } catch (ClientException $e) {
- $this->assertEquals(400, $e->getCode());
+ } catch (CtctException $exception) {
+ $this->assertEquals(400, $exception->getCode());
}
}
- public function testUpdateContact()
- {
- $response = self::$client->put('/');
+ public function testUpdateContact() {
+ $sourceContact = Contact::create((array) JsonLoader::getContactJson());
+ $contact = self::$constantContact->contactService->updateContact('ACCESS_TOKEN', $sourceContact, true);
- $contact = Contact::create($response->json());
$this->assertInstanceOf('Ctct\Components\Contacts\Contact', $contact);
$this->assertEquals(238, $contact->id);
$this->assertEquals("ACTIVE", $contact->status);
diff --git a/test/Services/ContactTrackingServiceUnitTest.php b/test/Services/ContactTrackingServiceUnitTest.php
index 36801bc..ee8807b 100755
--- a/test/Services/ContactTrackingServiceUnitTest.php
+++ b/test/Services/ContactTrackingServiceUnitTest.php
@@ -4,48 +4,37 @@
use Ctct\Components\Tracking\BounceActivity;
use Ctct\Components\Tracking\ClickActivity;
use Ctct\Components\Tracking\ForwardActivity;
-use Ctct\Components\Tracking\UnsubscribeActivity;
-use Ctct\Components\Tracking\SendActivity;
use Ctct\Components\Tracking\OpenActivity;
+use Ctct\Components\Tracking\SendActivity;
use Ctct\Components\Tracking\TrackingSummary;
-
+use Ctct\Components\Tracking\UnsubscribeActivity;
use GuzzleHttp\Client;
-use GuzzleHttp\Subscriber\Mock;
-use GuzzleHttp\Stream\Stream;
-use GuzzleHttp\Message\Response;
+use GuzzleHttp\Handler\MockHandler;
+use GuzzleHttp\HandlerStack;
+use GuzzleHttp\Psr7\Response;
-class ContactTrackingServiceUnitTest extends PHPUnit_Framework_TestCase
-{
+class ContactTrackingServiceUnitTest extends PHPUnit_Framework_TestCase {
/**
* @var Client
*/
private static $client;
- public static function setUpBeforeClass()
- {
- self::$client = new Client();
- $getBouncesStream = Stream::factory(JsonLoader::getBounces());
- $getClicksStream = Stream::factory(JsonLoader::getClicks());
- $getForwardsStream = Stream::factory(JsonLoader::getForwards());
- $getUnsubscribesStream = Stream::factory(JsonLoader::getOptOuts());
- $getSendsStream = Stream::factory(JsonLoader::getSends());
- $getOpensStream = Stream::factory(JsonLoader::getOpens());
- $getSummaryStream = Stream::factory(JsonLoader::getSummary());
- $mock = new Mock([
- new Response(200, array(), $getBouncesStream),
- new Response(200, array(), $getClicksStream),
- new Response(200, array(), $getForwardsStream),
- new Response(200, array(), $getUnsubscribesStream),
- new Response(200, array(), $getSendsStream),
- new Response(200, array(), $getOpensStream),
- new Response(200, array(), $getSummaryStream)
+ public static function setUpBeforeClass() {
+ $mock = new MockHandler([
+ new Response(200, array(), JsonLoader::getBounces()),
+ new Response(200, array(), JsonLoader::getClicks()),
+ new Response(200, array(), JsonLoader::getForwards()),
+ new Response(200, array(), JsonLoader::getOptOuts()),
+ new Response(200, array(), JsonLoader::getSends()),
+ new Response(200, array(), JsonLoader::getOpens()),
+ new Response(200, array(), JsonLoader::getSummary())
]);
- self::$client->getEmitter()->attach($mock);
+ $handler = HandlerStack::create($mock);
+ self::$client = new Client(['handler' => $handler]);
}
- public function testGetBounces()
- {
- $response = self::$client->get('/')->json();
+ public function testGetBounces() {
+ $response = json_decode(self::$client->request('GET', '/')->getBody(), true);
$resultSet = new ResultSet($response['results'], $response['meta']);
$bounceActivity = BounceActivity::create($resultSet->results[0]);
@@ -66,9 +55,8 @@ public function testGetBounces()
$this->assertEquals("2012-12-06T13:05:24.844Z", $bounceActivity->bounce_date);
}
- public function testGetClicks()
- {
- $response = self::$client->get('/')->json();
+ public function testGetClicks() {
+ $response = json_decode(self::$client->request('GET', '/')->getBody(), true);
$resultSet = new ResultSet($response['results'], $response['meta']);
$clickActivity = ClickActivity::create($resultSet->results[0]);
@@ -87,9 +75,8 @@ public function testGetClicks()
$this->assertEquals("2012-12-06T13:07:01.701Z", $clickActivity->click_date);
}
- public function testGetForwards()
- {
- $response = self::$client->get('/')->json();
+ public function testGetForwards() {
+ $response = json_decode(self::$client->request('GET', '/')->getBody(), true);
$resultSet = new ResultSet($response['results'], $response['meta']);
$forwardActivity = ForwardActivity::create($resultSet->results[0]);
@@ -107,9 +94,8 @@ public function testGetForwards()
$this->assertEquals("2012-12-06T13:07:06.810Z", $forwardActivity->forward_date);
}
- public function testGetUnsubscribes()
- {
- $response = self::$client->get('/')->json();
+ public function testGetUnsubscribes() {
+ $response = json_decode(self::$client->request('GET', '/')->getBody(), true);
$resultSet = new ResultSet($response['results'], $response['meta']);
$unsubscribeActivity = UnsubscribeActivity::create($resultSet->results[0]);
@@ -129,9 +115,8 @@ public function testGetUnsubscribes()
$this->assertEquals("", $unsubscribeActivity->unsubscribe_reason);
}
- public function testGetSends()
- {
- $response = self::$client->get('/')->json();
+ public function testGetSends() {
+ $response = json_decode(self::$client->request('GET', '/')->getBody(), true);
$resultSet = new ResultSet($response['results'], $response['meta']);
$sendActivity = SendActivity::create($resultSet->results[0]);
@@ -149,9 +134,8 @@ public function testGetSends()
$this->assertEquals("2012-12-06T18:06:50.650Z", $sendActivity->send_date);
}
- public function testGetOpens()
- {
- $response = self::$client->get('/')->json();
+ public function testGetOpens() {
+ $response = json_decode(self::$client->request('GET', '/')->getBody(), true);
$resultSet = new ResultSet($response['results'], $response['meta']);
$openActivity = OpenActivity::create($resultSet->results[0]);
@@ -169,11 +153,10 @@ public function testGetOpens()
$this->assertEquals("2012-12-06T13:07:11.839Z", $openActivity->open_date);
}
- public function testGetSummary()
- {
- $response = self::$client->get('/');
+ public function testGetSummary() {
+ $response = self::$client->request('GET', '/');
- $summary = TrackingSummary::create($response->json());
+ $summary = TrackingSummary::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Tracking\TrackingSummary', $summary);
$this->assertEquals(15, $summary->sends);
$this->assertEquals(10, $summary->opens);
diff --git a/test/Services/EmailCampaignServiceUnitTest.php b/test/Services/EmailCampaignServiceUnitTest.php
index ac2407e..e477a3b 100755
--- a/test/Services/EmailCampaignServiceUnitTest.php
+++ b/test/Services/EmailCampaignServiceUnitTest.php
@@ -1,43 +1,37 @@
getEmitter()->attach($mock);
+ $handler = HandlerStack::create($mock);
+ self::$client = new Client(['handler' => $handler]);
}
- public function testGetCampaigns()
- {
- $response = self::$client->get('/')->json();
+ public function testGetCampaigns() {
+ $response = json_decode(self::$client->request('GET', '/')->getBody(), true);
$result = new ResultSet($response['results'], $response['meta']);
$campaigns = array();
foreach ($result->results as $campaign) {
@@ -58,27 +52,24 @@ public function testGetCampaigns()
$this->assertEquals("2012-10-16T16:14:34.221Z", $campaigns[1]->modified_date);
}
- public function testDeleteCampaign()
- {
- $response = self::$client->delete('/');
+ public function testDeleteCampaign() {
+ $response = self::$client->request('DELETE', '/');
$this->assertEquals(204, $response->getStatusCode());
}
- public function testDeleteCampaignFailed()
- {
+ public function testDeleteCampaignFailed() {
try {
- self::$client->delete('/');
+ self::$client->request('DELETE', '/');
$this->fail("Delete did not fail");
} catch (ClientException $e) {
$this->assertEquals(400, $e->getCode());
}
}
- public function testGetCampaign()
- {
- $response = self::$client->get('/');
+ public function testGetCampaign() {
+ $response = self::$client->request('GET', '/');
- $campaign = Campaign::create($response->json());
+ $campaign = Campaign::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\EmailMarketing\Campaign', $campaign);
$this->assertEquals("1100394165290", $campaign->id);
$this->assertEquals("CampaignName-05965ddb-12d2-43e5-b8f3-0c22ca487c3a", $campaign->name);
@@ -142,11 +133,10 @@ public function testGetCampaign()
$this->assertEquals(10, $campaign->click_through_details[0]->click_count);
}
- public function testAddCampaign()
- {
- $response = self::$client->post('/');
+ public function testAddCampaign() {
+ $response = self::$client->request('POST', '/');
- $campaign = Campaign::create($response->json());
+ $campaign = Campaign::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\EmailMarketing\Campaign', $campaign);
$this->assertEquals("1100394165290", $campaign->id);
$this->assertEquals("CampaignName-05965ddb-12d2-43e5-b8f3-0c22ca487c3a", $campaign->name);
@@ -209,11 +199,10 @@ public function testAddCampaign()
$this->assertEquals(10, $campaign->click_through_details[0]->click_count);
}
- public function testUpdateCampaign()
- {
- $response = self::$client->put('/');
+ public function testUpdateCampaign() {
+ $response = self::$client->request('PUT', '/');
- $campaign = Campaign::create($response->json());
+ $campaign = Campaign::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\EmailMarketing\Campaign', $campaign);
$this->assertEquals("1100394165290", $campaign->id);
$this->assertEquals("CampaignName-05965ddb-12d2-43e5-b8f3-0c22ca487c3a", $campaign->name);
@@ -277,9 +266,9 @@ public function testUpdateCampaign()
}
public function testGetPreview() {
- $response = self::$client->get('/');
+ $response = self::$client->request('GET', '/');
- $preview = CampaignPreview::create($response->json());
+ $preview = CampaignPreview::create(json_decode($response->getBody(), true));
$this->assertEquals("Subject Test", $preview->subject);
$this->assertEquals("myemail@example.com", $preview->fromEmail);
$this->assertEquals("myemail@example.com", $preview->replyToEmail);
diff --git a/test/Services/LibraryServiceUnitTest.php b/test/Services/LibraryServiceUnitTest.php
index fda7742..f3773f2 100644
--- a/test/Services/LibraryServiceUnitTest.php
+++ b/test/Services/LibraryServiceUnitTest.php
@@ -1,46 +1,37 @@
1)),
- new Response(200, array(), $getFileUploadStream)
+ new Response(200, array(), JsonLoader::getFileUploadStatusJson())
]);
- self::$client->getEmitter()->attach($mock);
+ $handler = HandlerStack::create($mock);
+ self::$client = new Client(['handler' => $handler]);
}
- public function testGetLibraryFile()
- {
- $response = self::$client->get('/');
+ public function testGetLibraryFile() {
+ $response = self::$client->request('GET', '/');
- $file = File::create($response->json());
+ $file = File::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Library\File', $file);
$this->assertEquals("IMG_0261.JPG", $file->name);
$this->assertEquals("4", $file->id);
@@ -65,9 +56,8 @@ public function testGetLibraryFile()
$this->assertEquals("JPG", $file->type);
}
- public function testGetLibraryFiles()
- {
- $response = self::$client->get('/')->json();
+ public function testGetLibraryFiles() {
+ $response = json_decode(self::$client->request('GET', '/')->getBody(), true);
$result = new ResultSet($response['results'], $response['meta']);
$files = array();
@@ -101,11 +91,10 @@ public function testGetLibraryFiles()
$this->assertEquals("PNG", $files[0]->file_type);
}
- public function testGetLibraryFolder()
- {
- $response = self::$client->get('/');
+ public function testGetLibraryFolder() {
+ $response = self::$client->request('GET', '/');
- $folder = Folder::create($response->json());
+ $folder = Folder::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Library\Folder', $folder);
$this->assertEquals("-5", $folder->id);
$this->assertEquals("Folder", $folder->name);
@@ -131,9 +120,8 @@ public function testGetLibraryFolder()
$this->assertEquals("2013-09-09T14:25:44.000-04:00", $folder->created_date);
}
- public function testGetLibraryFolders()
- {
- $response = self::$client->get('/')->json();
+ public function testGetLibraryFolders() {
+ $response = json_decode(self::$client->request('GET', '/')->getBody(), true);
$result = new ResultSet($response['results'], $response['meta']);
$folders = array();
@@ -168,22 +156,22 @@ public function testGetLibraryFolders()
$this->assertEquals("2013-09-09T14:25:44.000-04:00", $folders[0]->created_date);
}
- public function testUploadFile()
- {
- $response = self::$client->post('/');
+ public function testUploadFile() {
+ $response = self::$client->request('POST', '/');
$id = $response->getHeader("Id");
$code = $response->getStatusCode();
- $this->assertEquals("1", $id);
+ foreach ($id as $item) {
+ $this->assertEquals(1, $item);
+ }
$this->assertEquals(201, $code);
}
- public function testGetFileUploadStatus()
- {
- $response = self::$client->get('/');
+ public function testGetFileUploadStatus() {
+ $response = self::$client->request('GET', '/');
$statuses = array();
- foreach ($response->json() as $result) {
+ foreach (json_decode($response->getBody(), true) as $result) {
$statuses[] = FileUploadStatus::create($result);
}
diff --git a/test/Services/ListServiceUnitTest.php b/test/Services/ListServiceUnitTest.php
index 1073dd9..ea34b57 100755
--- a/test/Services/ListServiceUnitTest.php
+++ b/test/Services/ListServiceUnitTest.php
@@ -1,43 +1,38 @@
getEmitter()->attach($mock);
+ $handler = HandlerStack::create($mock);
+ self::$client = new Client(['handler' => $handler]);
}
- public function testGetLists()
- {
- $response = self::$client->get('/');
+ public function testGetLists() {
+ $response = self::$client->request('GET', '/');
$lists = array();
- foreach ($response->json() as $list) {
+ foreach (json_decode($response->getBody(), true) as $list) {
$lists[] = ContactList::create($list);
}
$this->assertInstanceOf('Ctct\Components\Contacts\ContactList', $lists[0]);
@@ -52,10 +47,9 @@ public function testGetLists()
$this->assertEquals(18, $lists[1]->contact_count);
}
- public function testGetList()
- {
- $response = self::$client->get('/');
- $list = ContactList::create($response->json());
+ public function testGetList() {
+ $response = self::$client->request('GET', '/');
+ $list = ContactList::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Contacts\ContactList', $list);
$this->assertEquals(6, $list->id);
$this->assertEquals("Test List 4", $list->name);
@@ -63,10 +57,9 @@ public function testGetList()
$this->assertEquals(19, $list->contact_count);
}
- public function testAddList()
- {
- $response = self::$client->post('/');
- $list = ContactList::create($response->json());
+ public function testAddList() {
+ $response = self::$client->request('POST', '/');
+ $list = ContactList::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Contacts\ContactList', $list);
$this->assertEquals(6, $list->id);
$this->assertEquals("Test List 4", $list->name);
@@ -74,10 +67,9 @@ public function testAddList()
$this->assertEquals(19, $list->contact_count);
}
- public function testUpdateList()
- {
- $response = self::$client->put('/');
- $list = ContactList::create($response->json());
+ public function testUpdateList() {
+ $response = self::$client->request('PUT', '/');
+ $list = ContactList::create(json_decode($response->getBody(), true));
$this->assertInstanceOf('Ctct\Components\Contacts\ContactList', $list);
$this->assertEquals(6, $list->id);
$this->assertEquals("Test List 4", $list->name);
@@ -85,9 +77,8 @@ public function testUpdateList()
$this->assertEquals(19, $list->contact_count);
}
- public function testGetContactsFromList()
- {
- $response = self::$client->get('/')->json();
+ public function testGetContactsFromList() {
+ $response = json_decode(self::$client->request('GET', '/')->getBody(), true);
$result = new ResultSet($response['results'], $response['meta']);
$this->assertInstanceOf('Ctct\Components\ResultSet', $result);