You are here

protected function Mailchimp::addBatchOperation in Mailchimp 8

Adds a pending batch operation.

Parameters

string $method: The HTTP method.

string $path: The request path, relative to the API endpoint.

array $parameters: Associative array of optional request parameters.

Return value

object The new batch operation object.

Throws

MailchimpAPIException

See also

http://developer.mailchimp.com/documentation/mailchimp/reference/batches...

1 call to Mailchimp::addBatchOperation()
Mailchimp::request in lib/mailchimp-api-php/src/Mailchimp.php
Makes a request to the Mailchimp API.

File

lib/mailchimp-api-php/src/Mailchimp.php, line 217

Class

Mailchimp
Mailchimp library.

Namespace

Mailchimp

Code

protected function addBatchOperation($method, $path, $parameters = []) {
  if (empty($method) || empty($path)) {
    throw new MailchimpAPIException('Cannot add batch operation without a method and path.');
  }
  $op = (object) [
    'method' => $method,
    'path' => $path,
  ];
  if (!empty($parameters)) {
    if ($method == 'GET') {
      $op->params = (object) $parameters;
    }
    else {
      $op->body = json_encode($parameters);
    }
  }
  if (empty($this->batch_operations)) {
    $this->batch_operations = [];
  }
  $this->batch_operations[] = $op;
  return $op;
}