HTTP Helper Classes

The Twilio Rest Client

class Services_Twilio

Create a client to talk to the Twilio Rest API.

Parameters:
  • $sid (string) – Your Account SID
  • $token (string) – Your Auth Token from your dashboard
  • $version (string) – API version to use
  • $_http (Services_Twilio_TinyHttp) – A HTTP client for making requests.
  • $retryAttempts (int) – Number of times to retry failed requests. Currently only idempotent requests (GET’s and DELETE’s) are retried.

Here’s an example:

require('Services/Twilio.php');
$client = new Services_Twilio('AC123', '456bef', null, null, 3);
// Take some action with the client, etc.

Twilio’s Custom HTTP Client

class Services_Twilio_TinyHttp

An HTTP client that makes requests

Parameters:
  • $uri (string) – The base uri to use for requests
  • $kwargs (array) –

    An array of additional arguments to pass to the library. Accepted arguments are:

    • debug - Print the HTTP request before making it to Twilio
    • curlopts - An array of keys and values that are passed to
      curl_setopt_array.

Here’s an example. This is the default HTTP client used by the library.

$_http = new Services_Twilio_TinyHttp(
    "https://api.twilio.com",
    array("curlopts" => array(
        CURLOPT_USERAGENT => self::USER_AGENT,
        CURLOPT_HTTPHEADER => array('Accept-Charset: utf-8'),
        CURLOPT_CAINFO => dirname(__FILE__) . '/cacert.pem',
    ))
);

Twilio Rest Exceptions

class Services_Twilio_RestException

An exception talking to the Twilio API. This is thrown whenever the Twilio API returns a 400 or 500-level exception.

Parameters:
  • $status (int) – the HTTP status for the exception
  • $message (string) – a human-readable error message for the exception
  • $code (int) – a Twilio-specific error code for the exception
  • $info (string) – a link to more information
getStatus()

Get the HTTP status code

getInfo()

Get a link to more information