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

Commit

Permalink
Minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Galbraith committed Dec 29, 2015
1 parent bb1ff54 commit 10ca6dd
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -12,7 +12,7 @@
"license": "MIT",
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "~6.0"
"guzzlehttp/guzzle": "^6.1.1"
},
"require-dev": {
"phpunit/phpunit": "4.8.21"
Expand Down
2 changes: 1 addition & 1 deletion src/Ctct/Services/AccountService.php
Expand Up @@ -98,7 +98,7 @@ public function getAccountInfo($accessToken) {
public function updateAccountInfo($accessToken, AccountInfo $accountInfo) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.account_info');

$request = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, json_decode(json_encode($accountInfo), true));
$request = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, $accountInfo);

try {
$response = parent::getClient()->send($request);
Expand Down
4 changes: 2 additions & 2 deletions src/Ctct/Services/ActivityService.php
Expand Up @@ -73,7 +73,7 @@ public function createAddContactsActivity($accessToken, AddContacts $addContacts
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.add_contacts_activity');

try {
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, json_decode(json_encode($addContacts), true));
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $addContacts);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand Down Expand Up @@ -144,7 +144,7 @@ public function addExportContactsActivity($accessToken, ExportContacts $exportCo
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.export_contacts_activity');

try {
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, json_decode(json_encode($exportContacts), true));
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $exportContacts);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ctct/Services/BaseService.php
Expand Up @@ -52,7 +52,7 @@ protected function getClient() {
return $this->client;
}

protected function sendRequestWithBody($accessToken, $method, $baseUrl, Array $body, Array $queryParams = array()) {
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, [
Expand Down
6 changes: 3 additions & 3 deletions src/Ctct/Services/CampaignScheduleService.php
Expand Up @@ -26,7 +26,7 @@ public function addSchedule($accessToken, $campaignId, Schedule $schedule) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_schedules'), $campaignId);

try {
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, json_decode(json_encode($schedule), true));
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $schedule);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public function updateSchedule($accessToken, $campaignId, Schedule $schedule) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_schedule'), $campaignId, $schedule->id);

try {
$response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, json_decode(json_encode($schedule), true));
$response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, $schedule);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand Down Expand Up @@ -129,7 +129,7 @@ public function sendTest($accessToken, $campaignId, TestSend $testSend) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_test_sends'), $campaignId);

try {
$response = parent::sendRequestWithoutBody($accessToken, 'POST', $baseUrl, json_decode(json_encode($testSend), true));
$response = parent::sendRequestWithoutBody($accessToken, 'POST', $baseUrl, $testSend);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand Down
44 changes: 20 additions & 24 deletions src/Ctct/Services/ContactService.php
Expand Up @@ -95,63 +95,59 @@ public function getContact($accessToken, $contactId) {
}

/**
* 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');
public function unsubscribeContact($accessToken, $contactId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact'), $contactId);

try {
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, json_decode(json_encode($contact), true), $params);
$response = parent::sendRequestWithoutBody($accessToken, 'DELETE', $baseUrl);
} catch (TransferException $e) {
throw parent::convertException($e);
}

return Contact::create(json_decode($response->getBody(), true));
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 othe email address
* @return Contact
* @throws CtctException
*/
public function unsubscribeContact($accessToken, $contactId) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact'), $contactId);
public function addContact($accessToken, Contact $contact, $actionByContact) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.contacts');
$params["action_by"] = ($actionByContact ? true : false);

try {
$response = parent::sendRequestWithoutBody($accessToken, 'DELETE', $baseUrl);
$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);
$params["action_by"] = ($actionByContact ? true : false);

try {
$response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, json_decode(json_encode($contact), true), $params);
$response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, $contact, $params);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Ctct/Services/EmailMarketingService.php
Expand Up @@ -30,7 +30,7 @@ public function addCampaign($accessToken, Campaign $campaign) {
}

try {
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, json_decode(json_encode($campaign), true));
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $campaign);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand Down Expand Up @@ -116,7 +116,7 @@ public function updateCampaign($accessToken, Campaign $campaign) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign'), $campaign->id);

try {
$response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, json_decode(json_encode($campaign), true));
$response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, $campaign);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ctct/Services/LibraryService.php
Expand Up @@ -249,7 +249,7 @@ public function createLibraryFolder($accessToken, Folder $folder) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.library_folders');

try {
$response = parent::sendRequestWithBody($accessToken, "POST", $baseUrl, json_decode(json_encode($folder), true));
$response = parent::sendRequestWithBody($accessToken, "POST", $baseUrl, $folder);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Ctct/Services/ListService.php
Expand Up @@ -50,7 +50,7 @@ public function addList($accessToken, ContactList $list) {
$baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.lists');

try {
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, json_decode(json_encode($list), true));
$response = parent::sendRequestWithBody($accessToken, 'POST', $baseUrl, $list);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand All @@ -69,7 +69,7 @@ public function updateList($accessToken, ContactList $list) {
$baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list'), $list->id);

try {
$response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, json_decode(json_encode($list), true));
$response = parent::sendRequestWithBody($accessToken, 'PUT', $baseUrl, $list);
} catch (TransferException $e) {
throw parent::convertException($e);
}
Expand Down

0 comments on commit 10ca6dd

Please sign in to comment.