From 8a6413a658519a2057df61eb16da9c23b8049df6 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Thu, 12 Sep 2013 10:34:16 -0700 Subject: [PATCH] Rename sendMms and sendSms to sendMessage --- Services/Twilio/Rest/Messages.php | 52 +++++++------------------------ tests/TwilioTest.php | 2 +- tests/resources/MessagesTest.php | 13 ++++---- 3 files changed, 18 insertions(+), 49 deletions(-) diff --git a/Services/Twilio/Rest/Messages.php b/Services/Twilio/Rest/Messages.php index 7bb33be87..f14685b21 100644 --- a/Services/Twilio/Rest/Messages.php +++ b/Services/Twilio/Rest/Messages.php @@ -21,57 +21,24 @@ public function create($params = array()) { } /** - * Send an SMS message + * Send a message * * .. code-block:: php * * $client = new Services_Twilio('AC123', '123'); - * $message = $client->account->messages->sendSms( - * '+14085551234', // From a Twilio number in your account - * '+12125551234', // Text any number - * 'Hello monkey!', // Message body - * )); - * - * :param string $from: the from number for the message, this must be a - * number you purchased from Twilio - * :param string $to: the message recipient's phone number - * :param string $body: the text to include along with this MMS - * :param array $params: Any additional params (callback, etc) you'd like to - * send with this request, these are serialized and sent as POST - * parameters - * - * :returns: The created SMS - * :returntype: :php:class:`Services_Twilio_Rest_Message` - * :exception: :php:class:`Services_Twilio_RestException` - * An exception if the parameters are - * invalid (for example, the from number is not a Twilio number - * registered to your account) - */ - public function sendSms($from, $to, $body, $params = array()) { - return self::create(array( - 'From' => $from, - 'To' => $to, - 'Body' => $body, - ) + $params); - } - - /** - * Send an MMS message - * - * .. code-block:: php - * - * $client = new Services_Twilio('AC123', '123'); - * $message = $client->account->messages->sendMms( + * $message = $client->account->messages->sendMessage( * '+14085551234', // From a Twilio number in your account * '+12125551234', // Text any number * array('http://example.com/image.jpg'), // An array of MediaUrls - * 'Hello monkey!', // Message body (if any) + * 'Come at the king, you best not miss.', // Message body (if any) * )); * * :param string $from: the from number for the message, this must be a * number you purchased from Twilio * :param string $to: the message recipient's phone number - * :param string|array $mediaUrls: the URLs of images to send in this MMS + * :param $mediaUrls: the URLs of images to send in this MMS + * :type $mediaUrls: null (don't include media), a single URL, or an array + * of URLs to send as media with this message * :param string $body: the text to include along with this MMS * :param array $params: Any additional params (callback, etc) you'd like to * send with this request, these are serialized and sent as POST @@ -83,14 +50,17 @@ public function sendSms($from, $to, $body, $params = array()) { * number is not a Twilio number registered to your account, or is * unable to send MMS) */ - public function sendMms($from, $to, $mediaUrls, $body = null, + public function sendMessage($from, $to, $body = null, $mediaUrls = null, $params = array() ) { $postParams = array( 'From' => $from, 'To' => $to, - 'MediaUrl' => $mediaUrls, ); + // When the request is made, this will get serialized into MediaUrl=a&MediaUrl=b + if (!is_null($mediaUrls)) { + $postParams['MediaUrl'] = $mediaUrls; + } if (!is_null($body)) { $postParams['Body'] = $body; } diff --git a/tests/TwilioTest.php b/tests/TwilioTest.php index b113121fa..a412c1187 100644 --- a/tests/TwilioTest.php +++ b/tests/TwilioTest.php @@ -625,7 +625,7 @@ function testPostMultivaluedForm() { ) ); $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); - $message = $client->account->messages->sendMms('123', '123', + $message = $client->account->messages->sendMessage('123', '123', null, array('http://example.com/image1', 'http://example.com/image2') ); $this->assertSame($message->sid, 'SM123'); diff --git a/tests/resources/MessagesTest.php b/tests/resources/MessagesTest.php index 1c69851e1..8a0936c7e 100644 --- a/tests/resources/MessagesTest.php +++ b/tests/resources/MessagesTest.php @@ -15,7 +15,7 @@ function testCreateMessage() { json_encode(array('sid' => 'SM123')) )); $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); - $msg = $client->account->messages->sendSms('+1222', '+44123', 'Hi there'); + $msg = $client->account->messages->sendMessage('+1222', '+44123', 'Hi there'); $this->assertSame('SM123', $msg->sid); } @@ -28,7 +28,7 @@ function testCreateMessageWithMedia() { json_encode(array('sid' => 'SM123')) )); $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); - $msg = $client->account->messages->sendMms('+1222', '+44123', + $msg = $client->account->messages->sendMessage('+1222', '+44123', null, array('http://example.com/image1')); $this->assertSame('SM123', $msg->sid); } @@ -42,9 +42,8 @@ function testCreateMessageWithMediaAndBody() { json_encode(array('sid' => 'SM123')) )); $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); - $msg = $client->account->messages->sendMms('+1222', '+44123', - array('http://example.com/image1'), - 'Hi there' + $msg = $client->account->messages->sendMessage('+1222', '+44123', 'Hi there', + array('http://example.com/image1') ); $this->assertSame('SM123', $msg->sid); } @@ -58,7 +57,7 @@ function testCreateMessageWithMultipleMedia() { json_encode(array('sid' => 'SM123')) )); $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); - $msg = $client->account->messages->sendMms('+1222', '+44123', + $msg = $client->account->messages->sendMessage('+1222', '+44123', null, array('http://example.com/image1', 'http://example.com/image2')); $this->assertSame('SM123', $msg->sid); } @@ -76,7 +75,7 @@ function testBadMessageThrowsException() { )) )); $client = new Services_Twilio('AC123', '123', null, $http); - $msg = $client->account->messages->sendSms('+1222', '+44123', str_repeat('hi', 801)); + $msg = $client->account->messages->sendMessage('+1222', '+44123', str_repeat('hi', 801)); } function testRawCreate() {