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
Show all changes
34 commits
Select commit Hold shift + click to select a range
6bd14a7
Migrating to Guzzle
Jan 5, 2015
6fa29bc
Added multipart file uploads to Activities and Library
Jan 9, 2015
0935163
Add PHPunit as a dev-only dependency
Jan 9, 2015
6913a69
Finish tests
Jan 11, 2015
630f33f
PHPUnit fixes for TravisCI
Jan 11, 2015
476b758
PHPUnit fixes for TravisCI
Jan 11, 2015
6f5445f
PHPUnit fixes for TravisCI
Jan 11, 2015
1148a38
PHPUnit fixes for TravisCI
Jan 11, 2015
f560f19
PHPUnit fixes for TravisCI
Jan 11, 2015
608108d
PHPUnit fixes for TravisCI - at least trying
Jan 11, 2015
f92c797
Update minimum PHP version to 5.4
Jan 12, 2015
6e78b01
Add PHP 5.6 to tests
Jan 12, 2015
693fb93
YML formatting
Jan 12, 2015
7af1fbc
Fixed 2 bugs in the wrapper and added an example file
Jan 12, 2015
354e545
Update PHPUnit version, copyright, and Readme
Jan 12, 2015
d879fde
Update readme to include some Poser badges
Jan 13, 2015
45a381b
Correctly Json encode the array of the array because array
Jan 14, 2015
d090c94
Fix serialization names of variables
Jan 14, 2015
cdb5b72
Fix serialization names of variables
Jan 14, 2015
d922d3a
Merge remote-tracking branch 'ctct/development' into guzzle-development
Jan 14, 2015
7cc6655
Consume ClientException into CtctException
Jan 15, 2015
1c73687
Remove unused classes
Jan 16, 2015
7eefd22
Pushed details and usage into the services
Jan 24, 2015
2322ce5
Scope change
Jan 24, 2015
8af2143
Readme update
Jan 24, 2015
009c5a7
Better types for IDE and code cleanup
Jan 25, 2015
00ac571
Merge remote-tracking branch 'ctct/development' into guzzle-development
Jun 29, 2015
80d30ab
Merge remote-tracking branch 'ctct/development' into guzzle-development
Jun 29, 2015
4d46ee5
Update README and rebase from dev
Jun 29, 2015
b7d8b85
Update README
Jun 29, 2015
2e5ffa1
Fix add contact method
Jun 30, 2015
8f550f8
Fix campaign bug
Jun 30, 2015
e098088
Add birthday and anniversary to config logic
Jun 30, 2015
835c096
Update Readme
Jun 30, 2015
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
22 changes: 6 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
# Created by .gitignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

## Directory-based project format
.idea/
/*.iml
# if you remove the above rule, at least ignore user-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
# and these sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# and, if using gradle::
# .idea/gradle.xml
# .idea/libraries

## File-based project format
*.ipr
Expand All @@ -31,5 +17,9 @@ out/
# generated by JIRA plugin
atlassian-ide-plugin.xml

# generated by Crashlytics plugin (for Android Studio and Intellij)
com_crashlytics_export_strings.xml
### Composer template
composer.lock
composer.phar
vendor/

devFile.php
22 changes: 18 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
language: php

php:
- "5.4"
- "5.3"
- "5.5"
- hhvm
- 5.4
- 5.5
- 5.6
- hhvm

env:
- GUZZLE_VERSION="5.1.0"

before_script: composer install

install:
- composer require guzzlehttp/guzzle:${GUZZLE_VERSION}

matrix:
allow_failures:
- php: hhvm
fast_finish: true
50 changes: 19 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,22 @@
# Constant Contact PHP SDK
[![Build Status](https://secure.travis-ci.org/constantcontact/php-sdk.png?branch=master)](http://travis-ci.org/constantcontact/php-sdk)
[![Build Status](https://secure.travis-ci.org/constantcontact/php-sdk.png?branch=master)](http://travis-ci.org/constantcontact/php-sdk) [![Latest Stable Version](https://poser.pugx.org/constantcontact/constantcontact/v/stable.svg)](https://packagist.org/packages/constantcontact/constantcontact) [![Latest Unstable Version](https://poser.pugx.org/constantcontact/constantcontact/v/unstable.svg)](https://packagist.org/packages/constantcontact/constantcontact)

## Installation
### This library utilizes [GuzzlePHP](https://guzzlephp.org)

### Manual Installation
1. Download and extract the project into an appropriate place in your application.
2. Require the SDK's autoloader. (note: the path to include the autoload may be different depending on the structure of your application)
```
require '/src/Ctct/autoload.php'
```

### Installing via Composer
Composer is a dependency management tool for PHP that allows you to declare the dependencies your project needs and installs them into your project. In order to use the Constant Contact PHP SDK through composer, you must do the following

1. Add "constantcontact/constantcontact" as a dependency in your project's composer.json file.
## Installing via Composer
[Composer](https://getcomposer.org/) is a dependency management tool for PHP that allows you to declare the dependencies your project needs and installs them into your project. In order to use the Constant Contact PHP SDK through composer, you must add "constantcontact/constantcontact" as a dependency in your project's composer.json file.
```javascript
{
"require": {
"constantcontact/constantcontact": "1.3.*"
"constantcontact/constantcontact": "2.0.*"
}
}
```

2. Download and Install Composer.
```
curl -s "http://getcomposer.org/installer" | php
```

3. Install your dependencies by executing the following in your project root.
```
php composer.phar install
```
### Manual Installation
Manual installation is not recommended, as this library relies on other Composer libraries to function. Getting started with composer is easy!

4. Require Composer's autoloader.
Composer also prepares an autoload file that's capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process.
```
require 'vendor/autoload.php';
```
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.

## Documentation

Expand All @@ -45,12 +25,20 @@ The source documentation is hosted at http://constantcontact.github.io/php-sdk
API Documentation is located at http://developer.constantcontact.com/docs/developer-guides/api-documentation-index.html

## Usage
Once either the composer or built in autoloader has been required, you can begin using the SDK.
The ConstantContact class contains the underlying services that hold the methods that use the API.
```php
use Ctct\ConstantContact;
$cc = new ConstantContact('your api key');

$contacts = $cc->getContacts('your access token')
$contacts = $cc->contactService->getContacts('your access token')
```

Many methods will take an array of parameters for use in the calls. Available params are documented in the PHPDoc of the method.
```php
$params = array("limit" => 500);
$contacts = $cc->contactService->getContacts('your access token', $params);
```
## Minimum Requirements
Use of this library requires PHP 5.3+, and PHP cURL extension (http://php.net/manual/en/book.curl.php)
Use of this library requires PHP 5.4+, and PHP cURL extension (http://php.net/manual/en/book.curl.php)

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).
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
"homepage": "http://developer.constantcontact.com",
"license": "MIT",
"require": {
"php": ">=5.3.0",
"ext-curl": "*"
"php": ">=5.4.0",
"ext-curl": "*",
"guzzlehttp/guzzle": "5.1.0"
},
"require-dev": {
"phpunit/phpunit": "4.4.1"
},
"authors": [
{
Expand Down
20 changes: 11 additions & 9 deletions examples/addOrUpdateContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
-->

<?php
// require the autoloader
// require the autoloaders
require_once '../src/Ctct/autoload.php';
require_once '../vendor/autoload.php';

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

// Enter your Constant Contact APIKEY and ACCESS_TOKEN
Expand All @@ -31,19 +30,22 @@

// attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
try {
$lists = $cc->getLists(ACCESS_TOKEN);
$lists = $cc->listService->getLists(ACCESS_TOKEN);
} catch (CtctException $ex) {
foreach ($ex->getErrors() as $error) {
print_r($error);
}
if (!isset($lists)) {
$lists = null;
}
}

// check if the form was submitted
if (isset($_POST['email']) && strlen($_POST['email']) > 1) {
$action = "Getting Contact By Email Address";
try {
// check to see if a contact with the email addess already exists in the account
$response = $cc->getContactByEmail(ACCESS_TOKEN, $_POST['email']);
// check to see if a contact with the email address already exists in the account
$response = $cc->contactService->getContacts(ACCESS_TOKEN, array("email" => $_POST['email']));

// create a new contact if one does not exist
if (empty($response->results)) {
Expand All @@ -62,13 +64,13 @@
*
* See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
*/
$returnContact = $cc->addContact(ACCESS_TOKEN, $contact, true);
$returnContact = $cc->contactService->addContact(ACCESS_TOKEN, $contact);

// update the existing contact if address already existed
} else {
$action = "Updating Contact";

$contact = $response->results[0];
$contact = Contact::create($response->results[0]);
$contact->addList($_POST['list']);
$contact->first_name = $_POST['first_name'];
$contact->last_name = $_POST['last_name'];
Expand All @@ -80,7 +82,7 @@
*
* See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
*/
$returnContact = $cc->updateContact(ACCESS_TOKEN, $contact, true);
$returnContact = $cc->contactService->updateContact(ACCESS_TOKEN, $contact);
}

// catch any exceptions thrown during the process and print the errors to screen
Expand Down
19 changes: 10 additions & 9 deletions examples/createAndScheduleCampaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
-->

<?php
// require the autoloader
// require the autoloaders
require_once '../src/Ctct/autoload.php';
require_once '../vendor/autoload.php';

use Ctct\ConstantContact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\EmailMarketing\Campaign;
use Ctct\Components\EmailMarketing\MessageFooter;
use Ctct\Components\EmailMarketing\Schedule;
use Ctct\Exceptions\CtctException;

Expand All @@ -37,8 +36,9 @@
/**
* Create an email campaign with the parameters provided
* @param array $params associative array of parameters to create a campaign from
* @return Campaign updated by server
*/
function createCampaign(array $params)
function createCampaign(array $params = array())
{
$cc = new ConstantContact(APIKEY);
$campaign = new Campaign();
Expand All @@ -63,20 +63,21 @@ function createCampaign(array $params)
}
}

return $cc->addEmailCampaign(ACCESS_TOKEN, $campaign);
return $cc->emailMarketingService->addCampaign(ACCESS_TOKEN, $campaign);
}

/**
* Create a schedule for a campaign - this is time the campaign will be sent out
* @param $campaignId - Id of the campaign to be scheduled
* @param $time - ISO 8601 formatted timestamp of when the campaign should be sent
* @return Schedule updated by server
*/
function createSchedule($campaignId, $time)
{
$cc = new ConstantContact(APIKEY);
$schedule = new Schedule();
$schedule->scheduled_date = $time;
return $cc->addEmailCampaignSchedule(ACCESS_TOKEN, $campaignId, $schedule);
return $cc->campaignScheduleService->addSchedule(ACCESS_TOKEN, $campaignId, $schedule);
}

// check to see if the form was submitted
Expand Down Expand Up @@ -108,7 +109,7 @@ function createSchedule($campaignId, $time)

// attempt to get the lists in this account, displaying any errors that occur
try {
$lists = $cc->getLists(ACCESS_TOKEN);
$lists = $cc->listService->getLists(ACCESS_TOKEN);
} catch (CtctException $ex) {
echo '<div class="container alert-error"><pre class="failure-pre">';
print_r($ex->getErrors());
Expand Down Expand Up @@ -211,8 +212,8 @@ function createSchedule($campaignId, $time)
<label class="control-label" for="format">Email Content Format</label>

<div class="controls">
<input type="radio" id="name" name="format" value="HTML" checked> HTML </input>
<input type="radio" id="name" name="format" value="XHTML"> XHTML </input>
<input type="radio" id="name" name="format" value="HTML" checked> HTML
<input type="radio" id="name" name="format" value="XHTML"> XHTML
</div>
</div>
</fieldset>
Expand Down
3 changes: 2 additions & 1 deletion examples/getAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
-->

<?php
// require the autloader
// require the autoloaders
require_once '../src/Ctct/autoload.php';
require_once '../vendor/autoload.php';

use Ctct\Auth\CtctOAuth2;
use Ctct\Exceptions\OAuth2Exception;
Expand Down
Loading