diff options
-rw-r--r-- | AUTHORS.md | 1 | ||||
-rw-r--r-- | CHANGES.md | 7 | ||||
-rw-r--r-- | README.md | 15 | ||||
-rw-r--r-- | Twilio/Http/CurlClient.php | 7 | ||||
-rw-r--r-- | Twilio/Tests/Unit/Http/CurlClientTest.php | 80 | ||||
-rw-r--r-- | Twilio/VersionInfo.php | 2 |
6 files changed, 103 insertions, 9 deletions
@@ -21,6 +21,7 @@ A huge thanks to all of our contributors: - D. Keith Casey, Jr. - Doug Black - Elliot Lings +- Jarod Reyes - Jen Li - Jingming Niu - John Britton @@ -1,6 +1,13 @@ twilio-php Changelog ==================== +Version 5.0.3 +------------- +Released August 18, 2016 + +- Adds the ability to pass options into `Twilio\Http\CurlClient`. This feature + brings `CurlClient` closer to parity with `Services_Twilio_TinyHttp`. + Version 5.0.2 ------------- Released August 16, 2016 @@ -14,16 +14,17 @@ You can install **twilio-php** via composer or by downloading the source. ### Send an SMS ```php +// Send an SMS using Twilio's REST API and PHP <?php -$sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account -$token = "YYYYYY"; // Your Auth Token from www.twilio.com/user/account +$sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/console +$token = "YYYYYY"; // Your Auth Token from www.twilio.com/console $client = new Twilio\Rest\Client($sid, $token); $message = $client->account->messages->create( '9991231234', // From a valid Twilio number '8881231234', // Text this number array( - 'Body' => "Hello monkey!" + 'Body' => "Hello from Twilio!" ) ); @@ -34,8 +35,8 @@ print $message->sid; ```php <?php -$sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account -$token = "YYYYYY"; // Your Auth Token from www.twilio.com/user/account +$sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/console +$token = "YYYYYY"; // Your Auth Token from www.twilio.com/console $client = new Twilio\Rest\Client($sid, $token); $call = $client->account->calls->create( @@ -92,6 +93,6 @@ If you need help installing or using the library, please contact Twilio Support If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo! -[apidocs]: http://twilio.github.io/twilio-php/ -[documentation]: https://twilio.com/api/docs +[apidocs]: https://twilio.com/api/docs +[documentation]: http://twilio.github.io/twilio-php/ [versioning]: https://github.com/twilio/twilio-php/blob/master/VERSIONS.md diff --git a/Twilio/Http/CurlClient.php b/Twilio/Http/CurlClient.php index cbb4b0e..6fb2dda 100644 --- a/Twilio/Http/CurlClient.php +++ b/Twilio/Http/CurlClient.php @@ -8,6 +8,11 @@ use Twilio\Exceptions\EnvironmentException; class CurlClient implements Client { const DEFAULT_TIMEOUT = 60; + protected $curlOptions = array(); + + public function __construct(array $options = array()) { + $this->curlOptions = $options; + } public function request($method, $url, $params = array(), $data = array(), $headers = array(), $user = null, $password = null, @@ -71,7 +76,7 @@ class CurlClient implements Client { ? self::DEFAULT_TIMEOUT : $timeout; - $options = array( + $options = $this->curlOptions + array( CURLOPT_URL => $url, CURLOPT_HEADER => true, CURLOPT_RETURNTRANSFER => true, diff --git a/Twilio/Tests/Unit/Http/CurlClientTest.php b/Twilio/Tests/Unit/Http/CurlClientTest.php index b8725e0..2c6c952 100644 --- a/Twilio/Tests/Unit/Http/CurlClientTest.php +++ b/Twilio/Tests/Unit/Http/CurlClientTest.php @@ -229,4 +229,84 @@ class CurlClientTest extends UnitTest { $this->assertEquals('a=1&b=2', fread($actual[CURLOPT_INFILE], $actual[CURLOPT_INFILESIZE])); $this->assertEquals(7, $actual[CURLOPT_INFILESIZE]); } + + /** + * @param string $message Case message, displayed on assertion error + * @param mixed[] $options Options to inject + * @param mixed[] $expected Partial array to expect + * @dataProvider userInjectedOptionsProvider + */ + public function testUserInjectedOptions($message, $options, $expected) { + $client = new CurlClient($options); + $actual = $client->options( + 'GET', + 'url', + array('param-key' => 'param-value'), + array('data-key' => 'data-value'), + array('header-key' => 'header-value'), + 'user', + 'password', + 20 + ); + foreach ($expected as $key => $value) { + $this->assertEquals($value, $actual[$key], $message); + } + } + + public function userInjectedOptionsProvider() { + return array( + array( + 'No Conflict Options', + array( + CURLOPT_VERBOSE => true, + ), + array( + CURLOPT_VERBOSE => true, + ), + ), + array( + 'Options preferred over Defaults', + array( + CURLOPT_TIMEOUT => 1000, + ), + array( + CURLOPT_TIMEOUT => 1000, + ), + ), + array( + 'Required Options can not be injected', + array( + CURLOPT_HTTPGET => false, + ), + array( + CURLOPT_HTTPGET => true, + ), + ), + array( + 'Injected URL decorated with Query String', + array( + CURLOPT_URL => 'user-provided-url', + ), + array( + CURLOPT_URL => 'user-provided-url?param-key=param-value', + ), + ), + array( + 'Injected Headers are additive', + array( + CURLOPT_HTTPHEADER => array( + 'injected-key: injected-value', + ), + ), + array( + CURLOPT_HTTPHEADER => array( + 'injected-key: injected-value', + 'header-key: header-value', + 'Authorization: Basic ' . base64_encode('user:password'), + ), + ), + ), + ); + } + } diff --git a/Twilio/VersionInfo.php b/Twilio/VersionInfo.php index 6bb689e..a0d51df 100644 --- a/Twilio/VersionInfo.php +++ b/Twilio/VersionInfo.php @@ -7,7 +7,7 @@ namespace Twilio; class VersionInfo { const MAJOR = 5; const MINOR = 0; - const PATCH = '2-alpha1'; + const PATCH = '3-alpha1'; public static function string() { return implode('.', array(self::MAJOR, self::MINOR, self::PATCH)); |