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

Commit

Permalink
Merge pull request #105 from constantcontact/development
Browse files Browse the repository at this point in the history
Merge to Master
  • Loading branch information
WoogieNoogie committed Jun 30, 2015
2 parents 053b457 + d05bf74 commit 671e2ea
Show file tree
Hide file tree
Showing 60 changed files with 2,432 additions and 2,731 deletions.
22 changes: 6 additions & 16 deletions .gitignore
@@ -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
@@ -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
@@ -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
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
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
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
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

0 comments on commit 671e2ea

Please sign in to comment.