function MCAPI::callServer in Mailchimp 7
Same name and namespace in other branches
- 5.2 MCAPI.class.php \MCAPI::callServer()
- 5 MCAPI.class.php \MCAPI::callServer()
- 6.2 MCAPI.class.php \MCAPI::callServer()
- 6 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
65 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
File
- ./
MCAPI.class.php, line 1577
Class
Code
function callServer($method, $params) {
//Always include the apikey if we are not logging in
if ($method != "login") {
$dc = "us1";
if (strstr($this->api_key, "-")) {
list($key, $dc) = explode("-", $this->api_key, 2);
if (!$dc) {
$dc = "us1";
}
}
$host = $dc . "." . $this->apiUrl["host"];
$params["apikey"] = $this->api_key;
}
else {
$host = $this->apiUrl["host"];
}
$this->errorMessage = "";
$this->errorCode = "";
$post_vars = $this
->httpBuildQuery($params);
$payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
$payload .= "Host: " . $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();
if ($this->secure) {
$sock = fsockopen("ssl://" . $host, 443, $errno, $errstr, 30);
}
else {
$sock = fsockopen($host, 80, $errno, $errstr, 30);
}
if (!$sock) {
$this->errorMessage = "Could not connect (ERR {$errno}: {$errstr})";
$this->errorCode = "-99";
ob_end_clean();
return false;
}
$response = "";
fwrite($sock, $payload);
stream_set_timeout($sock, $this->timeout);
$info = stream_get_meta_data($sock);
while (!feof($sock) && !$info["timed_out"]) {
$response .= fread($sock, $this->chunkSize);
$info = stream_get_meta_data($sock);
}
if ($info["timed_out"]) {
$this->errorMessage = "Could not read response (timed out)";
$this->errorCode = -98;
}
fclose($sock);
ob_end_clean();
if ($info["timed_out"]) {
return false;
}
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;
}