You are here

function MCAPI::callServer in Mailchimp 5

Same name and namespace in other branches
  1. 5.2 MCAPI.class.php \MCAPI::callServer()
  2. 6.2 MCAPI.class.php \MCAPI::callServer()
  3. 6 MCAPI.class.php \MCAPI::callServer()
  4. 7 MCAPI.class.php \MCAPI::callServer()

Actually connect to the server and call the requested methods, parsing the result You should never have to call this function manually

48 calls to MCAPI::callServer()
MCAPI::apikeyAdd in ./MCAPI.class.php
Add an API Key to your account. We will generate a new key for you and return it.
MCAPI::apikeyExpire in ./MCAPI.class.php
Expire a Specific API Key. Note that if you expire all of your keys, a new, valid one will be created and returned next time you call login(). If you are trying to shut off access to your account for an old developer, change your MailChimp password,…
MCAPI::apikeys in ./MCAPI.class.php
Retrieve a list of all MailChimp API Keys for this User
MCAPI::callMethod in ./MCAPI.class.php
Internal function - proxy method for certain XML-RPC calls | DO NOT CALL
MCAPI::campaignAbuseReports in ./MCAPI.class.php
Get all email addresses that complained about a given campaign

... See full list

File

./MCAPI.class.php, line 1026

Class

MCAPI

Code

function callServer($method, $params) {

  //Always include the user id if we're not loggin in
  if ($method != "login") {
    $params["apikey"] = $this->api_key;
  }
  $post_vars = $this
    ->httpBuildQuery($params);
  $payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
  $payload .= "Host: " . $this->apiUrl["host"] . "\r\n";
  $payload .= "User-Agent: MCAPI/" . $this->version . "\r\n";
  $payload .= "Content-type: application/x-www-form-urlencoded\r\n";
  $payload .= "Content-length: " . strlen($post_vars) . "\r\n";
  $payload .= "Connection: close \r\n\r\n";
  $payload .= $post_vars;
  ob_start();
  $sock = fsockopen($this->apiUrl["host"], 80, $errno, $errstr, $this->timeout);
  if (!$sock) {
    $this->errorMessage = "Could not connect (ERR {$errno}: {$errstr})";
    $this->errorCode = "-99";
    ob_end_clean();
    return false;
  }
  $response = "";
  fwrite($sock, $payload);
  while (!feof($sock)) {
    $response .= fread($sock, $this->chunkSize);
  }
  fclose($sock);
  ob_end_clean();
  list($throw, $response) = explode("\r\n\r\n", $response, 2);
  if (ini_get("magic_quotes_runtime")) {
    $response = stripslashes($response);
  }
  $serial = unserialize($response);
  if ($response && $serial === false) {
    $response = array(
      "error" => "Bad Response.  Got This: " . $response,
      "code" => "-99",
    );
  }
  else {
    $response = $serial;
  }
  if (is_array($response) && isset($response["error"])) {
    $this->errorMessage = $response["error"];
    $this->errorCode = $response["code"];
    return false;
  }
  return $response;
}