You are here

class MailchimpLists in Mailchimp 8

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

Mailchimp Lists library test cases.

@package Mailchimp\Tests

Hierarchy

Expanded class hierarchy of MailchimpLists

16 string references to 'MailchimpLists'
MailchimpListsWebhookSettingsForm::submitForm in modules/mailchimp_lists/src/Form/MailchimpListsWebhookSettingsForm.php
Form submission handler.
mailchimp_batch_update_members in ./mailchimp.module
Batch updates a number of Mailchimp list members.
mailchimp_campaign_get_list_segments in modules/mailchimp_campaign/mailchimp_campaign.module
Gets an array of list segments for a given list ID.
mailchimp_get_lists in ./mailchimp.module
Returns all Mailchimp lists for a given key. Lists are stored in the cache.
mailchimp_get_lists_for_email in ./mailchimp.module
Returns all lists a given email address is currently subscribed to.

... See full list

File

lib/mailchimp-api-php/tests/src/MailchimpLists.php, line 10

Namespace

Mailchimp\Tests
View source
class MailchimpLists extends \Mailchimp\MailchimpLists {

  /**
   * @inheritdoc
   */
  public function __construct($api_key = 'apikey', $api_user = 'apikey', $http_options = []) {
    $this->client = new MailchimpTestHttpClient();
  }
  public function getClient() {
    return $this->client;
  }
  public function getEndpoint() {
    return $this->endpoint;
  }

  /**
   * @inheritdoc
   */
  public function getLists($parameters = []) {
    parent::getLists($parameters);
    $response = (object) [
      'lists' => [
        (object) [
          'id' => '57afe96172',
          'name' => 'Test List One',
        ],
        (object) [
          'id' => 'f4b7b26b2e',
          'name' => 'Test List Two',
        ],
        (object) [
          'id' => '587693d673',
          'name' => 'Test List Three',
        ],
      ],
      'total_items' => 3,
    ];
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function getList($list_id, $parameters = []) {
    parent::getList($list_id, $parameters);
    $response = (object) [
      'id' => $list_id,
      'name' => 'Test List One',
    ];
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function getInterestCategories($list_id, $parameters = []) {
    parent::getInterestCategories($list_id, $parameters);
    $response = (object) [
      'list_id' => $list_id,
      'categories' => [
        (object) [
          'list_id' => $list_id,
          'id' => 'a1e9f4b7f6',
          'title' => 'Test Interest Category',
        ],
      ],
      'total_items' => 1,
    ];
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function getInterests($list_id, $interest_category_id, $parameters = []) {
    parent::getInterests($list_id, $interest_category_id, $parameters);
    $response = (object) [
      'interests' => [
        (object) [
          'category_id' => $interest_category_id,
          'list_id' => $list_id,
          'id' => '9143cf3bd1',
          'name' => 'Test Interest',
        ],
      ],
      'total_items' => 1,
    ];
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function getMergeFields($list_id, $parameters = []) {
    parent::getMergeFields($list_id, $parameters);
    $response = (object) [
      'merge_fields' => [
        (object) [
          'merge_id' => 1,
          'tag' => 'FNAME',
          'list_id' => $list_id,
        ],
        (object) [
          'merge_id' => 2,
          'tag' => 'LNAME',
          'list_id' => $list_id,
        ],
      ],
      'total_items' => 2,
    ];
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function getMemberInfo($list_id, $email, $parameters = []) {
    parent::getMemberInfo($list_id, $email, $parameters);
    $response = (object) [
      'id' => md5(strtolower($email)),
      'email_address' => $email,
      'status' => 'subscribed',
    ];
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function addMember($list_id, $email, $parameters = [], $batch = FALSE) {
    parent::addMember($list_id, $email, $parameters, $batch);
    $response = (object) [
      'id' => md5(strtolower($email)),
      'email_address' => $email,
    ];
    foreach ($parameters as $key => $value) {
      $response->{$key} = $value;
    }
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function removeMember($list_id, $email) {
    parent::removeMember($list_id, $email);
  }

  /**
   * @inheritdoc
   */
  public function updateMember($list_id, $email, $parameters = [], $batch = FALSE) {
    parent::updateMember($list_id, $email, $parameters, $batch);
    $response = (object) [
      'id' => md5(strtolower($email)),
      'email_address' => $email,
    ];
    foreach ($parameters as $key => $value) {
      $response->{$key} = $value;
    }
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function addOrUpdateMember($list_id, $email, $parameters = [], $batch = FALSE) {
    parent::addOrUpdateMember($list_id, $email, $parameters, $batch);
    $response = (object) [
      'id' => md5(strtolower($email)),
      'email_address' => $email,
    ];
    foreach ($parameters as $key => $value) {
      $response->{$key} = $value;
    }
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function getSegments($list_id, $parameters = []) {
    parent::getSegments($list_id, $parameters);
    $response = (object) [
      'segments' => [
        (object) [
          'id' => 49377,
          'name' => 'Test Segment One',
          'type' => 'static',
          'list_id' => $list_id,
        ],
        (object) [
          'id' => 49378,
          'name' => 'Test Segment Two',
          'type' => 'static',
          'list_id' => $list_id,
        ],
      ],
      'total_items' => 2,
    ];
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function getSegment($list_id, $segment_id, $parameters = []) {
    parent::getSegment($list_id, $segment_id, $parameters);
    $response = (object) [
      'id' => 49377,
      'name' => 'Test Segment One',
      'type' => 'static',
      'list_id' => $list_id,
    ];
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function addSegment($list_id, $name, $parameters = [], $batch = FALSE) {
    parent::addSegment($list_id, $name, $parameters, $batch);
    $response = (object) [];
    if (!empty($list_id) && !empty($name) && !empty($parameters['type'])) {
      $response->id = 49381;
      $response->name = $name;
      $response->type = $parameters['type'];
      $response->list_id = $list_id;
    }
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function updateSegment($list_id, $segment_id, $name, $parameters = [], $batch = FALSE) {
    parent::updateSegment($list_id, $segment_id, $name, $parameters);
    $response = (object) [
      'id' => $segment_id,
      'name' => $name,
      'member_count' => isset($parameters['static_segment']) ? count($parameters['static_segment']) : 0,
      'list_id' => $list_id,
    ];
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function getWebhooks($list_id, $parameters = []) {
    parent::getWebhooks($list_id, $parameters);
    $response = (object) [
      'webhooks' => [
        (object) [
          'id' => '37b9c73a88',
          'url' => 'http://example.org',
          'events' => (object) [
            'subscribe' => TRUE,
            'unsubscribe' => FALSE,
          ],
          'sources' => (object) [
            'user' => TRUE,
            'api' => FALSE,
          ],
          'list_id' => $list_id,
        ],
      ],
      'total_items' => 1,
    ];
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function addWebhook($list_id, $url, $parameters = [], $batch = FALSE) {
    parent::addWebhook($list_id, $url, $parameters, $batch);
    $response = (object) [
      'id' => 'ab24521a00',
      'url' => $url,
      'list_id' => $list_id,
    ];
    foreach ($parameters as $key => $value) {
      $response->{$key} = $value;
    }
    return $response;
  }

  /**
   * @inheritdoc
   */
  public function deleteWebhook($list_id, $webhook_id, $parameters = []) {
    parent::deleteWebhook($list_id, $webhook_id, $parameters);
    return !empty($list_id) && !empty($webhook_id);
  }

}

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
MailchimpLists::addMember public function @inheritdoc Overrides MailchimpLists::addMember
MailchimpLists::addMergeField public function Add merge field associated with a Mailchimp list.
MailchimpLists::addOrUpdateMember public function @inheritdoc Overrides MailchimpLists::addOrUpdateMember
MailchimpLists::addSegment public function @inheritdoc Overrides MailchimpLists::addSegment
MailchimpLists::addSegmentMember public function Adds a member to a list segment.
MailchimpLists::addWebhook public function @inheritdoc Overrides MailchimpLists::addWebhook
MailchimpLists::deleteWebhook public function @inheritdoc Overrides MailchimpLists::deleteWebhook
MailchimpLists::getClient public function
MailchimpLists::getEndpoint public function
MailchimpLists::getInterestCategories public function @inheritdoc Overrides MailchimpLists::getInterestCategories
MailchimpLists::getInterests public function @inheritdoc Overrides MailchimpLists::getInterests
MailchimpLists::getList public function @inheritdoc Overrides MailchimpLists::getList
MailchimpLists::getLists public function @inheritdoc Overrides MailchimpLists::getLists
MailchimpLists::getListsForEmail public function Gets all lists an email address is subscribed to.
MailchimpLists::getMemberActivity public function Gets activity related to a member of a Mailchimp list.
MailchimpLists::getMemberInfo public function @inheritdoc Overrides MailchimpLists::getMemberInfo
MailchimpLists::getMemberInfoById public function Gets information about a member of a Mailchimp list.
MailchimpLists::getMembers public function Gets information about all members of a Mailchimp list.
MailchimpLists::getMergeFields public function @inheritdoc Overrides MailchimpLists::getMergeFields
MailchimpLists::getSegment public function @inheritdoc Overrides MailchimpLists::getSegment
MailchimpLists::getSegmentMembers public function Gets information about members of a list segment.
MailchimpLists::getSegments public function @inheritdoc Overrides MailchimpLists::getSegments
MailchimpLists::getWebhook public function Gets information about a specific webhook associated with a list.
MailchimpLists::getWebhooks public function @inheritdoc Overrides MailchimpLists::getWebhooks
MailchimpLists::MEMBER_STATUS_CLEANED constant
MailchimpLists::MEMBER_STATUS_PENDING constant
MailchimpLists::MEMBER_STATUS_SUBSCRIBED constant
MailchimpLists::MEMBER_STATUS_UNSUBSCRIBED constant
MailchimpLists::removeMember public function @inheritdoc Overrides MailchimpLists::removeMember
MailchimpLists::updateMember public function @inheritdoc Overrides MailchimpLists::updateMember
MailchimpLists::updateSegment public function @inheritdoc Overrides MailchimpLists::updateSegment
MailchimpLists::__construct public function @inheritdoc Overrides Mailchimp::__construct