Overview

Namespaces

  • Ctct
    • Auth
    • Components
      • Account
      • Activities
      • Contacts
      • EmailMarketing
      • Tracking
    • Exceptions
    • Services
  • PHP

Classes

  • AccountService
  • ActivityService
  • BaseService
  • CampaignScheduleService
  • CampaignTrackingService
  • ContactService
  • ContactTrackingService
  • EmailMarketingService
  • ListService
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: namespace Ctct\Services;
  3: 
  4: use Ctct\Util\RestClient;
  5: use Ctct\Util\Config;
  6: use Ctct\Components\Contacts\ContactList;
  7: use Ctct\Components\Contacts\Contact;
  8: use Ctct\Components\ResultSet;
  9: 
 10: /**
 11:  * Performs all actions pertaining to Constant Contact Lists
 12:  * 
 13:  * @package     Services
 14:  * @author         Constant Contact
 15:  */
 16: class ListService extends BaseService
 17: {
 18:     /**
 19:      * Get lists within an account
 20:      * @param $accessToken - Constant Contact OAuth2 access token
 21:      * @param array $params - array of query parameters to be appened to the request
 22:      * @return Array - ContactLists
 23:      */
 24:     public function getLists($accessToken, array $params = array())
 25:     {
 26:         $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.lists');
 27:         $url = $this->buildUrl($baseUrl, $params);
 28:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
 29:         
 30:         $lists = array();
 31:         foreach (json_decode($response->body, true) as $contact) {
 32:             $lists[] = ContactList::create($contact);
 33:         }
 34:         return $lists;
 35:     }
 36: 
 37:     /**
 38:      * Create a new Contact List
 39:      * @param string $accessToken - Constant Contact OAuth2 access token
 40:      * @param ContactList $list
 41:      * @return ContactList
 42:      */
 43:     public function addList($accessToken, ContactList $list)
 44:     {
 45:         $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.lists');
 46:         $url = $this->buildUrl($baseUrl);
 47:         $response = parent::getRestClient()->post($url, parent::getHeaders($accessToken), $list->toJson());
 48:         return ContactList::create(json_decode($response->body, true));
 49:     }
 50:     
 51:     /**
 52:      * Update a Contact List
 53:      * @param string $accessToken - Constant Contact OAuth2 access token
 54:      * @param ContactList $list - ContactList to be updated
 55:      * @return ContactList
 56:      */
 57:     public function updateList($accessToken, ContactList $list)
 58:     {
 59:         $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list'), $list->id);
 60:         $url = $this->buildUrl($baseUrl);
 61:         $response = parent::getRestClient()->put($url, parent::getHeaders($accessToken), $list->toJson());
 62:         return ContactList::create(json_decode($response->body, true));
 63:     }
 64: 
 65:     /**
 66:      * Get an individual contact list
 67:      * @param $accessToken - Constant Contact OAuth2 access token
 68:      * @param $list_id - list id
 69:      * @return ContactList
 70:      */
 71:     public function getList($accessToken, $list_id)
 72:     {
 73:         $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list'), $list_id);
 74:         $url = $this->buildUrl($baseUrl);
 75:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
 76:         return ContactList::create(json_decode($response->body, true));
 77:     }
 78: 
 79:     /**
 80:      * Get all contacts from an individual list
 81:      * @param string $accessToken - Constant Contact OAuth2 access token
 82:      * @param string $list_id - list id to retrieve contacts for
 83:      * @param array $params - query params to attach to request
 84:      * @return ResultSet
 85:      */
 86:     public function getContactsFromList($accessToken, $list_id, $params = null)
 87:     {
 88:         $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list_contacts'), $list_id);
 89:         $url = $this->buildUrl($baseUrl, $params);
 90:         
 91:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
 92:         $body = json_decode($response->body, true);
 93:         $contacts = array();
 94:         foreach ($body['results'] as $contact) {
 95:             $contacts[] = Contact::create($contact);
 96:         }
 97:         return new ResultSet($contacts, $body['meta']);
 98:     }
 99: }
100: 
Appconnect PHP SDK API documentation generated by ApiGen 2.8.0