From 7dc8d09fb4444128eed31286f37929f9ca0f9757 Mon Sep 17 00:00:00 2001 From: Paul Burdick Date: Sun, 7 Jan 2018 11:04:50 -0800 Subject: [PATCH 1/7] Updating the Twilio SDK version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fb7306b..8bf6fee 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "license": "MIT", "require": { "php": ">=5.5.0", - "twilio/sdk":">=3.12.0,<5.0.0" + "twilio/sdk":"5.*" }, "require-dev": { "friendsofphp/php-cs-fixer": "^1.9", From b3e80de23d16f10e7c64fb183b11817e4ef4c512 Mon Sep 17 00:00:00 2001 From: Paul Burdick Date: Sun, 7 Jan 2018 12:14:01 -0800 Subject: [PATCH 2/7] First draft of the Twilio 5.x library update --- README.md | 6 ++--- src/Manager.php | 5 ---- src/Twilio.php | 59 ++++++++++++++++++++----------------------- src/config/config.php | 12 --------- 4 files changed, 31 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 23be4b0..637d732 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ $twilio->call('+18085551212', function ($message) { }); ``` -Access the configured `\Services_Twilio` object: +Access the configured `Twilio\Rest\Client` object: ```php $sdk = $twilio->getTwilio(); @@ -116,7 +116,7 @@ $sdk = Twilio::getTwilio(); ##### Pass as many optional parameters as you want -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 +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 by adding to the `message` method. All arguments are passed on, and the `from` field is prepended from configuration. ```php @@ -124,7 +124,7 @@ $twilio->message($to, $message, $mediaUrls, $params); // passes all these arguments on. ``` -The same is true for the [call method](https://twilio-php.readthedocs.io/en/latest/api/rest.html#Services_Twilio_Rest_Calls::create). +The same is true for the [call method](https://www.twilio.com/docs/api/voice/call#post-parameters). ```php $twilio->call($to, $message, $params); diff --git a/src/Manager.php b/src/Manager.php index 2460a42..1354c8f 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -38,11 +38,6 @@ public function from($connection) $settings = $this->settings[$connection]; - if (isset($settings['ssl_verify'])) { - return new Twilio($settings['sid'], $settings['token'], $settings['from'], $settings['ssl_verify']); - } - - // Let the Twilio constructor decide the default value for ssl_verify return new Twilio($settings['sid'], $settings['token'], $settings['from']); } diff --git a/src/Twilio.php b/src/Twilio.php index 9eca882..abbbc0a 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -1,9 +1,8 @@ from; + } - array_unshift($arguments, $this->from); + if (!empty($medialUrls)) { + $options['mediaUrl'] = $mediaUrls; + } - return call_user_func_array([$this->getTwilio()->account->messages, 'sendMessage'], $arguments); + return $this->getTwilio->create($to, $options); } /** @@ -67,45 +74,35 @@ public function message($to, $message) * * @return \Services_Twilio_Rest_Call */ - public function call($to, $message) + public function call($to, $message, array $params = []) { - $arguments = func_get_args(); - - array_unshift($arguments, $this->from); - if (is_callable($message)) { $query = http_build_query([ 'Twiml' => $this->twiml($message), ]); - $arguments[2] = 'https://twimlets.com/echo?'.$query; + $message = 'https://twimlets.com/echo?'.$query; } - return call_user_func_array([$this->getTwilio()->account->calls, 'create'], $arguments); + $params['url'] = $message; + + return $this->getTwilio->calls->create( + $to, + $this->from, + $params + ); } /** - * @return \Services_Twilio + * @return \Twilio\Rest\Client */ public function getTwilio() { if ($this->twilio) { return $this->twilio; } - - if (!$this->sslVerify) { - $http = new Services_Twilio_TinyHttp( - 'https://api.twilio.com', - [ - 'curlopts' => [ - CURLOPT_SSL_VERIFYPEER => false, - CURLOPT_SSL_VERIFYHOST => 2, - ], - ] - ); - } - return $this->twilio = new Services_Twilio($this->sid, $this->token, null, isset($http) ? $http : null); + return $this->twilio = new Client($this->sid, $this->token); } /** @@ -115,7 +112,7 @@ public function getTwilio() */ private function twiml(callable $callback) { - $message = new Services_Twilio_Twiml(); + $message = new Twiml(); call_user_func($callback, $message); diff --git a/src/config/config.php b/src/config/config.php index 7b38373..0366ece 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -42,18 +42,6 @@ */ 'from' => getenv('TWILIO_FROM') ?: '', - - /* - |-------------------------------------------------------------------------- - | Verify Twilio's SSL Certificates - |-------------------------------------------------------------------------- - | - | Allows the client to bypass verifying Twilio's SSL certificates. - | It is STRONGLY advised to leave this set to true for production environments. - | - */ - - 'ssl_verify' => true, ], ], ], From 467f6c8c88670a48c27fc3335893a80a1ff0bac6 Mon Sep 17 00:00:00 2001 From: Paul Burdick Date: Sun, 7 Jan 2018 12:20:03 -0800 Subject: [PATCH 3/7] Supposed to be a Method not a variable --- src/Twilio.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Twilio.php b/src/Twilio.php index abbbc0a..5492d68 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -65,7 +65,7 @@ public function message($to, $message, $mediaUrls = null, array $params = []) $options['mediaUrl'] = $mediaUrls; } - return $this->getTwilio->create($to, $options); + return $this->getTwilio()->create($to, $options); } /** @@ -86,7 +86,7 @@ public function call($to, $message, array $params = []) $params['url'] = $message; - return $this->getTwilio->calls->create( + return $this->getTwilio()->calls->create( $to, $this->from, $params From c0b5d286e754f6fd07556478d279e0d45c8f890f Mon Sep 17 00:00:00 2001 From: Paul Burdick Date: Sun, 7 Jan 2018 12:22:20 -0800 Subject: [PATCH 4/7] Seems we have a message --- src/Twilio.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Twilio.php b/src/Twilio.php index 5492d68..e35499c 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -65,7 +65,7 @@ public function message($to, $message, $mediaUrls = null, array $params = []) $options['mediaUrl'] = $mediaUrls; } - return $this->getTwilio()->create($to, $options); + return $this->getTwilio()->messages->create($to, $options); } /** From 8cef2875b85676270f7d41d57b5fc1cc62b6c8e1 Mon Sep 17 00:00:00 2001 From: Paul Burdick Date: Sun, 7 Jan 2018 12:25:43 -0800 Subject: [PATCH 5/7] Add PHPDoc @link attribute for calls and message --- src/Twilio.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Twilio.php b/src/Twilio.php index e35499c..a920b5a 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -51,6 +51,8 @@ public function __construct($sid, $token, $from, $sslVerify = true) * @param array|null $mediaUrls * @param array $params * + * @link https://www.twilio.com/docs/api/messaging/send-messages Documentation + * * @return \Services_Twilio_Rest_Message */ public function message($to, $message, $mediaUrls = null, array $params = []) @@ -72,6 +74,8 @@ public function message($to, $message, $mediaUrls = null, array $params = []) * @param string $to * @param string|callable $message * + * @link https://www.twilio.com/docs/api/voice/making-calls Documentation + * * @return \Services_Twilio_Rest_Call */ public function call($to, $message, array $params = []) From a4b5caea347a5962f526d6fbd710078500ec4343 Mon Sep 17 00:00:00 2001 From: Paul Burdick Date: Sun, 7 Jan 2018 12:33:12 -0800 Subject: [PATCH 6/7] Updating code comments to have new correct class return --- src/Twilio.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Twilio.php b/src/Twilio.php index a920b5a..5640136 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -53,7 +53,7 @@ public function __construct($sid, $token, $from, $sslVerify = true) * * @link https://www.twilio.com/docs/api/messaging/send-messages Documentation * - * @return \Services_Twilio_Rest_Message + * @return \Twilio\Rest\Api\V2010\Account\MessageInstance */ public function message($to, $message, $mediaUrls = null, array $params = []) { @@ -76,7 +76,7 @@ public function message($to, $message, $mediaUrls = null, array $params = []) * * @link https://www.twilio.com/docs/api/voice/making-calls Documentation * - * @return \Services_Twilio_Rest_Call + * @return \Twilio\Rest\Api\V2010\Account\MessageInstance */ public function call($to, $message, array $params = []) { From cd1949efcef95b1ad2212372df3ab5091d472eb4 Mon Sep 17 00:00:00 2001 From: Paul Burdick Date: Sun, 7 Jan 2018 12:33:42 -0800 Subject: [PATCH 7/7] Whoops, wrong class --- src/Twilio.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Twilio.php b/src/Twilio.php index 5640136..77c779d 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -76,7 +76,7 @@ public function message($to, $message, $mediaUrls = null, array $params = []) * * @link https://www.twilio.com/docs/api/voice/making-calls Documentation * - * @return \Twilio\Rest\Api\V2010\Account\MessageInstance + * @return \Twilio\Rest\Api\V2010\Account\CallInstance */ public function call($to, $message, array $params = []) {