diff options
author | Jingming Niu <niu@jingming.ca> | 2016-09-13 17:24:55 +0300 |
---|---|---|
committer | Jingming Niu <niu@jingming.ca> | 2016-09-13 17:24:55 +0300 |
commit | 2bcfe1695a053f58fea89429c510dbb44c1c0e3b (patch) | |
tree | 5778b40678937dce81d126b77654d35b9f3e0e3b | |
parent | bd0ce5e1d81d0b872a39e96d637b9ed4c63e36e5 (diff) | |
download | twilio-php-origin/port-support.zip twilio-php-origin/port-support.tar.gz twilio-php-origin/port-support.tar.bz2 |
Add port support on rest clientorigin/port-support
-rw-r--r-- | Twilio/Rest/Client.php | 12 | ||||
-rw-r--r-- | Twilio/Tests/Unit/Rest/ClientTest.php | 24 |
2 files changed, 35 insertions, 1 deletions
diff --git a/Twilio/Rest/Client.php b/Twilio/Rest/Client.php index 4860e1d..59f34e5 100644 --- a/Twilio/Rest/Client.php +++ b/Twilio/Rest/Client.php @@ -81,6 +81,7 @@ class Client { protected $accountSid; protected $region; protected $httpClient; + protected $port; protected $_account; protected $_api = null; protected $_ipMessaging = null; @@ -104,10 +105,11 @@ class Client { * @param \Twilio\Http\Client $httpClient HttpClient, defaults to CurlClient * @param mixed[] $environment Environment to look for auth details, defaults * to $_ENV + * @param int $port Port to make requests too * @return \Twilio\Rest\Client Twilio Client * @throws ConfigurationException If valid authentication is not present */ - public function __construct($username = null, $password = null, $accountSid = null, $region = null, HttpClient $httpClient = null, $environment = null) { + public function __construct($username = null, $password = null, $accountSid = null, $region = null, HttpClient $httpClient = null, $environment = null, $port = null) { if (is_null($environment)) { $environment = $_ENV; } @@ -134,6 +136,7 @@ class Client { $this->accountSid = $accountSid ?: $this->username; $this->region = $region; + $this->port = $port; if ($httpClient) { $this->httpClient = $httpClient; @@ -172,6 +175,13 @@ class Client { $headers['Accept'] = 'application/json'; } + if ($this->port) { + list($subdomain, $twilio, $tail) = explode('.', $uri, 3); + list($domain, $path) = explode('/', $tail, 2); + + $uri = implode('.', array($subdomain, $twilio, implode('/', array($domain.':'.$this->port, $path)))); + } + if ($this->region) { list($head, $tail) = explode('.', $uri, 2); $uri = implode('.', array($head, $this->region, $tail)); diff --git a/Twilio/Tests/Unit/Rest/ClientTest.php b/Twilio/Tests/Unit/Rest/ClientTest.php index b31f1cb..c80748a 100644 --- a/Twilio/Tests/Unit/Rest/ClientTest.php +++ b/Twilio/Tests/Unit/Rest/ClientTest.php @@ -110,4 +110,28 @@ class ClientTest extends UnitTest { $this->assertTrue($network->hasRequest($expected)); } + public function testPortDefaultsToEmpty() { + $network = new Holodeck(); + $client = new Client('username', 'password', null, null, $network); + $client->request('POST', 'https://test.twilio.com/v1/Resources'); + $expected = new Request('POST', 'https://test.twilio.com/v1/Resources'); + $this->assertTrue($network->hasRequest($expected)); + } + + public function testPortInjectedWhenSet() { + $network = new Holodeck(); + $client = new Client('username', 'password', null, null, $network, null, 8443); + $client->request('POST', 'https://test.twilio.com/v1/Resources'); + $expected = new Request('POST', 'https://test.twilio.com:8443/v1/Resources'); + $this->assertTrue($network->hasRequest($expected)); + } + + public function testPortAndRegionInjectedWhenSet() { + $network = new Holodeck(); + $client = new Client('username', 'password', null, 'ie1', $network, null, 8443); + $client->request('POST', 'https://test.twilio.com/v1/Resources'); + $expected = new Request('POST', 'https://test.ie1.twilio.com:8443/v1/Resources'); + $this->assertTrue($network->hasRequest($expected)); + } + }
\ No newline at end of file |