Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
845ca81
Defaulting example to send welcome email
shannon7wallace Dec 9, 2015
c260d33
Update to Guzzle 6
Dec 28, 2015
bb1ff54
Code formatting (because I can)
Dec 29, 2015
10ca6dd
Minor bugfixes
Dec 29, 2015
f2707ca
Fix Travis.YML versioning
Dec 29, 2015
74f6b37
Readme fixes
Dec 29, 2015
e73034b
Merge pull request #119 from constantcontact/master
WoogieNoogie Dec 29, 2015
d2fdc4f
Merge pull request #118 from WoogieNoogie/development
shannon7wallace Dec 29, 2015
56980a8
Properly retrieve message body from Guzzle prior to calling json_deco…
chrisnetonline Jan 21, 2016
249c605
Merge pull request #121 from chrisnetonline/development
WoogieNoogie Jan 21, 2016
d002af0
Fixed the action_by parameter to use the correct syntax
Jan 22, 2016
5c36b83
Back end tracking
Feb 2, 2016
ffc3d18
Make GuzzleHttp\Client Injectable and Shared
huebs Feb 3, 2016
eb6d921
Improve ContactService Unit Tests Through Dependency Injection
huebs Feb 3, 2016
5fa31b5
Implement most of the EventSpot API
zackkatz Feb 9, 2016
81e9792
Set all variables for the EventSpot object
zackkatz Feb 11, 2016
61eb9ba
Create missing classes
zackkatz Feb 11, 2016
c251999
Add Promocode actions to EventSpotServices
zackkatz Feb 11, 2016
9749512
Tweak docBlocks
zackkatz Feb 11, 2016
db7c3de
Make sure variables are set before creating components
zackkatz Feb 12, 2016
ac2be01
Fix return type
zackkatz Feb 12, 2016
d70c412
Add a manual zip of the library and dependencies
Feb 17, 2016
09495c5
Merge remote-tracking branch 'constantcontact/development' into event…
zackkatz Mar 29, 2016
0e445d0
Fix reference
zackkatz Mar 29, 2016
f54ac3f
Update for new request structure
zackkatz Mar 29, 2016
687a61e
Merge pull request #125 from AdvisorPerspectives/use-di-for-guzzle
WoogieNoogie Mar 29, 2016
a774d35
Fix component types
zackkatz Mar 29, 2016
416da88
Fix remaining sendRequestWithBody() methods
zackkatz Mar 30, 2016
ea7e12e
Fix OAuth response being
zackkatz Apr 8, 2016
e7ef384
Merge pull request #131 from katzwebservices/eventspot
WoogieNoogie Jun 3, 2016
59c8ab6
use trusty for build and added link_uri in click response
May 3, 2020
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
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
language: php

dist: trusty
php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

env:
- GUZZLE_VERSION="5.1.0"
- GUZZLE_VERSION="6.1.1"

before_script: composer install

Expand All @@ -17,4 +18,5 @@ install:
matrix:
allow_failures:
- php: hhvm
- php: 7.0
fast_finish: true
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@
}
```

### Manual Installation
Manual installation is not recommended, as this library relies on other Composer libraries to function. Getting started with composer is easy!
Or, if you would like a more bleeding edge build, which has features like the newest version of GuzzlePHP and a minimum of PHP 5.5, you can build off our development branch.

```javascript
{
"require": {
"constantcontact/constantcontact": "dev-development"
}
}
```

If you require manual installation, it is recommended that you use [version 1](https://github.com/constantcontact/php-sdk/tree/v1-master). Composer handles all of the dependencies that this library requires in version 2.

### Manual Installation
If you are unable to install using composer, we have provided a zip file that includes a version of the dependencies at the time of our release, as well as our library. Unzip the vendor file in the standalone directory, and require the autoload.php file to use our methods.

## Documentation

Expand All @@ -39,6 +48,6 @@ $params = array("limit" => 500);
$contacts = $cc->contactService->getContacts('your access token', $params);
```
## Minimum Requirements
Use of this library requires PHP 5.4+, and PHP cURL extension (http://php.net/manual/en/book.curl.php)
Use of this library requires PHP 5.4+

If you are being required to use an older version of PHP, it is highly recommended that you update to at least 5.4 - but you can use version 1.3.* via composer, or [manually](https://github.com/constantcontact/php-sdk/tree/v1-master).
If you are being required to use an older version of PHP, it is highly recommended that you update to at least 5.4 - but you can use version 1.3.* (PHP 5.3+) via composer, or [manually](https://github.com/constantcontact/php-sdk/releases) (but note that versions 2 and up require other dependencies).
54 changes: 29 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
{
"name": "constantcontact/constantcontact",
"type": "library",
"description": "Constant Contact PHP SDK for v2",
"keywords": ["constantcontact", "ctct", "email marketing", "constant contact"],
"homepage": "http://developer.constantcontact.com",
"license": "MIT",
"require": {
"php": ">=5.4.0",
"ext-curl": "*",
"guzzlehttp/guzzle": "^5.1.0"
},
"require-dev": {
"phpunit/phpunit": "4.4.1"
},
"authors": [
{
"name": "Constant Contact Web Services",
"email": "[email protected]",
"homepage": "http://developer.constantcontact.com"
}
],
"autoload": {
"psr-0": {
"Ctct": "src"
}
"name": "constantcontact/constantcontact",
"type": "library",
"description": "Constant Contact PHP SDK for v2",
"keywords": [
"constantcontact",
"ctct",
"email marketing",
"constant contact"
],
"homepage": "http://developer.constantcontact.com",
"license": "MIT",
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.1.1"
},
"require-dev": {
"phpunit/phpunit": "4.8.21"
},
"authors": [
{
"name": "Constant Contact Web Services",
"email": "[email protected]",
"homepage": "http://developer.constantcontact.com"
}
],
"autoload": {
"psr-0": {
"Ctct": "src"
}
}
}
6 changes: 3 additions & 3 deletions examples/addOrUpdateContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
require_once '../src/Ctct/autoload.php';
require_once '../vendor/autoload.php';

use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\ConstantContact;
use Ctct\Exceptions\CtctException;

// Enter your Constant Contact APIKEY and ACCESS_TOKEN
Expand Down Expand Up @@ -64,7 +64,7 @@
*
* See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
*/
$returnContact = $cc->contactService->addContact(ACCESS_TOKEN, $contact);
$returnContact = $cc->contactService->addContact(ACCESS_TOKEN, $contact, true);

// update the existing contact if address already existed
} else {
Expand All @@ -83,7 +83,7 @@
*
* See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
*/
$returnContact = $cc->contactService->updateContact(ACCESS_TOKEN, $contact);
$returnContact = $cc->contactService->updateContact(ACCESS_TOKEN, $contact, true);
} else {
$e = new CtctException();
$e->setErrors(array("type", "Contact type not returned"));
Expand Down
11 changes: 4 additions & 7 deletions examples/createAndScheduleCampaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
require_once '../src/Ctct/autoload.php';
require_once '../vendor/autoload.php';

use Ctct\ConstantContact;
use Ctct\Components\EmailMarketing\Campaign;
use Ctct\Components\EmailMarketing\Schedule;
use Ctct\ConstantContact;
use Ctct\Exceptions\CtctException;

// Enter your Constant Contact APIKEY and ACCESS_TOKEN
Expand All @@ -38,8 +38,7 @@
* @param array $params associative array of parameters to create a campaign from
* @return Campaign updated by server
*/
function createCampaign(array $params = array())
{
function createCampaign(array $params = array()) {
$cc = new ConstantContact(APIKEY);
$campaign = new Campaign();
$campaign->name = $params['name'];
Expand Down Expand Up @@ -72,8 +71,7 @@ function createCampaign(array $params = array())
* @param $time - ISO 8601 formatted timestamp of when the campaign should be sent
* @return Schedule updated by server
*/
function createSchedule($campaignId, $time)
{
function createSchedule($campaignId, $time) {
$cc = new ConstantContact(APIKEY);
$schedule = new Schedule();
$schedule->scheduled_date = $time;
Expand Down Expand Up @@ -204,8 +202,7 @@ function createSchedule($campaignId, $time)

<div class="controls">
<input type="text" name="schedule_time" id="schedule_time"
value="<?php echo date('Y-m-d\TH:i:s\.000\Z', strtotime("+1 month"));
; ?>"/>
value="<?php echo date('Y-m-d\TH:i:s\.000\Z', strtotime("+1 month"));; ?>"/>
</div>
</div>
<div class="control-group">
Expand Down
8 changes: 4 additions & 4 deletions examples/getAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
if (isset($_GET['error'])) {
echo '<span class="label label-important">OAuth2 Error!</span>';
echo '<div class="container alert-error"><pre class="failure-pre">';
echo 'Error: ' . htmlspecialchars( $_GET['error'] );
echo '<br />Description: ' . htmlspecialchars( $_GET['error_description'] );
echo 'Error: ' . htmlspecialchars($_GET['error']);
echo '<br />Description: ' . htmlspecialchars($_GET['error_description']);
echo '</pre></div>';
die();
}
Expand All @@ -52,14 +52,14 @@
} catch (OAuth2Exception $ex) {
echo '<span class="label label-important">OAuth2 Error!</span>';
echo '<div class="container alert-error"><pre class="failure-pre">';
echo 'Error: ' . htmlspecialchars( $ex->getMessage() );
echo 'Error: ' . htmlspecialchars($ex->getMessage());
echo '</pre></div>';
die();
}

echo '<span class="label label-success">Access Token Retrieved!</span>';
echo '<div class="container alert-success"><pre class="success-pre">';
print_r( htmlspecialchars( $accessToken ) );
print_r(htmlspecialchars($accessToken));
echo '</pre></div>';

} else {
Expand Down
7 changes: 4 additions & 3 deletions examples/uploadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
<div class="well">
<h3>Upload a New Image or PDF</h3>

<form class="form-horizontal" name="submitFile" id="submitFile" method="POST" action="uploadFile.php" enctype="multipart/form-data">
<form class="form-horizontal" name="submitFile" id="submitFile" method="POST" action="uploadFile.php"
enctype="multipart/form-data">
<div class="control-group">
<label class="control-label" for="file_name">File Name</label>

Expand Down Expand Up @@ -103,8 +104,8 @@
<?php
// print the contents of the file upload status to screen
if (isset($fileUploadStatus)) {
echo '<span class="label label-success">File Uploaded!</span>';
echo '<div class="container alert-success"><pre class="success-pre">';
echo '<span class="label label-success">File Uploaded!</span>';
echo '<div class="container alert-success"><pre class="success-pre">';
foreach ($fileUploadStatus as $status) {
print_r($status);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Ctct/Auth/CtctDataStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
* @author Constant Contact
*/

interface CtctDataStore
{

interface CtctDataStore {
/**
* Add a new user to the data store
* @param $id - unique identifier
Expand Down
54 changes: 23 additions & 31 deletions src/Ctct/Auth/CtctOAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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;
}

/**
Expand All @@ -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,
Expand All @@ -72,46 +67,43 @@ 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);
}

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;
}
}
Loading