Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.
Merged
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
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
language: php

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 +17,5 @@ install:
matrix:
allow_failures:
- php: hhvm
- php: 7.0
fast_finish: true
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
}
```

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"
}
}
```


### Manual Installation
Manual installation is not recommended, as this library relies on other Composer libraries to function. Getting started with composer is easy!

Expand All @@ -39,6 +50,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": "webservices@constantcontact.com",
"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": "webservices@constantcontact.com",
"homepage": "http://developer.constantcontact.com"
}
],
"autoload": {
"psr-0": {
"Ctct": "src"
}
}
}
2 changes: 1 addition & 1 deletion 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
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
]), 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()));
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)
]), 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;
}
}
18 changes: 6 additions & 12 deletions src/Ctct/Auth/SessionDataStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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;
}

Expand All @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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]);
}
}
Loading