diff --git a/src/MailChimp.php b/src/MailChimp.php index e810836..4bff3f9 100644 --- a/src/MailChimp.php +++ b/src/MailChimp.php @@ -15,6 +15,8 @@ class MailChimp private $api_key; private $api_endpoint = 'https://.api.mailchimp.com/3.0'; + private $source_ip; + const TIMEOUT = 10; /* SSL Verification @@ -36,7 +38,7 @@ class MailChimp * * @throws \Exception */ - public function __construct($api_key, $api_endpoint = null) + public function __construct($api_key, $api_endpoint = null, $source_ip = null) { if (!function_exists('curl_init') || !function_exists('curl_setopt')) { throw new \Exception("cURL support is required, but can't be found."); @@ -44,6 +46,8 @@ public function __construct($api_key, $api_endpoint = null) $this->api_key = $api_key; + $this->source_ip = $source_ip; + if ($api_endpoint === null) { if (strpos($this->api_key, '-') === false) { throw new \Exception("Invalid MailChimp API key supplied."); @@ -218,8 +222,8 @@ private function makeRequest($http_verb, $method, $args = array(), $timeout = se $response = $this->prepareStateForRequest($http_verb, $method, $url, $timeout); $httpHeader = array( - 'Accept: application/vnd.api+json', - 'Content-Type: application/vnd.api+json', + 'Accept: application/json', + 'Content-Type: application/json', 'Authorization: apikey ' . $this->api_key ); @@ -232,6 +236,9 @@ private function makeRequest($http_verb, $method, $args = array(), $timeout = se } $ch = curl_init(); + if($this->source_ip && is_string($this->source_ip)) { + curl_setopt($ch, CURLOPT_INTERFACE, $this->source_ip); + } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader); curl_setopt($ch, CURLOPT_USERAGENT, 'DrewM/MailChimp-API/3.0 (github.com/drewm/mailchimp-api)');