Skip to content

Commit 0fd74d5

Browse files
Merge pull request #149 from reedmaniac/4.x
Twilio 4.x
2 parents 783a74f + cd1949e commit 0fd74d5

File tree

5 files changed

+38
-54
lines changed

5 files changed

+38
-54
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ $twilio->call('+18085551212', function ($message) {
102102
});
103103
```
104104

105-
Access the configured `\Services_Twilio` object:
105+
Access the configured `Twilio\Rest\Client` object:
106106

107107
```php
108108
$sdk = $twilio->getTwilio();
@@ -116,15 +116,15 @@ $sdk = Twilio::getTwilio();
116116

117117
##### Pass as many optional parameters as you want
118118

119-
If you want to pass on extra optional parameters to the `messages->sendMessage(...)` method [from the Twilio SDK](https://twilio-php.readthedocs.io/en/latest/api/rest.html#Services_Twilio_Rest_Messages::sendMessage), you can do so
119+
If you want to pass on extra optional parameters to the `messages->sendMessage(...)` method [from the Twilio SDK](https://www.twilio.com/docs/api/messaging/send-messages), you can do so
120120
by adding to the `message` method. All arguments are passed on, and the `from` field is prepended from configuration.
121121

122122
```php
123123
$twilio->message($to, $message, $mediaUrls, $params);
124124
// passes all these arguments on.
125125
```
126126

127-
The same is true for the [call method](https://twilio-php.readthedocs.io/en/latest/api/rest.html#Services_Twilio_Rest_Calls::create).
127+
The same is true for the [call method](https://www.twilio.com/docs/api/voice/call#post-parameters).
128128

129129
```php
130130
$twilio->call($to, $message, $params);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"license": "MIT",
1818
"require": {
1919
"php": ">=5.5.0",
20-
"twilio/sdk":">=3.12.0,<5.0.0"
20+
"twilio/sdk":"5.*"
2121
},
2222
"require-dev": {
2323
"friendsofphp/php-cs-fixer": "^1.9",

src/Manager.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ public function from($connection)
3838

3939
$settings = $this->settings[$connection];
4040

41-
if (isset($settings['ssl_verify'])) {
42-
return new Twilio($settings['sid'], $settings['token'], $settings['from'], $settings['ssl_verify']);
43-
}
44-
45-
// Let the Twilio constructor decide the default value for ssl_verify
4641
return new Twilio($settings['sid'], $settings['token'], $settings['from']);
4742
}
4843

src/Twilio.php

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
namespace Aloha\Twilio;
33

4-
use Services_Twilio;
5-
use Services_Twilio_TinyHttp;
6-
use Services_Twilio_Twiml;
4+
use Twilio\Rest\Client;
5+
use Twilio\Twiml;
76

87
class Twilio implements TwilioInterface
98
{
@@ -26,9 +25,9 @@ class Twilio implements TwilioInterface
2625
* @var bool
2726
*/
2827
protected $sslVerify;
29-
28+
3029
/**
31-
* @var \Services_Twilio
30+
* @var \Twilio\Rest\Client
3231
*/
3332
protected $twilio;
3433

@@ -49,63 +48,65 @@ public function __construct($sid, $token, $from, $sslVerify = true)
4948
/**
5049
* @param string $to
5150
* @param string $message
51+
* @param array|null $mediaUrls
52+
* @param array $params
53+
*
54+
* @link https://www.twilio.com/docs/api/messaging/send-messages Documentation
5255
*
53-
* @return \Services_Twilio_Rest_Message
56+
* @return \Twilio\Rest\Api\V2010\Account\MessageInstance
5457
*/
55-
public function message($to, $message)
58+
public function message($to, $message, $mediaUrls = null, array $params = [])
5659
{
57-
$arguments = func_get_args();
60+
$options['body'] = $message;
5861

59-
array_unshift($arguments, $this->from);
62+
if (!isset($options['from'])) {
63+
$options['from'] = $this->from;
64+
}
65+
66+
if (!empty($medialUrls)) {
67+
$options['mediaUrl'] = $mediaUrls;
68+
}
6069

61-
return call_user_func_array([$this->getTwilio()->account->messages, 'sendMessage'], $arguments);
70+
return $this->getTwilio()->messages->create($to, $options);
6271
}
6372

6473
/**
6574
* @param string $to
6675
* @param string|callable $message
6776
*
68-
* @return \Services_Twilio_Rest_Call
77+
* @link https://www.twilio.com/docs/api/voice/making-calls Documentation
78+
*
79+
* @return \Twilio\Rest\Api\V2010\Account\CallInstance
6980
*/
70-
public function call($to, $message)
81+
public function call($to, $message, array $params = [])
7182
{
72-
$arguments = func_get_args();
73-
74-
array_unshift($arguments, $this->from);
75-
7683
if (is_callable($message)) {
7784
$query = http_build_query([
7885
'Twiml' => $this->twiml($message),
7986
]);
8087

81-
$arguments[2] = 'https://twimlets.com/echo?'.$query;
88+
$message = 'https://twimlets.com/echo?'.$query;
8289
}
8390

84-
return call_user_func_array([$this->getTwilio()->account->calls, 'create'], $arguments);
91+
$params['url'] = $message;
92+
93+
return $this->getTwilio()->calls->create(
94+
$to,
95+
$this->from,
96+
$params
97+
);
8598
}
8699

87100
/**
88-
* @return \Services_Twilio
101+
* @return \Twilio\Rest\Client
89102
*/
90103
public function getTwilio()
91104
{
92105
if ($this->twilio) {
93106
return $this->twilio;
94107
}
95-
96-
if (!$this->sslVerify) {
97-
$http = new Services_Twilio_TinyHttp(
98-
'https://api.twilio.com',
99-
[
100-
'curlopts' => [
101-
CURLOPT_SSL_VERIFYPEER => false,
102-
CURLOPT_SSL_VERIFYHOST => 2,
103-
],
104-
]
105-
);
106-
}
107108

108-
return $this->twilio = new Services_Twilio($this->sid, $this->token, null, isset($http) ? $http : null);
109+
return $this->twilio = new Client($this->sid, $this->token);
109110
}
110111

111112
/**
@@ -115,7 +116,7 @@ public function getTwilio()
115116
*/
116117
private function twiml(callable $callback)
117118
{
118-
$message = new Services_Twilio_Twiml();
119+
$message = new Twiml();
119120

120121
call_user_func($callback, $message);
121122

src/config/config.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@
4242
*/
4343

4444
'from' => getenv('TWILIO_FROM') ?: '',
45-
46-
/*
47-
|--------------------------------------------------------------------------
48-
| Verify Twilio's SSL Certificates
49-
|--------------------------------------------------------------------------
50-
|
51-
| Allows the client to bypass verifying Twilio's SSL certificates.
52-
| It is STRONGLY advised to leave this set to true for production environments.
53-
|
54-
*/
55-
56-
'ssl_verify' => true,
5745
],
5846
],
5947
],

0 commit comments

Comments
 (0)