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

Commit d05bf74

Browse files
committed
Merge pull request #104 from WoogieNoogie/guzzle-development
Version 2.0.0
2 parents 0aa1c72 + 835c096 commit d05bf74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2432
-2731
lines changed

.gitignore

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
# Created by .gitignore support plugin (hsz.mobi)
2-
### JetBrains template
3-
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
42

53
## Directory-based project format
64
.idea/
75
/*.iml
8-
# if you remove the above rule, at least ignore user-specific stuff:
9-
# .idea/workspace.xml
10-
# .idea/tasks.xml
11-
# .idea/dictionaries
12-
# and these sensitive or high-churn files:
13-
# .idea/dataSources.ids
14-
# .idea/dataSources.xml
15-
# .idea/sqlDataSources.xml
16-
# .idea/dynamic.xml
17-
# and, if using gradle::
18-
# .idea/gradle.xml
19-
# .idea/libraries
206

217
## File-based project format
228
*.ipr
@@ -31,5 +17,9 @@ out/
3117
# generated by JIRA plugin
3218
atlassian-ide-plugin.xml
3319

34-
# generated by Crashlytics plugin (for Android Studio and Intellij)
35-
com_crashlytics_export_strings.xml
20+
### Composer template
21+
composer.lock
22+
composer.phar
23+
vendor/
24+
25+
devFile.php

.travis.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
language: php
2+
23
php:
3-
- "5.4"
4-
- "5.3"
5-
- "5.5"
6-
- hhvm
4+
- 5.4
5+
- 5.5
6+
- 5.6
7+
- hhvm
8+
9+
env:
10+
- GUZZLE_VERSION="5.1.0"
11+
12+
before_script: composer install
13+
14+
install:
15+
- composer require guzzlehttp/guzzle:${GUZZLE_VERSION}
16+
17+
matrix:
18+
allow_failures:
19+
- php: hhvm
20+
fast_finish: true

README.md

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,22 @@
11
# Constant Contact PHP SDK
2-
[![Build Status](https://secure.travis-ci.org/constantcontact/php-sdk.png?branch=master)](http://travis-ci.org/constantcontact/php-sdk)
2+
[![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)
33

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

6-
### Manual Installation
7-
1. Download and extract the project into an appropriate place in your application.
8-
2. Require the SDK's autoloader. (note: the path to include the autoload may be different depending on the structure of your application)
9-
```
10-
require '/src/Ctct/autoload.php'
11-
```
12-
13-
### Installing via Composer
14-
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
15-
16-
1. Add "constantcontact/constantcontact" as a dependency in your project's composer.json file.
6+
## Installing via Composer
7+
[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.
178
```javascript
189
{
1910
"require": {
20-
"constantcontact/constantcontact": "1.3.*"
11+
"constantcontact/constantcontact": "2.0.*"
2112
}
2213
}
2314
```
2415

25-
2. Download and Install Composer.
26-
```
27-
curl -s "http://getcomposer.org/installer" | php
28-
```
29-
30-
3. Install your dependencies by executing the following in your project root.
31-
```
32-
php composer.phar install
33-
```
16+
### Manual Installation
17+
Manual installation is not recommended, as this library relies on other Composer libraries to function. Getting started with composer is easy!
3418

35-
4. Require Composer's autoloader.
36-
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.
37-
```
38-
require 'vendor/autoload.php';
39-
```
19+
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.
4020

4121
## Documentation
4222

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

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

53-
$contacts = $cc->getContacts('your access token')
33+
$contacts = $cc->contactService->getContacts('your access token')
34+
```
35+
36+
Many methods will take an array of parameters for use in the calls. Available params are documented in the PHPDoc of the method.
37+
```php
38+
$params = array("limit" => 500);
39+
$contacts = $cc->contactService->getContacts('your access token', $params);
5440
```
5541
## Minimum Requirements
56-
Use of this library requires PHP 5.3+, and PHP cURL extension (http://php.net/manual/en/book.curl.php)
42+
Use of this library requires PHP 5.4+, and PHP cURL extension (http://php.net/manual/en/book.curl.php)
43+
44+
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).

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
"homepage": "http://developer.constantcontact.com",
77
"license": "MIT",
88
"require": {
9-
"php": ">=5.3.0",
10-
"ext-curl": "*"
9+
"php": ">=5.4.0",
10+
"ext-curl": "*",
11+
"guzzlehttp/guzzle": "5.1.0"
12+
},
13+
"require-dev": {
14+
"phpunit/phpunit": "4.4.1"
1115
},
1216
"authors": [
1317
{

examples/addOrUpdateContact.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
-->
1515

1616
<?php
17-
// require the autoloader
17+
// require the autoloaders
1818
require_once '../src/Ctct/autoload.php';
19+
require_once '../vendor/autoload.php';
1920

2021
use Ctct\ConstantContact;
2122
use Ctct\Components\Contacts\Contact;
22-
use Ctct\Components\Contacts\ContactList;
23-
use Ctct\Components\Contacts\EmailAddress;
2423
use Ctct\Exceptions\CtctException;
2524

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

3231
// attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
3332
try {
34-
$lists = $cc->getLists(ACCESS_TOKEN);
33+
$lists = $cc->listService->getLists(ACCESS_TOKEN);
3534
} catch (CtctException $ex) {
3635
foreach ($ex->getErrors() as $error) {
3736
print_r($error);
3837
}
38+
if (!isset($lists)) {
39+
$lists = null;
40+
}
3941
}
4042

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

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

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

71-
$contact = $response->results[0];
73+
$contact = Contact::create($response->results[0]);
7274
$contact->addList($_POST['list']);
7375
$contact->first_name = $_POST['first_name'];
7476
$contact->last_name = $_POST['last_name'];
@@ -80,7 +82,7 @@
8082
*
8183
* See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
8284
*/
83-
$returnContact = $cc->updateContact(ACCESS_TOKEN, $contact, true);
85+
$returnContact = $cc->contactService->updateContact(ACCESS_TOKEN, $contact);
8486
}
8587

8688
// catch any exceptions thrown during the process and print the errors to screen

examples/createAndScheduleCampaign.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
-->
1818

1919
<?php
20-
// require the autoloader
20+
// require the autoloaders
2121
require_once '../src/Ctct/autoload.php';
22+
require_once '../vendor/autoload.php';
2223

2324
use Ctct\ConstantContact;
24-
use Ctct\Components\Contacts\ContactList;
2525
use Ctct\Components\EmailMarketing\Campaign;
26-
use Ctct\Components\EmailMarketing\MessageFooter;
2726
use Ctct\Components\EmailMarketing\Schedule;
2827
use Ctct\Exceptions\CtctException;
2928

@@ -37,8 +36,9 @@
3736
/**
3837
* Create an email campaign with the parameters provided
3938
* @param array $params associative array of parameters to create a campaign from
39+
* @return Campaign updated by server
4040
*/
41-
function createCampaign(array $params)
41+
function createCampaign(array $params = array())
4242
{
4343
$cc = new ConstantContact(APIKEY);
4444
$campaign = new Campaign();
@@ -63,20 +63,21 @@ function createCampaign(array $params)
6363
}
6464
}
6565

66-
return $cc->addEmailCampaign(ACCESS_TOKEN, $campaign);
66+
return $cc->emailMarketingService->addCampaign(ACCESS_TOKEN, $campaign);
6767
}
6868

6969
/**
7070
* Create a schedule for a campaign - this is time the campaign will be sent out
7171
* @param $campaignId - Id of the campaign to be scheduled
7272
* @param $time - ISO 8601 formatted timestamp of when the campaign should be sent
73+
* @return Schedule updated by server
7374
*/
7475
function createSchedule($campaignId, $time)
7576
{
7677
$cc = new ConstantContact(APIKEY);
7778
$schedule = new Schedule();
7879
$schedule->scheduled_date = $time;
79-
return $cc->addEmailCampaignSchedule(ACCESS_TOKEN, $campaignId, $schedule);
80+
return $cc->campaignScheduleService->addSchedule(ACCESS_TOKEN, $campaignId, $schedule);
8081
}
8182

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

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

213214
<div class="controls">
214-
<input type="radio" id="name" name="format" value="HTML" checked> HTML </input>
215-
<input type="radio" id="name" name="format" value="XHTML"> XHTML </input>
215+
<input type="radio" id="name" name="format" value="HTML" checked> HTML
216+
<input type="radio" id="name" name="format" value="XHTML"> XHTML
216217
</div>
217218
</div>
218219
</fieldset>

examples/getAccessToken.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
-->
1515

1616
<?php
17-
// require the autloader
17+
// require the autoloaders
1818
require_once '../src/Ctct/autoload.php';
19+
require_once '../vendor/autoload.php';
1920

2021
use Ctct\Auth\CtctOAuth2;
2122
use Ctct\Exceptions\OAuth2Exception;

0 commit comments

Comments
 (0)