Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Move base and contact lists to V3 #164

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "MIT",
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.1.1"
"guzzlehttp/guzzle": "^6.1.1 || ^7.4.1"
},
"require-dev": {
"phpunit/phpunit": "4.8.21"
Expand Down
24 changes: 24 additions & 0 deletions src/Ctct/Auth/CtctOAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,28 @@ public function getTokenInfo($accessToken) {
}
return $response;
}

public function refreshTokens($refreshToken)
{
$query = array(
'grant_type' => 'refresh_token',
'refresh_token' => $refreshToken,
);

$headers = [
'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret),
];

$baseUrl = Config::get('auth.base_url') . Config::get('auth.token_endpoint');
try {
$response = json_decode(
$this->client->request('POST', $baseUrl, compact('query', 'headers'))->getBody(),
true
);
} catch (ClientException $e) {
throw $this->convertException($e);
}

return $response;
}
}
26 changes: 19 additions & 7 deletions src/Ctct/Components/Contacts/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ class Contact extends Component {
public $source;

/**
* Array of email addresses associated with this contact
* @var EmailAddress[]
* Contact source information
* @var string
*/
public $create_source;

/**
* Email address associated with this contact
* @var EmailAddress
*/
public $email_addresses = array();
public $email_address;

/**
* The prefix name of the contact
Expand Down Expand Up @@ -119,6 +125,12 @@ class Contact extends Component {
*/
public $lists = array();

/**
* Array of contact lists IDs this contact belongs to
* @var []
*/
public $list_memberships = array();

/**
* Date the contact was created
* @var string
Expand Down Expand Up @@ -150,11 +162,11 @@ public static function create(array $props) {
$contact->last_name = parent::getValue($props, "last_name");
$contact->confirmed = parent::getValue($props, "confirmed");
$contact->source = parent::getValue($props, "source");
$contact->create_source = parent::getValue($props, "create_source");
$contact->list_memberships = parent::getValue($props, "list_memberships");

if (isset($props['email_addresses'])) {
foreach ($props['email_addresses'] as $email_address) {
$contact->email_addresses[] = EmailAddress::create($email_address);
}
if (isset($props['email_address'])) {
$contact->email_address = EmailAddress::create(parent::getValue($props, "email_address"));
}

$contact->prefix_name = parent::getValue($props, "prefix_name");
Expand Down
2 changes: 1 addition & 1 deletion src/Ctct/Components/Contacts/ContactList.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct($list_id = null) {
*/
public static function create(array $props) {
$contact_list = new ContactList();
$contact_list->id = parent::getValue($props, "id");
$contact_list->id = parent::getValue($props, "list_id");
$contact_list->name = parent::getValue($props, "name");
$contact_list->status = parent::getValue($props, "status");
$contact_list->contact_count = parent::getValue($props, "contact_count");
Expand Down
10 changes: 5 additions & 5 deletions src/Ctct/Components/Contacts/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class EmailAddress extends Component {
* Email address associated with the contact
* @var string
*/
public $email_address;
public $address;

public function __construct($email_address = null) {
if (!is_null($email_address)) {
$this->email_address = $email_address;
public function __construct($address = null) {
if (!is_null($address)) {
$this->address = $address;
}

return $this;
Expand All @@ -75,7 +75,7 @@ public static function create(array $props) {
$email_address->opt_in_source = parent::getValue($props, "opt_in_source");
$email_address->opt_in_date = parent::getValue($props, "opt_in_date");
$email_address->opt_out_date = parent::getValue($props, "opt_out_date");
$email_address->email_address = parent::getValue($props, "email_address");
$email_address->address = parent::getValue($props, "address");
return $email_address;
}
}
3 changes: 1 addition & 2 deletions src/Ctct/Services/ContactService.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ public function unsubscribeContact($accessToken, $contactId) {
*/
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::sendRequestWithBody($accessToken, 'POST', $baseUrl, $contact, $params);
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $contact);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Ctct/Services/ListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function getLists($accessToken, Array $params = array()) {
}

$lists = array();
foreach (json_decode($response->getBody(), true) as $contact) {
$lists[] = ContactList::create($contact);
foreach (json_decode($response->getBody(), true)['lists'] as $list) {
$lists[] = ContactList::create($list);
}

return $lists;
Expand Down
10 changes: 5 additions & 5 deletions src/Ctct/Util/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Config {
* REST endpoints
*/
'endpoints' => array(
'base_url' => 'https://api.constantcontact.com/v2/',
'base_url' => 'https://api.cc.email/v3/',
'account_verified_addresses' => 'account/verifiedemailaddresses',
'account_info' => 'account/info',
'activity' => 'activities/%s',
Expand All @@ -27,7 +27,7 @@ class Config {
'add_contacts_activity' => 'activities/addcontacts',
'contact' => 'contacts/%s',
'contacts' => 'contacts',
'lists' => 'lists',
'lists' => 'contact_lists',
'list' => 'lists/%s',
'list_contacts' => 'lists/%s/contacts',
'contact_lists' => 'contacts/%s/lists',
Expand Down Expand Up @@ -116,13 +116,13 @@ class Config {
* OAuth2 Authorization related configuration options
*/
'auth' => array(
'base_url' => 'https://oauth2.constantcontact.com/oauth2/',
'base_url' => 'https://idfed.constantcontact.com/as/',
'response_type_code' => 'code',
'response_type_token' => 'token',
'authorization_code_grant_type' => 'authorization_code',
'authorization_endpoint' => 'oauth/siteowner/authorize',
'token_endpoint' => 'oauth/token',
'token_info' => 'tokeninfo.htm'
'token_endpoint' => 'token.oauth2',
'token_info' => 'tokeninfo.htm',
),
/**
* Errors to be returned for various exceptions
Expand Down