diff options
author | Jingming Niu <niu@jingming.ca> | 2016-08-11 14:31:15 -0700 |
---|---|---|
committer | Jingming Niu <niu@jingming.ca> | 2016-08-11 14:31:15 -0700 |
commit | 784f0ab7df4e99bb5fa6e55f24cdc7d1f0b91d54 (patch) | |
tree | 5b4dd1add1a40ebe7f9355adefbfb2d710cd6a53 | |
parent | 15bf7cca6f5f3b25a6a265385d16dd51af53e019 (diff) | |
download | twilio-php-origin/next-gen-region.zip twilio-php-origin/next-gen-region.tar.gz twilio-php-origin/next-gen-region.tar.bz2 |
Add region supportorigin/next-gen-region
-rw-r--r-- | Twilio/Rest/Client.php | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/Twilio/Rest/Client.php b/Twilio/Rest/Client.php index ec2ff8d..dbf562d 100644 --- a/Twilio/Rest/Client.php +++ b/Twilio/Rest/Client.php @@ -78,6 +78,7 @@ class Client { protected $username; protected $password; protected $accountSid; + protected $region; protected $httpClient; protected $_account; protected $_api = null; @@ -101,10 +102,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 string $region Twilio region to make requests * @return \Twilio\Rest\Client Twilio Client * @throws ConfigurationException If valid authentication is not present */ - public function __construct($username = null, $password = null, $accountSid = null, HttpClient $httpClient = null, $environment = null) { + public function __construct($username = null, $password = null, $accountSid = null, HttpClient $httpClient = null, $environment = null, $region = null) { if (!$environment) { $environment = $_ENV; } @@ -136,6 +138,8 @@ class Client { } else { $this->httpClient = new CurlClient(); } + + $this->region = $region; } /** @@ -167,7 +171,15 @@ class Client { if (!array_key_exists('Accept', $headers)) { $headers['Accept'] = 'application/json'; } - + + if ($this->region) { + $parts = explode('.', $uri); + $uri = join('.', array_merge( + array($parts[0], $this->region), + array_slice($parts, 1) + )); + } + return $this->getHttpClient()->request( $method, $uri, @@ -208,6 +220,26 @@ class Client { } /** + * Retrieve the Region + * + * @return null|string Current region + */ + public function getRegion() + { + return $this->region; + } + + /** + * Set the Region + * + * @param null|string $region Region to use + */ + public function setRegion($region) + { + $this->region = $region; + } + + /** * Access the Api Twilio Domain * * @return \Twilio\Rest\Api Api Twilio Domain |