PHP Class DrewM\MailChimp\MailChimp

Author: Drew McLellan ([email protected])
Mostrar archivo Open project: drewm/mailchimp-api Class Usage Examples

Public Properties

Property Type Description
$verify_ssl * SSL Verification Read before disabling: http://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/

Public Methods

Method Description
__construct ( string $api_key ) Create a new instance
delete ( string $method, array $args = [], integer $timeout = 10 ) : array | false Make an HTTP DELETE request - for deleting data
get ( string $method, array $args = [], integer $timeout = 10 ) : array | false Make an HTTP GET request - for retrieving data
getLastError ( ) : array | false Get the last error returned by either the network transport, or by the API.
getLastRequest ( ) : array Get an array containing the HTTP headers and the body of the API request.
getLastResponse ( ) : array Get an array containing the HTTP headers and the body of the API response.
new_batch ( string $batch_id = null ) : Batch Create a new instance of a Batch request. Optionally with the ID of an existing batch.
patch ( string $method, array $args = [], integer $timeout = 10 ) : array | false Make an HTTP PATCH request - for performing partial updates
post ( string $method, array $args = [], integer $timeout = 10 ) : array | false Make an HTTP POST request - for creating and updating items
put ( string $method, array $args = [], integer $timeout = 10 ) : array | false Make an HTTP PUT request - for creating new items
subscriberHash ( string $email ) : string Convert an email address into a 'subscriber hash' for identifying the subscriber in a method URL
success ( ) : boolean Was the last request successful?

Private Methods

Method Description
attachRequestPayload ( resource &$ch, array $data ) Encode the data and attach it to the request
determineSuccess ( array $response, array | false $formattedResponse ) : boolean Check if the response was successful or a failure. If it failed, store the error.
findHTTPStatus ( array $response, array | false $formattedResponse ) : integer Find the HTTP status code from the headers or API response body
formatResponse ( array $response ) : array | false Decode the response and format any error messages for debugging
makeRequest ( string $http_verb, string $method, array $args = [], integer $timeout = 10 ) : array | false Performs the underlying HTTP request. Not very exciting.

Method Details

__construct() public method

Create a new instance
public __construct ( string $api_key )
$api_key string Your MailChimp API key

delete() public method

Make an HTTP DELETE request - for deleting data
public delete ( string $method, array $args = [], integer $timeout = 10 ) : array | false
$method string URL of the API request method
$args array Assoc array of arguments (if any)
$timeout integer Timeout limit for request in seconds
return array | false Assoc array of API response, decoded from JSON

get() public method

Make an HTTP GET request - for retrieving data
public get ( string $method, array $args = [], integer $timeout = 10 ) : array | false
$method string URL of the API request method
$args array Assoc array of arguments (usually your data)
$timeout integer Timeout limit for request in seconds
return array | false Assoc array of API response, decoded from JSON

getLastError() public method

If something didn't work, this should contain the string describing the problem.
public getLastError ( ) : array | false
return array | false describing the error

getLastRequest() public method

Get an array containing the HTTP headers and the body of the API request.
public getLastRequest ( ) : array
return array Assoc array

getLastResponse() public method

Get an array containing the HTTP headers and the body of the API response.
public getLastResponse ( ) : array
return array Assoc array with keys 'headers' and 'body'

new_batch() public method

Create a new instance of a Batch request. Optionally with the ID of an existing batch.
public new_batch ( string $batch_id = null ) : Batch
$batch_id string Optional ID of an existing batch, if you need to check its status for example.
return Batch New Batch object.

patch() public method

Make an HTTP PATCH request - for performing partial updates
public patch ( string $method, array $args = [], integer $timeout = 10 ) : array | false
$method string URL of the API request method
$args array Assoc array of arguments (usually your data)
$timeout integer Timeout limit for request in seconds
return array | false Assoc array of API response, decoded from JSON

post() public method

Make an HTTP POST request - for creating and updating items
public post ( string $method, array $args = [], integer $timeout = 10 ) : array | false
$method string URL of the API request method
$args array Assoc array of arguments (usually your data)
$timeout integer Timeout limit for request in seconds
return array | false Assoc array of API response, decoded from JSON

put() public method

Make an HTTP PUT request - for creating new items
public put ( string $method, array $args = [], integer $timeout = 10 ) : array | false
$method string URL of the API request method
$args array Assoc array of arguments (usually your data)
$timeout integer Timeout limit for request in seconds
return array | false Assoc array of API response, decoded from JSON

subscriberHash() public method

Convert an email address into a 'subscriber hash' for identifying the subscriber in a method URL
public subscriberHash ( string $email ) : string
$email string The subscriber's email address
return string Hashed version of the input

success() public method

Was the last request successful?
public success ( ) : boolean
return boolean True for success, false for failure

Property Details

$verify_ssl public_oe property

* SSL Verification Read before disabling: http://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/
public $verify_ssl