Skip to content

Commit

Permalink
Rename sendMms and sendSms to sendMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Burke committed Sep 12, 2013
1 parent 8b43c94 commit 8a6413a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 49 deletions.
52 changes: 11 additions & 41 deletions Services/Twilio/Rest/Messages.php
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TwilioTest.php
Expand Up @@ -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');
Expand Down
13 changes: 6 additions & 7 deletions tests/resources/MessagesTest.php
Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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() {
Expand Down

0 comments on commit 8a6413a

Please sign in to comment.