2017-25 © Pedro Peláez
 

library constantcontact-php-client

Wrapper around Guzzle Http Client to interact with Constant Contact APIv2

image

classy-org/constantcontact-php-client

Wrapper around Guzzle Http Client to interact with Constant Contact APIv2

  • Tuesday, May 1, 2018
  • by sholman
  • Repository
  • 4 Watchers
  • 0 Stars
  • 537 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 607 % Grown

The README.md

ConstantContact PHP Client Build Status

Wrapper around Guzzle Http Client to interact with Constant Contact APIv2, (*1)

Installation

The ConstantContact API php client can be installed with Composer:, (*2)

composer require classy-org/constantcontact-php-client

Be sure you included composer autoloader in your app:, (*3)

require_once '/path/to/your/project/vendor/autoload.php';

Usage

// Instantiate the client
$client = new \Classy\ConstantContactClient('API-KEY', 'ACCESS-TOKEN');

// Make a request. 
$httpResponse = $client->request('GET', 'contacts');
$contacts = json_decode($httpResponse->getBody()->getContents());

//Or Grab Data Quickly.
$contacts = $client->getData('contacts');

//Store a Contact Quickly.
$payload = [
    'lists' => [
        [
            'id' => (string)1
        ]
    ],
    'email_addresses' => [
        [
            'email_address' => (string)'person@constantcontact.com'
        ]
    ],
    'first_name' => (string)'My',
    'last_name'  => (string)'Name',
];
$contacts = $client->addContact($payload);

Exception handling

This client is using Guzzle Http client. Exceptions are thrown when the Http response is not a 200 (OK) one:, (*4)

try {
    $response = $client->request('POST', 'path/to/route', ['body' => ['check' => 1]]);
} catch (Exception $e) {
    if ($e instanceof \GuzzleHttp\Exception\ConnectException) {
        // there was a networking error
    }

    if ($e instanceof \GuzzleHttp\Exception\ClientException) {
        // Mailchimp API returned a 4xx response.
        $httpStatusCode = $e->getCode();
        if ($httpStatusCode == 404) {
            // resource doesn't exist
        }
        if ($httpStatusCode == 401) {
            // you're unauthorized (api key must be invalid)
        }
        if ($httpStatusCode == 403) {
            // you're not allowed to request this endpoint
        }
        if ($httpStatusCode == 400) {
            // body payload is invalid
        }
        if (...) {
            //
        }

        $bodyResponse = $e->getResponse()->getBody()->getContents();
    }

    if ($e instanceof \GuzzleHttp\Exception\ServerException) {
        // ConstantContact returned a 5xx response, which means they experience technical difficulties.
    }
}

The Versions

01/05 2018

dev-master

9999999-dev

Wrapper around Guzzle Http Client to interact with Constant Contact APIv2

  Sources   Download

The Requires

 

The Development Requires

by Steven Holman

01/05 2018

1.1.0

1.1.0.0

Wrapper around Guzzle Http Client to interact with Constant Contact APIv2

  Sources   Download

The Requires

 

The Development Requires

by Steven Holman

30/04 2018

1.0.2

1.0.2.0

Wrapper around Guzzle Http Client to interact with Constant Contact APIv2

  Sources   Download

The Requires

 

The Development Requires

by Steven Holman

26/04 2018

1.0.1

1.0.1.0

Wrapper around Guzzle Http Client to interact with Constant Contact APIv2

  Sources   Download

The Requires

 

The Development Requires

by Steven Holman