You are here

class MailchimpCampaigns in Mailchimp 8

Same name in this branch
  1. 8 lib/mailchimp-api-php/src/MailchimpCampaigns.php \Mailchimp\MailchimpCampaigns
  2. 8 lib/mailchimp-api-php/tests/src/MailchimpCampaigns.php \Mailchimp\Tests\MailchimpCampaigns

Mailchimp Campaigns library.

@package Mailchimp

Hierarchy

Expanded class hierarchy of MailchimpCampaigns

1 file declares its use of MailchimpCampaigns
mailchimp_campaign.module in modules/mailchimp_campaign/mailchimp_campaign.module
Module file for mailchimp_campaign.
5 string references to 'MailchimpCampaigns'
mailchimp_campaign_delete_campaign in modules/mailchimp_campaign/mailchimp_campaign.module
Delete a Mailchimp campaign and the local entity.
mailchimp_campaign_get_campaigns in modules/mailchimp_campaign/mailchimp_campaign.module
Get Mailchimp campaigns.
mailchimp_campaign_save_campaign in modules/mailchimp_campaign/mailchimp_campaign.module
Save a campaign in Mailchimp and as a Drupal entity.
mailchimp_campaign_send_campaign in modules/mailchimp_campaign/mailchimp_campaign.module
Sends a Mailchimp campaign.
mailchimp_get_campaign_data in ./mailchimp.module
Wrapper function to return data for a given campaign.

File

lib/mailchimp-api-php/src/MailchimpCampaigns.php, line 10

Namespace

Mailchimp
View source
class MailchimpCampaigns extends Mailchimp {
  const EMAIL_TYPE_HTML = 'html';
  const EMAIL_TYPE_PLAIN_TEXT = 'plain_text';
  const CAMPAIGN_TYPE_REGULAR = 'regular';
  const CAMPAIGN_TYPE_PLAINTEXT = 'plaintext';
  const CAMPAIGN_TYPE_ABSPLIT = 'absplit';
  const CAMPAIGN_TYPE_RSS = 'rss';
  const CAMPAIGN_TYPE_VARIATE = 'variate';

  /**
   * Gets information about all campaigns owned by the authenticated account.
   *
   * @param array $parameters
   *   Associative array of optional request parameters.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/#read-get_campaigns
   */
  public function getCampaigns($parameters = []) {
    return $this
      ->request('GET', '/campaigns', NULL, $parameters);
  }

  /**
   * Gets information about a specific campaign.
   *
   * @param string $campaign_id
   *   The ID of the campaign.
   * @param array $parameters
   *   Associative array of optional request parameters.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/#read-get_campaigns_campaign_id
   */
  public function getCampaign($campaign_id, $parameters = []) {
    $tokens = [
      'campaign_id' => $campaign_id,
    ];
    return $this
      ->request('GET', '/campaigns/{campaign_id}', $tokens, $parameters);
  }

  /**
   * Adds a new campaign to the authenticated account.
   *
   * @param string $type
   *   The campaign type. See CAMPAIGN_TYPE_* constants.
   * @param object $recipients
   *   List settings for the campaign.
   * @param object $settings
   *   The subject, from name, reply-to, etc settings for the campaign.
   * @param array $parameters
   *   Associative array of optional request parameters.
   * @param bool $batch
   *   TRUE to create a new pending batch operation.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/#create-post_campaigns
   */
  public function addCampaign($type, $recipients, $settings, $parameters = [], $batch = FALSE) {
    $parameters += [
      'type' => $type,
      'recipients' => $recipients,
      'settings' => $settings,
    ];
    return $this
      ->request('POST', '/campaigns', NULL, $parameters, $batch);
  }

  /**
   * Gets the HTML, plain-text, and template content for a Mailchimp campaign.
   *
   * @param string $campaign_id
   *   The ID of the campaign.
   * @param array $parameters
   *   Associative array of optional request parameters.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/content/#read-get_campaigns_campaign_id_content
   */
  public function getCampaignContent($campaign_id, $parameters = []) {
    $tokens = [
      'campaign_id' => $campaign_id,
    ];
    return $this
      ->request('GET', '/campaigns/{campaign_id}/content', $tokens, $parameters);
  }

  /**
   * Sets the HTML, plain-text, and template content for a Mailchimp campaign.
   *
   * @param string $campaign_id
   *   The ID of the campaign.
   * @param array $parameters
   *   Associative array of optional request parameters.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/content/#edit-put_campaigns_campaign_id_content
   */
  public function setCampaignContent($campaign_id, $parameters = []) {
    $tokens = [
      'campaign_id' => $campaign_id,
    ];
    return $this
      ->request('PUT', '/campaigns/{campaign_id}/content', $tokens, $parameters);
  }

  /**
   * Get the send checklist for a Mailchimp campaign.
   *
   * @param string $campaign_id
   *   The ID of the campaign.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/send-checklist
   */
  public function getSendChecklist($campaign_id) {
    $tokens = [
      'campaign_id' => $campaign_id,
    ];
    return $this
      ->request('GET', '/campaigns/{campaign_id}/send-checklist', $tokens, NULL);
  }

  /**
   * Updates a campaign.
   *
   * @param string $campaign_id
   *   The ID of the campaign.
   * @param string $type
   *   The campaign type. See CAMPAIGN_TYPE_* constants.
   * @param object $recipients
   *   List settings for the campaign.
   * @param object $settings
   *   The subject, from name, reply-to, etc settings for the campaign.
   * @param array $parameters
   *   Associative array of optional request parameters.
   * @param bool $batch
   *   TRUE to create a new pending batch operation.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/#edit-patch_campaigns_campaign_id
   */
  public function updateCampaign($campaign_id, $type, $recipients, $settings, $parameters = [], $batch = FALSE) {
    $tokens = [
      'campaign_id' => $campaign_id,
    ];
    $parameters += [
      'type' => $type,
      'recipients' => $recipients,
      'settings' => $settings,
    ];
    return $this
      ->request('PATCH', '/campaigns/{campaign_id}', $tokens, $parameters, $batch);
  }

  /**
   * Sends a test email.
   *
   * @param string $campaign_id
   *   The ID of the campaign.
   * @param array $test_emails
   *   Email addresses to send the test email to.
   * @param string $send_type
   *   The type of test email to send.
   * @param array $parameters
   *   Associative array of optional request parameters.
   * @param bool $batch
   *   TRUE to create a new pending batch operation.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/#action-post_campaigns_campaign_id_actions_test
   */
  public function sendTest($campaign_id, $test_emails, $send_type, $parameters = [], $batch = FALSE) {
    $tokens = [
      'campaign_id' => $campaign_id,
    ];
    $parameters += [
      'test_emails' => $test_emails,
      'send_type' => $send_type,
    ];
    return $this
      ->request('POST', '/campaigns/{campaign_id}/actions/test', $tokens, $parameters, $batch);
  }

  /**
   * Schedule a Mailchimp campaign.
   *
   * @param string $campaign_id
   *   The ID of the campaign.
   * @param schedule_time $schedule_time
   *   The date and time in UTC to schedule the campaign for delivery.
   * @param bool $timewarp
   *   Choose whether the campaign should use Timewarp when sending.
   * @param object $batch_delivery
   *   Choose whether the campaign should use Batch Delivery.
   *   Cannot be set to true for campaigns using Timewarp.
   * @param bool $batch
   *   TRUE to create a new pending batch operation.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/#action-post_campaigns_campaign_id_actions_schedule
   */
  public function schedule($campaign_id, $schedule_time, $timewarp = FALSE, $batch_delivery = FALSE, $parameters = [], $batch = FALSE) {
    $tokens = [
      'campaign_id' => $campaign_id,
    ];
    $parameters += [
      'schedule_time' => $schedule_time,
      'timewarp' => $timewarp,
      'batch_delivery' => $batch_delivery,
    ];
    return $this
      ->request('POST', '/campaigns/{campaign_id}/actions/schedule', $tokens, $parameters, $batch);
  }

  /**
   * Unschedule a Mailchimp campaign.
   *
   * @param string $campaign_id
   *   The ID of the campaign.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/#action-post_campaigns_campaign_id_actions_unschedule
   */
  public function unschedule($campaign_id) {
    $tokens = [
      'campaign_id' => $campaign_id,
    ];
    return $this
      ->request('POST', '/campaigns/{campaign_id}/actions/unschedule', $tokens, NULL);
  }

  /**
   * Send a Mailchimp campaign.
   *
   * @param string $campaign_id
   *   The ID of the campaign.
   * @param bool $batch
   *   TRUE to create a new pending batch operation.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/#action-post_campaigns_campaign_id_actions_send
   */
  public function send($campaign_id, $batch = FALSE) {
    $tokens = [
      'campaign_id' => $campaign_id,
    ];
    return $this
      ->request('POST', '/campaigns/{campaign_id}/actions/send', $tokens, NULL, $batch);
  }

  /**
   * Deletes a Mailchimp campaign.
   *
   * @param string $campaign_id
   *   The ID of the campaign.
   *
   * @return object
   *
   * @see http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/#delete-delete_campaigns_campaign_id
   */
  public function delete($campaign_id) {
    $tokens = [
      'campaign_id' => $campaign_id,
    ];
    return $this
      ->request('DELETE', '/campaigns/{campaign_id}', $tokens);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Mailchimp::$api_key private property The Mailchimp API key to authenticate with.
Mailchimp::$api_user private property The Mailchimp API username to authenticate with.
Mailchimp::$batch_operations private property Array of pending batch operations.
Mailchimp::$client protected property The HTTP client.
Mailchimp::$debug_error_code private property A Mailchimp API error code to return with every API response.
Mailchimp::$endpoint protected property The REST API endpoint.
Mailchimp::$version public property API version.
Mailchimp::addBatchOperation protected function Adds a pending batch operation.
Mailchimp::DEFAULT_DATA_CENTER constant
Mailchimp::ERROR_CODE_API_KEY_INVALID constant
Mailchimp::ERROR_CODE_API_KEY_MISSING constant
Mailchimp::ERROR_CODE_BAD_REQUEST constant
Mailchimp::ERROR_CODE_COMPLIANCE_RELATED constant
Mailchimp::ERROR_CODE_FORBIDDEN constant
Mailchimp::ERROR_CODE_INTERNAL_SERVER_ERROR constant
Mailchimp::ERROR_CODE_INVALID_ACTION constant
Mailchimp::ERROR_CODE_INVALID_METHOD_OVERRIDE constant
Mailchimp::ERROR_CODE_INVALID_RESOURCE constant
Mailchimp::ERROR_CODE_JSON_PARSE_ERROR constant
Mailchimp::ERROR_CODE_METHOD_NOT_ALLOWED constant
Mailchimp::ERROR_CODE_REQUESTED_FIELDS_INVALID constant
Mailchimp::ERROR_CODE_RESOURCE_NESTING_TOO_DEEP constant
Mailchimp::ERROR_CODE_RESOURCE_NOT_FOUND constant
Mailchimp::ERROR_CODE_TOO_MANY_REQUESTS constant
Mailchimp::ERROR_CODE_USER_DISABLED constant
Mailchimp::ERROR_CODE_WRONG_DATACENTER constant
Mailchimp::getAccount public function Gets Mailchimp account information for the authenticated account.
Mailchimp::getBatchOperation public function Gets the status of a batch request.
Mailchimp::getDataCenter private function Gets the ID of the data center associated with an API key.
Mailchimp::getDefaultHttpClient private function Instantiates a default HTTP client based on the local environment.
Mailchimp::processBatchOperations public function Processes all pending batch operations.
Mailchimp::request public function Makes a request to the Mailchimp API.
Mailchimp::setClient public function Sets a custom HTTP client to be used for all API requests.
Mailchimp::setDebugErrorCode public function Sets a Mailchimp error code to be returned by all requests.
Mailchimp::VERSION constant
Mailchimp::__construct public function Mailchimp constructor. 7
MailchimpCampaigns::addCampaign public function Adds a new campaign to the authenticated account.
MailchimpCampaigns::CAMPAIGN_TYPE_ABSPLIT constant
MailchimpCampaigns::CAMPAIGN_TYPE_PLAINTEXT constant
MailchimpCampaigns::CAMPAIGN_TYPE_REGULAR constant
MailchimpCampaigns::CAMPAIGN_TYPE_RSS constant
MailchimpCampaigns::CAMPAIGN_TYPE_VARIATE constant
MailchimpCampaigns::delete public function Deletes a Mailchimp campaign.
MailchimpCampaigns::EMAIL_TYPE_HTML constant
MailchimpCampaigns::EMAIL_TYPE_PLAIN_TEXT constant
MailchimpCampaigns::getCampaign public function Gets information about a specific campaign. 1
MailchimpCampaigns::getCampaignContent public function Gets the HTML, plain-text, and template content for a Mailchimp campaign.
MailchimpCampaigns::getCampaigns public function Gets information about all campaigns owned by the authenticated account.
MailchimpCampaigns::getSendChecklist public function Get the send checklist for a Mailchimp campaign.
MailchimpCampaigns::schedule public function Schedule a Mailchimp campaign.
MailchimpCampaigns::send public function Send a Mailchimp campaign.
MailchimpCampaigns::sendTest public function Sends a test email.
MailchimpCampaigns::setCampaignContent public function Sets the HTML, plain-text, and template content for a Mailchimp campaign.
MailchimpCampaigns::unschedule public function Unschedule a Mailchimp campaign.
MailchimpCampaigns::updateCampaign public function Updates a campaign.