Overview

Namespaces

  • Ctct
    • Auth
    • Components
      • Account
      • Activities
      • Contacts
      • EmailMarketing
      • Library
      • Tracking
    • Exceptions
    • Services
    • Util
    • WebHooks

Classes

  • Ctct\Auth\CtctOAuth2
  • Ctct\Auth\SessionDataStore
  • Ctct\Components\Account\AccountInfo
  • Ctct\Components\Account\VerifiedEmailAddress
  • Ctct\Components\Activities\Activity
  • Ctct\Components\Activities\ActivityError
  • Ctct\Components\Activities\AddContacts
  • Ctct\Components\Activities\AddContactsImportData
  • Ctct\Components\Activities\ExportContacts
  • Ctct\Components\Component
  • Ctct\Components\Contacts\Address
  • Ctct\Components\Contacts\Contact
  • Ctct\Components\Contacts\ContactList
  • Ctct\Components\Contacts\CustomField
  • Ctct\Components\Contacts\EmailAddress
  • Ctct\Components\Contacts\Note
  • Ctct\Components\EmailMarketing\Campaign
  • Ctct\Components\EmailMarketing\ClickThroughDetails
  • Ctct\Components\EmailMarketing\MessageFooter
  • Ctct\Components\EmailMarketing\Schedule
  • Ctct\Components\EmailMarketing\TestSend
  • Ctct\Components\Library\File
  • Ctct\Components\Library\FileUploadStatus
  • Ctct\Components\Library\Folder
  • Ctct\Components\Library\Thumbnail
  • Ctct\Components\ResultSet
  • Ctct\Components\Tracking\BounceActivity
  • Ctct\Components\Tracking\ClickActivity
  • Ctct\Components\Tracking\ForwardActivity
  • Ctct\Components\Tracking\OpenActivity
  • Ctct\Components\Tracking\SendActivity
  • Ctct\Components\Tracking\TrackingActivity
  • Ctct\Components\Tracking\TrackingSummary
  • Ctct\Components\Tracking\UnsubscribeActivity
  • Ctct\ConstantContact
  • Ctct\Services\AccountService
  • Ctct\Services\ActivityService
  • Ctct\Services\BaseService
  • Ctct\Services\CampaignScheduleService
  • Ctct\Services\CampaignTrackingService
  • Ctct\Services\ContactService
  • Ctct\Services\ContactTrackingService
  • Ctct\Services\EmailMarketingService
  • Ctct\Services\LibraryService
  • Ctct\Services\ListService
  • Ctct\SplClassLoader
  • Ctct\Util\Config
  • Ctct\WebHooks\CTCTWebhookUtil

Interfaces

  • Ctct\Auth\CtctDataStore

Exceptions

  • Ctct\Exceptions\CtctException
  • Ctct\Exceptions\IllegalArgumentException
  • Ctct\Exceptions\OAuth2Exception
  • Overview
  • Namespace
  • Class
 1: <?php
 2: namespace Ctct\Services;
 3: 
 4: use Ctct\Exceptions\CtctException;
 5: use Ctct\Util\Config;
 6: use GuzzleHttp\Client;
 7: use GuzzleHttp\Exception\ClientException;
 8: 
 9: /**
10:  * Super class for all services
11:  *
12:  * @package Services
13:  * @author Constant Contact
14:  */
15: abstract class BaseService
16: {
17:     /**
18:      * Helper function to return required headers for making an http request with constant contact
19:      * @param $accessToken - OAuth2 access token to be placed into the Authorization header
20:      * @return array - authorization headers
21:      */
22:     private static function getHeaders($accessToken)
23:     {
24:         return array(
25:             'User-Agent' => 'ConstantContact AppConnect PHP Library v' . Config::get('settings.version'),
26:             'Content-Type' => 'application/json',
27:             'Accept' => 'application/json',
28:             'Authorization' => 'Bearer ' . $accessToken
29:         );
30:     }
31: 
32:     /**
33:      * GuzzleHTTP Client Implementation to use for HTTP requests
34:      * @var Client
35:      */
36:     private $client;
37: 
38:     /**
39:      * ApiKey for the application
40:      * @var string
41:      */
42:     private $apiKey;
43: 
44:     /**
45:      * Constructor with the option to to supply an alternative rest client to be used
46:      * @param string $apiKey - Constant Contact API Key
47:      */
48:     public function __construct($apiKey)
49:     {
50:         $this->apiKey = $apiKey;
51:         $this->client = new Client();
52:     }
53: 
54:     /**
55:      * Get the rest client being used by the service
56:      * @return Client - GuzzleHTTP Client implementation being used
57:      */
58:     protected function getClient()
59:     {
60:         return $this->client;
61:     }
62: 
63:     protected function createBaseRequest($accessToken, $method, $baseUrl) {
64:         $request = $this->client->createRequest($method, $baseUrl);
65:         $request->getQuery()->set("api_key", $this->apiKey);
66:         $request->setHeaders($this->getHeaders($accessToken));
67:         return $request;
68:     }
69: 
70:     /**
71:      * Turns a ClientException into a CtctException - like magic.
72:      * @param ClientException $exception - Guzzle ClientException
73:      * @return CtctException
74:      */
75:     protected function convertException($exception)
76:     {
77:         $ctctException = new CtctException($exception->getResponse()->getReasonPhrase(), $exception->getCode());
78:         $ctctException->setUrl($exception->getResponse()->getEffectiveUrl());
79:         $ctctException->setErrors(json_decode($exception->getResponse()->getBody()->getContents()));
80:         return $ctctException;
81:     }
82: }
83: 
API documentation generated by ApiGen