Permalink
Browse files

Merge branch 'master' into add-docs

  • Loading branch information...
2 parents 97bba87 + 14abd80 commit e125c56bccc5f2313ed8e09d36c12d547c16bce3 Kevin Burke committed Jul 31, 2012
View
@@ -1,6 +1,23 @@
twilio-php Changelog
====================
+Version 3.5.2
+-------------
+
+Released on July 23, 2012
+
+- Fix an issue introduced in the 3.5.0 release where updating or muting
+ a participant would [throw an exception instead of muting the
+ participant][mute-request].
+ (Reporter: [Alex Chan](/alexcchan))
+
+- Fix an issue introduced in the 3.5.0 release where [filtering an iterator
+with parameters would not work properly][paging-request] on subsequent HTTP
+requests. (Reporters: [Alex Chan](/alexcchan), Ivor O'Connor)
+
+[mute-request]: /twilio/twilio-php/pull/74
+[paging-request]: /twilio/twilio-php/pull/75
+
Version 3.5.1
-------------
View
@@ -56,7 +56,10 @@ how to get the most out of **twilio-php**.
// This line loads the library
require('/path/to/twilio-php/Services/Twilio.php');
-$client = new Services_Twilio('AC123', '123');
+$sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account
+$token = "YYYYYY"; // Your Auth Token from www.twilio.com/user/account
+
+$client = new Services_Twilio($sid, $token);
$message = $client->account->sms_messages->create(
'9991231234', // From a valid Twilio number
'8881231234', // Text this number
View
@@ -22,7 +22,7 @@ function Services_Twilio_autoload($className) {
*/
class Services_Twilio extends Services_Twilio_Resource
{
- const USER_AGENT = 'twilio-php/3.5.1';
+ const USER_AGENT = 'twilio-php/3.5.2';
protected $http;
protected $version;
@@ -49,10 +49,10 @@ public function get($sid)
* @return Services_Twilio_InstanceResource An instance with properties
* initialized to the values in the params array.
*/
- public function getObjectFromJson($params)
+ public function getObjectFromJson($params, $idParam = "sid")
{
- if (isset($params->sid)) {
- $uri = $this->uri . "/" . $params->sid;
+ if (isset($params->{$idParam})) {
+ $uri = $this->uri . "/" . $params->{$idParam};
} else {
$uri = $this->uri;
}
@@ -107,7 +107,7 @@ public function getPage(
) {
$list_name = $this->getResourceName();
if ($deep_paging_uri !== null) {
- $page = $this->client->retrieveData($deep_paging_uri, $filters, true);
+ $page = $this->client->retrieveData($deep_paging_uri, array(), true);
} else {
$page = $this->client->retrieveData($this->uri, array(
'Page' => $page,
@@ -3,4 +3,8 @@
class Services_Twilio_Rest_Participants
extends Services_Twilio_ListResource
{
+ /* Participants are identified by CallSid, not like PI123 */
+ public function getObjectFromJson($params, $idParam = "sid") {
+ return parent::getObjectFromJson($params, "call_sid");
+ }
}
View
@@ -152,7 +152,7 @@ Calls
.. php:class:: Services_Twilio_Rest_Calls
- For more information, see the `Call Instance Resource <http://www.twilio.com/docs/api/rest/call#list>`_ documentation.
+ For more information, see the `Call List Resource <http://www.twilio.com/docs/api/rest/call#list>`_ documentation.
.. php:method:: create($from, $to, $url, array $params = array())
View
@@ -51,7 +51,7 @@
# The short X.Y version.
version = '3.5'
# The full version, including alpha/beta/rc tags.
-release = '3.5.1'
+release = '3.5.2'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
View
@@ -10,7 +10,7 @@
Status
=======
-This documentation is for version 3.5.1 of `twilio-php <https://www.github.com/twilio/twilio-php>`_.
+This documentation is for version 3.5.2 of `twilio-php <https://www.github.com/twilio/twilio-php>`_.
Quickstart
============
@@ -18,12 +18,60 @@ The :class:`Calls` resource allows you to make outgoing calls:
print $call->length;
print $call->sid;
+Adding Extra Call Parameters
+============================
+
+Add extra parameters, like a `StatusCallback` when the call ends, like this:
+
+.. code-block:: php
+
+ $client = new Services_Twilio('AC123', '123');
+ $call = $client->account->calls->create(
+ '9991231234', // From this number
+ '8881231234', // Call this number
+ 'http://foo.com/call.xml',
+ array(
+ 'StatusCallback' => 'http://foo.com/callback',
+ 'StatusCallbackMethod' => 'GET'
+ )
+ );
+
+A full list of extra parameters can be found `here
+<http://www.twilio.com/docs/api/rest/making-calls#post-parameters-optional>`_.
+
+Listing Calls
+=============
+
+It's easy to iterate over your list of calls.
+
+.. code-block:: php
+
+ $client = new Services_Twilio('AC123', '123');
+ foreach ($client->account->calls as $call) {
+ echo "From: {$call->from}\nTo: {$call->to}\nSid: {$call->sid}\n\n";
+ }
+
+Filtering Calls
+======================
+
+Let's say you want to find all of the calls that have been sent from
+a particular number. You can do so by constructing an iterator explicitly:
+
+.. code-block:: php
+
+ $client = new Services_Twilio('AC123', '123');
+ foreach ($client->account->calls->getIterator(0, 50, array(
+ 'From' => '+14105551234',
+ ) as $call) {
+ echo "From: {$call->from}\nTo: {$call->to}\nSid: {$call->sid}\n\n";
+ }
+
Accessing Resources from a Specific Call
========================================
-The :class:`Call` resource has some sub resources you can access, such as
+The :class:`Call` resource has some subresources you can access, such as
notifications and recordings. If you have already have a :class:`Call`
-resource, they are easy to get.:
+resource, they are easy to get:
.. code-block:: php
@@ -51,8 +99,8 @@ resource, they are easy to get.:
}
}
-Be careful, as the above code makes quite a few HTTP requests and display
-numerous PHP warnings for unintialized variables.
+Be careful, as the above code makes quite a few HTTP requests and may display
+PHP warnings for unintialized variables.
Retrieve a Call Record
======================
@@ -19,3 +19,30 @@ The :class:`SmsMessages` resource allows you to send outgoing text messages.
);
print $message->sid;
+
+Listing SMS Messages
+====================
+
+It's easy to iterate over your SMS messages.
+
+.. code-block:: php
+
+ $client = new Services_Twilio('AC123', '123');
+ foreach ($client->account->sms_messages as $message) {
+ echo "From: {$message->from}\nTo: {$message->to}\nBody: " . $message->body;
+ }
+
+Filtering SMS Messages
+======================
+
+Let's say you want to find all of the SMS messages that have been sent from
+a particular number. You can do so by constructing an iterator explicitly:
+
+.. code-block:: php
+
+ $client = new Services_Twilio('AC123', '123');
+ foreach ($client->account->sms_messages->getIterator(0, 50, array(
+ 'From' => '+14105551234',
+ ) as $message) {
+ echo "From: {$message->from}\nTo: {$message->to}\nBody: " . $message->body;
+ }
View
@@ -35,12 +35,12 @@
require_once 'PEAR/PackageFileManager2.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);
-$api_version = '3.5.1';
+$api_version = '3.5.2';
$api_state = 'stable';
-$release_version = '3.5.1';
+$release_version = '3.5.2';
$release_state = 'stable';
-$release_notes = 'Hotfix for an error in the 3.5.0 release';
+$release_notes = 'Hotfix for two errors introduced the 3.5.0 release';
$description = <<<DESC
A SDK (or helper library, as we're calling them) for PHP developers to write
@@ -245,7 +245,6 @@ function testBadMessageThrowsException() {
}
}
-
class CallsTest extends PHPUnit_Framework_TestCase
{
/**
View
@@ -268,7 +268,7 @@ function testUnmute() {
'/2010-04-01/Accounts/AC123/Conferences/CF123/Participants.json?Page=0&PageSize=10')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array(
- 'participants' => array(array('sid' => 'CA123'))
+ 'participants' => array(array('call_sid' => 'CA123'))
))
));
$http->shouldReceive('post')->once()
@@ -378,4 +378,43 @@ function testDeepPagingUsesAfterSid() {
}
}
+ function testIteratorWithFiltersPagesCorrectly() {
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $recordingsBase = '/2010-04-01/Accounts/AC123/Recordings.json';
+ $firstPageUri = $recordingsBase . '?Page=0&PageSize=1&DateCreated%3E=2011-01-01';
+ $secondPageUri = $recordingsBase . '?DateCreated%3E=2011-01-01&Page=1&PageSize=1';
+ $thirdPageUri = $recordingsBase . '?DateCreated%3E=2011-01-01&Page=2&PageSize=1';
+ $http->shouldReceive('get')->once()
+ ->with($firstPageUri)
+ ->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array(
+ 'next_page_uri' => $secondPageUri,
+ 'recordings' => array(array(
+ 'sid' => 'RE123',
+ 'duration' => 7,
+ ))
+ ))
+ ));
+ $http->shouldReceive('get')->once()
+ ->with($secondPageUri)
+ ->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array(
+ 'next_page_uri' => $thirdPageUri,
+ 'recordings' => array(array(
+ 'sid' => 'RE123',
+ 'duration' => 7,
+ ))
+ ))
+ ));
+ $http->shouldReceive('get')->once()
+ ->with($thirdPageUri)
+ ->andReturn(array(400, array('Content-Type' => 'application/json'),
+ '{"status":400,"message":"foo", "code": "20006"}'
+ ));
+
+ $client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
+ foreach ($client->account->recordings->getIterator(0, 1, array('DateCreated>' => '2011-01-01')) as $recording) {
+ $this->assertSame($recording->duration, 7);
+ }
+ }
}

0 comments on commit e125c56

Please sign in to comment.