- if (!in_array('openssl', get_loaded_extensions())) {
- throw new Services_Twilio_HttpException("The OpenSSL extension is required but not currently enabled. For more information, see http://php.net/manual/en/book.openssl.php");
- }
- if (in_array('curl', get_loaded_extensions())) {
- * @param string $category The category of usage to fire a trigger for. A full list of categories can be found in the `Usage Categories documentation <http://www.twilio.com/docs/api/rest/usage-records#usage-categories>`_.
- * @param string $value Fire the trigger when usage crosses this value.
- * @param string $url The URL to request when the trigger fires.
- * @param array $params Optional parameters for this trigger. A full list of parameters can be found in the `Usage Trigger documentation <http://www.twilio.com/docs/api/rest/usage-triggers#list-post-optional-parameters>`_.
- * @return Services_Twilio_Rest_UsageTrigger The created trigger
- */
- function create($category, $value, $url, array $params = array()) {
- "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succint API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.",
- For more information, see the `AvailablePhoneNumbers API Resource <http://www.twilio.com/docs/api/rest/available-phone-numbers#local>`_ documentation at twilio.com.
-
- .. php:method:: getList($country, $type)
-
- Get a list of available phone numbers.
-
- :param string country: The 2-digit country code for numbers ('US', 'GB',
- 'CA')
- :param string type: The type of phone number ('TollFree' or 'Local')
- :return: An instance of the :php:class:`Services_Twilio_Rest_AvailablePhoneNumbers` resource.
-
- .. php:attr:: available_phone_numbers
-
- A list of :php:class:`Services_Twilio_Rest_AvailablePhoneNumber` instances.
-
- .. php:attr:: uri
-
- The uri representing this resource, relative to https://api.twilio.com.
-
-
-Calls
-=======
-
-.. php:class:: Services_Twilio_Rest_Calls
-
- For more information, see the `Call List Resource <http://www.twilio.com/docs/api/rest/call#list>`_ documentation.
- :param string $from: The phone number to use as the caller id.
- :param string $to: The number to call formatted with a '+' and country code
- :param string $url: The fully qualified URL that should be consulted when
- the call connects. This value can also be an ApplicationSid.
- :param array $params: An array of optional parameters for this call
-
- The **$params** array can contain the following keys:
-
- *Method*
- The HTTP method Twilio should use when making its request to the above Url parameter's value. Defaults to POST. If an ApplicationSid parameter is present, this parameter is ignored.
-
- *FallbackUrl*
- A URL that Twilio will request if an error occurs requesting or executing the TwiML at Url. If an ApplicationSid parameter is present, this parameter is ignored.
-
- *FallbackMethod*
- The HTTP method that Twilio should use to request the FallbackUrl. Must be either GET or POST. Defaults to POST. If an ApplicationSid parameter is present, this parameter is ignored.
-
- *StatusCallback*
- A URL that Twilio will request when the call ends to notify your app. If an ApplicationSid parameter is present, this parameter is ignored.
-
- *StatusCallbackMethod*
- The HTTP method Twilio should use when requesting the above URL. Defaults to POST. If an ApplicationSid parameter is present, this parameter is ignored.
-
- *SendDigits*
- A string of keys to dial after connecting to the number. Valid digits in the string include: any digit (0-9), '#' and '*'. For example, if you connected to a company phone number, and wanted to dial extension 1234 and then the pound key, use SendDigits=1234#. Remember to URL-encode this string, since the '#' character has special meaning in a URL.
-
- *IfMachine*
- Tell Twilio to try and determine if a machine (like voicemail) or a human has answered the call. Possible values are Continue and Hangup. See the answering machines section below for more info.
-
- *Timeout*
- The integer number of seconds that Twilio should allow the phone to ring before assuming there is no answer. Default is 60 seconds, the maximum is 999 seconds. Note, you could set this to a low value, such as 15, to hangup before reaching an answering machine or voicemail.
- For more information, including a list of filter parameters, see the `Member List Resource <http://www.twilio.com/docs/api/rest/member#list>`_ documentation.
-
- .. php:method:: front()
-
- Return the :php:class:`Services_Twilio_Rest_Member` at the front of the
- queue.
-
-Messages
-========
-
-.. phpautoclass:: Services_Twilio_Rest_Messages
- :filename: ../Services/Twilio/Rest/Messages.php
- :members:
-
-Queues
-===========
-
-.. php:class:: Services_Twilio_Rest_Queues
-
- For more information, including a list of filter parameters, see the
- `Queues List Resource <http://www.twilio.com/docs/api/rest/queues#list>`_
- Create a new :php:class:`Services_Twilio_Rest_Queue`.
-
- :param string $friendly_name: The name of the new Queue.
- :param array $params: An array of optional parameters and their values,
- like `MaxSize`.
- :returns: A new :php:class:`Services_Twilio_Rest_Queue`
-
-
-UsageRecords
-==============
-
-.. php:class:: Services_Twilio_Rest_UsageRecords
-
- For more information, including a list of filter parameters, see the `UsageRecords List Resource <http://www.twilio.com/docs/api/rest/usage-records#list>`_ documentation.
-
- .. php:method:: getCategory($category)
-
- Return the single UsageRecord corresponding to this category of usage.
- Valid only for the `Records`, `Today`, `Yesterday`, `ThisMonth`,
- `LastMonth` and `AllTime` resources.
-
- :param string $category: The category to retrieve a usage record for. For a full list of valid categories, see the full `Usage Category documentation <http://www.twilio.com/docs/api/rest/usage-records#usage-all-categories>`_.
- :returns: :php:class:`Services_Twilio_Rest_UsageRecord` A single usage record
- For more information, including a list of filter parameters, see the `UsageTriggers List Resource <http://www.twilio.com/docs/api/rest/usage-triggers#list>`_ documentation.
- :param string $category: The category of usage to fire a trigger for. A full list of categories can be found in the `Usage Categories documentation <http://www.twilio.com/docs/api/rest/usage-records#usage-categories>`_.
- :param string $value: Fire the trigger when usage crosses this value.
- :param string $url: The URL to request when the trigger fires.
- :param array $params: Optional parameters for this trigger. A full list of parameters can be found in the `Usage Trigger documentation <http://www.twilio.com/docs/api/rest/usage-triggers#list-post-optional-parameters>`_.
- :returns: :php:class:`Services_Twilio_Rest_UsageTrigger` The created trigger.
- For more information, see the `Account Instance Resource <http://www.twilio.com/docs/api/rest/account#instance>`_ documentation.
-
- .. php:method:: update($params)
-
- Update the account
-
- The **$params** array is the same as in :php:meth:`Services_Twilio_Rest_Accounts::create`
-
- .. php:attr:: sid
-
- A 34 character string that uniquely identifies this account.
-
- .. php:attr:: date_created
-
- The date that this account was created, in GMT in RFC 2822 format
-
- .. php:attr:: date_updated
-
- The date that this account was last updated, in GMT in RFC 2822 format.
-
- .. php:attr:: friendly_name
-
- A human readable description of this account, up to 64 characters long. By default the FriendlyName is your email address.
-
- .. php:attr:: status
-
- The status of this account. Usually active, but can be suspended if you've been bad, or closed if you've been horrible.
-
- .. php:attr:: auth_token
-
- The authorization token for this account. This token should be kept a secret, so no sharing.
-
-Application
-===========
-
-.. php:class:: Services_Twilio_Rest_Application
-
- For more information, see the `Application Instance Resource <http://www.twilio.com/docs/api/rest/applications#instance>`_ documentation.
-
- .. php:attr:: sid
-
- A 34 character string that uniquely idetifies this resource.
-
- .. php:attr:: date_created
-
- The date that this resource was created, given as GMT RFC 2822 format.
-
- .. php:attr:: date_updated
-
- The date that this resource was last updated, given as GMT RFC 2822 format.
-
- .. php:attr:: friendly_name
-
- A human readable descriptive text for this resource, up to 64 characters long. By default, the FriendlyName is a nicely formatted version of the phone number.
-
- .. php:attr:: account_sid
-
- The unique id of the Account responsible for this phone number.
-
- .. php:attr:: api_version
-
- Calls to this phone number will start a new TwiML session with this API version.
-
- .. php:attr:: voice_caller_id_lookup
-
- Look up the caller's caller-ID name from the CNAM database (additional charges apply). Either true or false.
-
- .. php:attr:: voice_url
-
- The URL Twilio will request when this phone number receives a call.
-
- .. php:attr:: voice_method
-
- The HTTP method Twilio will use when requesting the above Url. Either GET or POST.
-
- .. php:attr:: voice_fallback_url
-
- The URL that Twilio will request if an error occurs retrieving or executing the TwiML requested by Url.
-
- .. php:attr:: voice_fallback_method
-
- The HTTP method Twilio will use when requesting the VoiceFallbackUrl. Either GET or POST.
-
- .. php:attr:: status_callback
-
- The URL that Twilio will request to pass status parameters (such as call ended) to your application.
-
- .. php:attr:: status_callback_method
-
- The HTTP method Twilio will use to make requests to the StatusCallback URL. Either GET or POST.
-
- .. php:attr:: sms_url
-
- The URL Twilio will request when receiving an incoming SMS message to this number.
-
- .. php:attr:: sms_method
-
- The HTTP method Twilio will use when making requests to the SmsUrl. Either GET or POST.
-
- .. php:attr:: sms_fallback_url
-
- The URL that Twilio will request if an error occurs retrieving or executing the TwiML from SmsUrl.
-
- .. php:attr:: sms_fallback_method
-
- The HTTP method Twilio will use when requesting the above URL. Either GET or POST.
-
- .. php:attr:: uri
-
- The URI for this resource, relative to https://api.twilio.com.
- For more information, see the `AvailablePhoneNumber Instance Resource <http://www.twilio.com/docs/api/rest/available-phone-numbers#instance>`_ documentation.
-
- .. php:attr:: friendly_name
-
- A nicely-formatted version of the phone number.
-
- .. php:attr:: phone_number
-
- The phone number, in E.164 (i.e. "+1") format.
-
- .. php:attr:: lata
-
- The LATA of this phone number.
-
- .. php:attr:: rate_center
-
- The rate center of this phone number.
-
- .. php:attr:: latitude
-
- The latitude coordinate of this phone number.
-
- .. php:attr:: longitude
-
- The longitude coordinate of this phone number.
-
- .. php:attr:: region
-
- The two-letter state or province abbreviation of this phone number.
- For more information, see the `OutgoingCallerId Instance Resource <http://www.twilio.com/docs/api/rest/outgoing-caller-ids#instance>`_ documentation.
-
- .. php:attr:: sid
-
- A 34 character string that uniquely identifies this resource.
-
- .. php:attr:: date_created
-
- The date that this resource was created, given in RFC 2822 format.
-
- .. php:attr:: date_updated
-
- The date that this resource was last updated, given in RFC 2822 format.
-
- .. php:attr:: friendly_name
-
- A human readable descriptive text for this resource, up to 64 characters long. By default, the FriendlyName is a nicely formatted version of the phone number.
-
- .. php:attr:: account_sid
-
- The unique id of the Account responsible for this Caller Id.
-
- .. php:attr:: phone_number
-
- The incoming phone number. Formatted with a '+' and country code e.g., +16175551212 (E.164 format).
-
- .. php:attr:: uri
-
- The URI for this resource, relative to https://api.twilio.com.
-
-Conference
-=============
-
-.. php:class:: Services_Twilio_Rest_Conference
-
- For more information, see the `Conference Instance Resource <http://www.twilio.com/docs/api/rest/conference#instance>`_ documentation.
-
- .. php:attr:: sid
-
- A 34 character string that uniquely identifies this conference.
-
- .. php:attr:: friendly_name
-
- A user provided string that identifies this conference room.
-
- .. php:attr:: status
-
- A string representing the status of the conference. May be init, in-progress, or completed.
-
- .. php:attr:: date_created
-
- The date that this conference was created, given as GMT in RFC 2822 format.
-
- .. php:attr:: date_updated
-
- The date that this conference was last updated, given as GMT in RFC 2822 format.
-
- .. php:attr:: account_sid
-
- The unique id of the Account responsible for creating this conference.
-
- .. php:attr:: uri
-
- The URI for this resource, relative to https://api.twilio.com.
-
- .. php:attr:: participants
-
- The :php:class:`Services_Twilio_Rest_Participants` instance, listing people currently in this conference
- For more information, see the `Notification Instance Resource <http://www.twilio.com/docs/api/rest/notification#instance>`_ documentation.
-
- .. php:attr:: sid
-
- A 34 character string that uniquely identifies this resource.
-
- .. php:attr:: date_created
-
- The date that this resource was created, given in RFC 2822 format.
-
- .. php:attr:: date_updated
-
- The date that this resource was last updated, given in RFC 2822 format.
-
- .. php:attr:: account_sid
-
- The unique id of the Account responsible for this notification.
-
- .. php:attr:: call_sid
-
- CallSid is the unique id of the call during which the notification was generated. Empty if the notification was generated by the REST API without regard to a specific phone call.
-
- .. php:attr:: api_version
-
- The version of the Twilio in use when this notification was generated.
-
- .. php:attr:: log
-
- An integer log level corresponding to the type of notification: 0 is ERROR, 1 is WARNING.
-
- .. php:attr:: error_code
-
- A unique error code for the error condition. You can lookup errors, with possible causes and solutions, in our `Error Dictionary <http://www.twilio.com/docs/errors/reference>`_.
-
- .. php:attr:: more_info
-
- A URL for more information about the error condition. The URL is a page in our `Error Dictionary <http://www.twilio.com/docs/errors/reference>`_.
-
- .. php:attr:: message_text
-
- The text of the notification.
-
- .. php:attr:: message_date
-
- The date the notification was actually generated, given in RFC 2822
- format. Due to buffering, this may be slightly different than the
- DateCreated date.
-
- .. php:attr:: request_url
-
- The URL of the resource that generated the notification. If the
- notification was generated during a phone call: This is the URL of the
- resource on YOUR SERVER that caused the notification. If the notification
- was generated by your use of the REST API: This is the URL of the REST
- resource you were attempting to request on Twilio's servers.
-
- .. php:attr:: request_method
-
- The HTTP method in use for the request that generated the notification. If
- the notification was generated during a phone call: The HTTP Method use to
- request the resource on your server. If the notification was generated by
- your use of the REST API: This is the HTTP method used in your request to
- the REST resource on Twilio's servers.
-
- .. php:attr:: request_variables
-
- The Twilio-generated HTTP GET or POST variables sent to your server. Alternatively, if the notification was generated by the REST API, this field will include any HTTP POST or PUT variables you sent to the REST API.
-
- .. php:attr:: response_headers
-
- The HTTP headers returned by your server.
-
- .. php:attr:: response_body
-
- The HTTP body returned by your server.
-
- .. php:attr:: uri
-
- The URI for this resource, relative to https://api.twilio.com
- For more information about available properties, see the `Member Instance Resource <http://www.twilio.com/docs/api/rest/member#instance>`_ documentation.
-
- .. php:method:: dequeue($url, $method = 'POST')
-
- Dequeue this member and immediately play the Twiml at the given ``$url``.
-
- :param string $url: The Twiml URL to play for this member, after dequeuing them
- :param string $method: The HTTP method to use when fetching the Twiml URL. Defaults to POST.
- For more information, see the `SMS Message Instance Resource <http://www.twilio.com/docs/api/rest/sms#instance>`_ documentation.
-
- .. php:attr:: sid
-
- A 34 character string that uniquely identifies this resource.
-
- .. php:attr:: date_created
-
- The date that this resource was created, given in RFC 2822 format.
-
- .. php:attr:: date_updated
-
- The date that this resource was last updated, given in RFC 2822 format.
-
- .. php:attr:: date_sent
-
- The date that the SMS was sent, given in RFC 2822 format.
-
- .. php:attr:: account_sid
-
- The unique id of the Account that sent this SMS message.
-
- .. php:attr:: from
-
- The phone number that initiated the message in E.164 format. For incoming messages, this will be the remote phone. For outgoing messages, this will be one of your Twilio phone numbers.
-
- .. php:attr:: to
-
- The phone number that received the message in E.164 format. For incoming messages, this will be one of your Twilio phone numbers. For outgoing messages, this will be the remote phone.
-
- .. php:attr:: body
-
- The text body of the SMS message. Up to 160 characters long.
-
- .. php:attr:: status
-
- The status of this SMS message. Either queued, sending, sent, or failed.
-
- .. php:attr:: direction
-
- The direction of this SMS message. ``incoming`` for incoming messages,
- ``outbound-api`` for messages initiated via the REST API, ``outbound-call`` for
- messages initiated during a call or ``outbound-reply`` for messages initiated in
- response to an incoming SMS.
-
- .. php:attr:: price
-
- The amount billed for the message.
-
- .. php:attr:: api_version
-
- The version of the Twilio API used to process the SMS message.
-
- .. php:attr:: uri
-
- The URI for this resource, relative to https://api.twilio.com
-`Twilio Client <http://www.twilio.com/api/client>`_ allows you to make and recieve connections in the browser. You can place a call to a phone on the PSTN network, all without leaving your browser. See the `Twilio Client Quickstart <http:/www.twilio.com/docs/quickstart/client>`_ to get up and running with Twilio Client.
-
-Capability tokens are used by `Twilio Client <http://www.twilio.com/api/client>`_ to provide connection security and authorization. The `Capability Token documentation <http://www.twilio.con/docs/tokens>`_ explains indepth the purpose and features of these tokens.
-
-:php:class:`Services_Twilio_Capability` is responsible for the creation of these capability tokens. You'll need your Twilio AccountSid and AuthToken.
- $capability = new Services_Twilio_Capability($accountSid, $authToken);
-
-
-Allow Incoming Connections
-==============================
-
-Before a device running `Twilio Client <http://www.twilio.com/api/client>`_ can recieve incoming connections, the instance must first register a name (such as "Alice" or "Bob"). The :php:meth:`allowCclientIncoming` method adds the client name to the capability token.
-
-.. code-block:: php
-
- $capability->allowClientIncoming("Alice");
-
-
-Allow Outgoing Connections
-==============================
-
-To make an outgoing connection from a `Twilio Client <http://www.twilio.com/api/client>`_ device, you'll need to choose a `Twilio Application <http://www.twilio.com/docs/api/rest/applications>`_ to handle TwiML URLs. A Twilio Application is a collection of URLs responsible for outputing valid TwiML to control phone calls and SMS.
-:php:meth:`allowClientOutgoing` accepts an optional array of parameters. These parameters will be passed along when Twilio requests TwiML from the application.
-By default, this token will expire in one hour. If you'd like to change the token expiration time, :php:meth:`generateToken` takes an optional argument which specifies `time to live` in seconds.
-Twilio requires that your TwiML-serving web server be open to the public. This is necessary so that Twilio can retrieve TwiML from urls and POST data back to your server.
-
-However, there may be people out there trying to spoof the Twilio service. Luckily, there's an easy way to validate that incoming requests are from Twilio and Twilio alone.
-
-An `indepth guide <http://www.twilio.com/docs/security>`_ to our security features can be found in our online documentation.
-
-Before you can validate requests, you'll need four pieces of information
-
-* your Twilio Auth Token
-* the POST data for the request
-* the requested URL
-* the X-Twilio-Signature header value
-
-Get your Auth Token from the `Twilio User Dashboard <https://www.twilio.com/user/account>`_.
-
-Obtaining the other three pieces of information depends on the framework of your choosing. I will assume that you have the POST data as an array and the url and X-Twilio-Signature as strings.
-
-The below example will print out a confirmation message if the request is actually from Twilio.com
-
-.. code-block:: php
-
- // Your auth token from twilio.com/user/account
- $authToken = '12345';
-
- // Download the twilio-php library from twilio.com/docs/php/install, include it
- // The post variables in the Twilio request. You may be able to use
- // $postVars = $_POST
- $postVars = array(
- 'CallSid' => 'CA1234567890ABCDE',
- 'Caller' => '+14158675309',
- 'Digits' => '1234',
- 'From' => '+14158675309',
- 'To' => '+18005551212'
- );
-
- // The X-Twilio-Signature header - in PHP this should be
- // $_SERVER["HTTP_X_TWILIO_SIGNATURE"];
- $signature = 'RSOYDt4T1cUTdK1PDd93/VVr8B8=';
-
- if ($validator->validate($signature, $url, $postVars)) {
- echo "Confirmed to have come from Twilio.";
- } else {
- echo "NOT VALID. It might have been spoofed!";
- }
-
-Trailing Slashes
-==================
-
-If your URL uses an "index" page, such as index.php or index.html to handle the request, such as: https://mycompany.com/twilio where the real page is served from https://mycompany.com/twilio/index.php, then Apache or PHP may rewrite that URL a little bit so it's got a trailing slash... https://mycompany.com/twilio/ for example.
-
-Using the code above, or similar code in another language, you could end up with an incorrect hash because, Twilio built the hash using https://mycompany.com/twilio and you may have built the hash using https://mycompany.com/twilio/.