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:      * @return Array - ContactLists
22:      */
23:     public function getLists($accessToken)
24:     {
25:         $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.lists');
26:         $url = $this->buildUrl($baseUrl);
27:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
28:         
29:         $lists = array();
30:         foreach (json_decode($response->body, true) as $contact) {
31:             $lists[] = ContactList::create($contact);
32:         }
33:         return $lists;
34:     }
35: 
36:     /**
37:      * Create a new Contact List
38:      * @param string $accessToken - Constant Contact OAuth2 access token
39:      * @param ContactList $list
40:      * @return ContactList
41:      */
42:     public function addList($accessToken, ContactList $list)
43:     {
44:         $url = Config::get('endpoints.base_url') . Config::get('endpoints.lists');
45:         $response = parent::getRestClient()->post($url, parent::getHeaders($accessToken), $list->toJson());
46:         return ContactList::create(json_decode($response->body, true));
47:     }
48:     
49:     /**
50:      * Update a Contact List
51:      * @param string $accessToken - Constant Contact OAuth2 access token
52:      * @param ContactList $list - ContactList to be updated
53:      * @return ContactList
54:      */
55:     public function updateList($accessToken, ContactList $list)
56:     {
57:         $url = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list'), $list->id);
58:         $response = parent::getRestClient()->put($url, parent::getHeaders($accessToken), $list->toJson());
59:         return ContactList::create(json_decode($response->body, true));
60:     }
61: 
62:     /**
63:      * Get an individual contact list
64:      * @param $accessToken - Constant Contact OAuth2 access token
65:      * @param $list_id - list id
66:      * @return ContactList
67:      */
68:     public function getList($accessToken, $list_id)
69:     {
70:         $url = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list'), $list_id);
71:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
72:         return ContactList::create(json_decode($response->body, true));
73:     }
74: 
75:     /**
76:      * Get all contacts from an individual list
77:      * @param string $accessToken - Constant Contact OAuth2 access token
78:      * @param string $list_id - list id to retrieve contacts for
79:      * @param array $params - query params to attach to request
80:      * @return ResultSet
81:      */
82:     public function getContactsFromList($accessToken, $list_id, $params = null)
83:     {
84:         $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.list_contacts'), $list_id);
85:         $url = $this->buildUrl($baseUrl, $params);
86:         
87:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
88:         $body = json_decode($response->body, true);
89:         $contacts = array();
90:         foreach ($body['results'] as $contact) {
91:             $contacts[] = Contact::create($contact);
92:         }
93:         return new ResultSet($contacts, $body['meta']);
94:     }
95: }
96: 
Appconnect PHP SDK API documentation generated by ApiGen 2.8.0