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/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", 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..77c779d 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -1,9 +1,8 @@ from); + if (!isset($options['from'])) { + $options['from'] = $this->from; + } + + if (!empty($medialUrls)) { + $options['mediaUrl'] = $mediaUrls; + } - return call_user_func_array([$this->getTwilio()->account->messages, 'sendMessage'], $arguments); + return $this->getTwilio()->messages->create($to, $options); } /** * @param string $to * @param string|callable $message * - * @return \Services_Twilio_Rest_Call + * @link https://www.twilio.com/docs/api/voice/making-calls Documentation + * + * @return \Twilio\Rest\Api\V2010\Account\CallInstance */ - 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 +116,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, ], ], ],