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\EmailMarketing\Schedule;
  7: use Ctct\Components\EmailMarketing\TestSend;
  8: 
  9: /**
 10:  * Performs all actions pertaining to scheduling Constant Contact Campaigns
 11:  *
 12:  * @package     Services
 13:  * @author         Constant Contact
 14:  */
 15: class CampaignScheduleService extends BaseService
 16: {
 17:     /**
 18:      * Create a new schedule for a campaign
 19:      * @param string $accessToken - Constant Contact OAuth2 access token
 20:      * @param int $campaignId - Campaign id to be scheduled
 21:      * @param Schedule $schedule - Schedule to be created
 22:      * @return Campaign
 23:      */
 24:     public function addSchedule($accessToken, $campaignId, Schedule $schedule)
 25:     {
 26:         $baseUrl = Config::get('endpoints.base_url') .
 27:             sprintf(Config::get('endpoints.campaign_schedules'), $campaignId);
 28:         $url = $this->buildUrl($baseUrl);
 29:         $response = parent::getRestClient()->post($url, parent::getHeaders($accessToken), $schedule->toJson());
 30:         return Schedule::create(json_decode($response->body, true));
 31:     }
 32:      
 33:      /**
 34:      * Get a list of schedules for a campaign
 35:      * @param string $accessToken - Constant Contact OAuth2 access token
 36:      * @param int $campaignId - Campaign id to be scheduled
 37:      * @return array 
 38:      */
 39:     public function getSchedules($accessToken, $campaignId)
 40:     {
 41:         $baseUrl = Config::get('endpoints.base_url') .
 42:             sprintf(Config::get('endpoints.campaign_schedules'), $campaignId);
 43:         $url = $this->buildUrl($baseUrl);
 44:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
 45:         
 46:         $schedules = array();
 47:         
 48:         foreach (json_decode($response->body, true) as $schedule) {
 49:             $schedules[] = Schedule::create($schedule);
 50:         }
 51:         
 52:         return $schedules;
 53:     }
 54:      
 55:      /**
 56:      * Get a specific schedule for a campaign
 57:      * @param string $accessToken - Constant Contact OAuth2 access token
 58:      * @param int $campaignId - Campaign id to be get a schedule for
 59:      * @param int $scheudle_id - Schedule id to retrieve 
 60:      * @return Schedule 
 61:      */
 62:     public function getSchedule($accessToken, $campaignId, $scheduleId)
 63:     {
 64:         $baseUrl = Config::get('endpoints.base_url') .
 65:             sprintf(Config::get('endpoints.campaign_schedule'), $campaignId, $scheduleId);
 66:         $url = $this->buildUrl($baseUrl);
 67:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
 68:         return Schedule::create(json_decode($response->body, true));
 69:     }
 70:      
 71:     /**
 72:      * Update a specific schedule for a campaign
 73:      * @param string $accessToken - Constant Contact OAuth2 access token
 74:      * @param int $campaignId - Campaign id to be scheduled
 75:      * @param Schedule $schedule - Schedule to retrieve 
 76:      * @return Schedule 
 77:      */
 78:     public function updateSchedule($accessToken, $campaignId, Schedule $schedule)
 79:     {
 80:         $baseUrl = Config::get('endpoints.base_url') .
 81:             sprintf(Config::get('endpoints.campaign_schedule'), $campaignId, $schedule->id);
 82:         $url = $this->buildUrl($baseUrl);
 83:         $response = parent::getRestClient()->put($url, parent::getHeaders($accessToken), $schedule->toJson());
 84:         return Schedule::create(json_decode($response->body, true));
 85:     }
 86:      
 87:      /**
 88:      * Get a specific schedule for a campaign
 89:      * @param string $accessToken - Constant Contact OAuth2 access token
 90:      * @param int $campaignId - Campaign id
 91:      * @param int $scheduleId - Schedule id to delete
 92:      * @return Schedule 
 93:      */
 94:     public function deleteSchedule($accessToken, $campaignId, $scheduleId)
 95:     {
 96:         $baseUrl = Config::get('endpoints.base_url') .
 97:             sprintf(Config::get('endpoints.campaign_schedule'), $campaignId, $scheduleId);
 98:         $url = $this->buildUrl($baseUrl);
 99:         $response = parent::getRestClient()->delete($url, parent::getHeaders($accessToken));
100:         return ($response->info['http_code'] == 204) ? true : false;
101:     }
102: 
103:     /**
104:      * Send a test send of a campaign
105:      * @param string $accessToken - Constant Contact OAuth2 access token
106:      * @param int $campaignId - Id of campaign to send test of
107:      * @param TestSend $test_send - Test send details
108:      * @return TestSend
109:      */
110:     public function sendTest($accessToken, $campaignId, TestSend $test_send)
111:     {
112:         $baseUrl = Config::get('endpoints.base_url') .
113:             sprintf(Config::get('endpoints.campaign_test_sends'), $campaignId);
114:         $url = $this->buildUrl($baseUrl);
115:         $response = parent::getRestClient()->post($url, parent::getHeaders($accessToken), $test_send->toJson());
116:         return TestSend::create(json_decode($response->body, true));
117:     }
118: }
119: 
Appconnect PHP SDK API documentation generated by ApiGen 2.8.0