summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Witz <jwitz@twilio.com>2015-05-13 15:14:45 -0700
committerJustin Witz <jwitz@twilio.com>2015-05-13 15:14:45 -0700
commitddf3d95f697c04d7636d53893df686a98d70aeec (patch)
treed26a70d2191aed02e681226d1eaa59f01c05478b
parent67803245509f14ed9653210f2a6fd4de1887f4fe (diff)
parent1da5194eaffaf9f22c4d5bb6c4b2df713b8e51fe (diff)
downloadtwilio-php-ddf3d95f697c04d7636d53893df686a98d70aeec.zip
twilio-php-ddf3d95f697c04d7636d53893df686a98d70aeec.tar.gz
twilio-php-ddf3d95f697c04d7636d53893df686a98d70aeec.tar.bz2
Merge branch 'master' of https://code.hq.twilio.com/jwitz/twilio-php into taskrouter-workspace-client
-rw-r--r--CHANGES.md16
-rw-r--r--Makefile2
-rw-r--r--Services/Twilio.php186
-rw-r--r--Services/Twilio/MonitorInstanceResource.php15
-rw-r--r--Services/Twilio/MonitorListResource.php18
-rw-r--r--Services/Twilio/PricingInstanceResource.php14
-rw-r--r--Services/Twilio/PricingListResource.php14
-rw-r--r--Services/Twilio/Rest/Monitor/Alert.php5
-rw-r--r--Services/Twilio/Rest/Monitor/Alerts.php5
-rw-r--r--Services/Twilio/Rest/Monitor/Event.php5
-rw-r--r--Services/Twilio/Rest/Monitor/Events.php5
-rw-r--r--Services/Twilio/Rest/Pricing/PhoneNumberCountries.php23
-rw-r--r--Services/Twilio/Rest/Pricing/PhoneNumberCountry.php4
-rw-r--r--Services/Twilio/Rest/Pricing/VoiceCountries.php24
-rw-r--r--Services/Twilio/Rest/Pricing/VoiceCountry.php5
-rw-r--r--Services/Twilio/Rest/Pricing/VoiceNumber.php5
-rw-r--r--Services/Twilio/Rest/Pricing/VoiceNumbers.php11
-rw-r--r--docs/conf.py4
-rw-r--r--docs/faq.rst17
-rw-r--r--docs/index.rst2
-rw-r--r--docs/usage/rest/pricing.rst137
-rw-r--r--tests/TwilioTest.php6
-rw-r--r--tests/resources/monitor/AlertsTest.php42
-rw-r--r--tests/resources/monitor/EventsTest.php42
-rw-r--r--tests/resources/pricing/PhoneNumbersTest.php47
-rw-r--r--tests/resources/pricing/VoiceTest.php63
26 files changed, 671 insertions, 46 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 0ce2f5b..f924411 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,6 +1,20 @@
twilio-php Changelog
====================
+Version 4.1.0
+-------------
+
+Released May 7, 2015
+
+- Add support for Twilio Monitor Events and Alerts
+
+Version 4.0.4
+-------------
+
+Released May 6, 2015
+
+- Add support for the new Pricing API.
+
Version 4.0.3
-------------
@@ -13,7 +27,7 @@ Version 4.0.2
Released on April 27, 2015
-- Fix the autoloading so that Lookups_Services_Twilio and
+- Fix the autoloading so that Lookups_Services_Twilio and
TaskRouter_Services_Twilio are available independently of Services_Twilio
Version 4.0.1
diff --git a/Makefile b/Makefile
index fad48f6..9fa1b2a 100644
--- a/Makefile
+++ b/Makefile
@@ -47,7 +47,7 @@ install:
# if these fail, you may need to install the helper library - run "make
# test-install"
test:
- @PATH=vendor/bin:$(PATH) phpunit --strict --colors --configuration tests/phpunit.xml;
+ @PATH=vendor/bin:$(PATH) phpunit --report-useless-tests --strict-coverage --disallow-test-output --colors --configuration tests/phpunit.xml;
venv:
virtualenv venv
diff --git a/Services/Twilio.php b/Services/Twilio.php
index 15c8e62..7a86cb4 100644
--- a/Services/Twilio.php
+++ b/Services/Twilio.php
@@ -8,9 +8,11 @@
function Services_Twilio_autoload($className)
{
- if (substr($className, 0, 15) != 'Services_Twilio'
+ if (substr($className, 0, 15) != 'Services_Twilio'
&& substr($className, 0, 26) != 'TaskRouter_Services_Twilio'
- && substr($className, 0, 23) != 'Lookups_Services_Twilio') {
+ && substr($className, 0, 23) != 'Lookups_Services_Twilio'
+ && substr($className, 0, 23) != 'Monitor_Services_Twilio'
+ && substr($className, 0, 23) != 'Pricing_Services_Twilio') {
return false;
}
$file = str_replace('_', '/', $className);
@@ -25,7 +27,7 @@ spl_autoload_register('Services_Twilio_autoload');
*/
abstract class Base_Services_Twilio extends Services_Twilio_Resource
{
- const USER_AGENT = 'twilio-php/4.0.3';
+ const USER_AGENT = 'twilio-php/4.1.0';
protected $http;
protected $last_response;
@@ -39,8 +41,7 @@ abstract class Base_Services_Twilio extends Services_Twilio_Resource
$version = null,
Services_Twilio_TinyHttp $_http = null,
$retryAttempts = 1
- )
- {
+ ) {
$this->version = in_array($version, $this->versions) ? $version : end($this->versions);
if (null === $_http) {
@@ -86,15 +87,11 @@ abstract class Base_Services_Twilio extends Services_Twilio_Resource
* :param array $queryData: An associative array of keys and values. The
* values can be a simple type or a list, in which case the list is
* converted to multiple query parameters with the same key.
- * :param string $numericPrefix:
- * :param string $queryStringStyle: Determine how to build the url
- * - strict: Build a standards compliant query string without braces (can be hacked by using braces in key)
- * - php: Build a PHP compatible query string with nested array syntax
+ * :param string $numericPrefix: optional prefix to prepend to numeric keys
* :return: The encoded query string
* :rtype: string
*/
- public static function buildQuery($queryData, $numericPrefix = '')
- {
+ public static function buildQuery($queryData, $numericPrefix = '') {
$query = '';
// Loop through all of the $query_data
foreach ($queryData as $key => $value) {
@@ -158,8 +155,7 @@ abstract class Base_Services_Twilio extends Services_Twilio_Resource
* :return: the user agent
* :rtype: string
*/
- public static function qualifiedUserAgent($php_version)
- {
+ public static function qualifiedUserAgent($php_version) {
return self::USER_AGENT . " (php $php_version)";
}
@@ -206,8 +202,7 @@ abstract class Base_Services_Twilio extends Services_Twilio_Resource
* :return: the number of retry attempts
* :rtype: int
*/
- public function getRetryAttempts()
- {
+ public function getRetryAttempts() {
return $this->retryAttempts;
}
@@ -217,8 +212,7 @@ abstract class Base_Services_Twilio extends Services_Twilio_Resource
* :return: the API version in use
* :returntype: string
*/
- public function getVersion()
- {
+ public function getVersion() {
return $this->version;
}
@@ -248,8 +242,7 @@ abstract class Base_Services_Twilio extends Services_Twilio_Resource
* :return: base URI
* :rtype: string
*/
- protected function _getBaseUri()
- {
+ protected function _getBaseUri() {
return 'https://api.twilio.com';
}
@@ -263,8 +256,7 @@ abstract class Base_Services_Twilio extends Services_Twilio_Resource
* :return: The object representation of the resource
* :rtype: object
*/
- protected function _makeIdempotentRequest($callable, $uri, $retriesLeft)
- {
+ protected function _makeIdempotentRequest($callable, $uri, $retriesLeft) {
$response = call_user_func_array($callable, array($uri));
list($status, $headers, $body) = $response;
if ($status >= 500 && $retriesLeft > 0) {
@@ -335,8 +327,6 @@ abstract class Base_Services_Twilio extends Services_Twilio_Resource
*/
class Services_Twilio extends Base_Services_Twilio
{
-
- CONST URI = 'https://api.twilio.com';
protected $versions = array('2008-08-01', '2010-04-01');
public function __construct(
@@ -466,7 +456,6 @@ class TaskRouter_Services_Twilio extends Base_Services_Twilio
}
}
-
/**
* Create a client to talk to the Twilio Lookups API.
*
@@ -545,3 +534,152 @@ class Lookups_Services_Twilio extends Base_Services_Twilio
}
}
+
+/**
+ * Create a client to talk to the Twilio Pricing API.
+ *
+ *
+ * :param string $sid: Your Account SID
+ * :param string $token: Your Auth Token from `your dashboard
+ * <https://www.twilio.com/user/account>`_
+ * :param string $version: API version to use
+ * :param $_http: A HTTP client for making requests.
+ * :type $_http: :php:class:`Services_Twilio_TinyHttp`
+ * :param int $retryAttempts:
+ * Number of times to retry failed requests. Currently only idempotent
+ * requests (GET's and DELETE's) are retried.
+ *
+ * Here's an example:
+ *
+ * .. code-block:: php
+ *
+ * require('Services/Twilio.php');
+ * $client = new Pricing_Services_Twilio('AC123', '456bef', null, null, 3);
+ * // Take some action with the client, etc.
+ */
+class Pricing_Services_Twilio extends Base_Services_Twilio
+{
+ protected $versions = array('v1');
+
+ public function __construct(
+ $sid,
+ $token,
+ $version = null,
+ Services_Twilio_TinyHttp $_http = null,
+ $retryAttempts = 1
+ ) {
+ parent::__construct($sid, $token, $version, $_http, $retryAttempts);
+
+ $this->voiceCountries = new Services_Twilio_Rest_Pricing_VoiceCountries(
+ $this, "/{$this->version}/Voice/Countries"
+ );
+ $this->voiceNumbers = new Services_Twilio_Rest_Pricing_VoiceNumbers(
+ $this, "/{$this->version}/Voice/Numbers"
+ );
+ $this->phoneNumberCountries = new Services_Twilio_Rest_Pricing_PhoneNumberCountries(
+ $this, "/{$this->version}/PhoneNumbers/Countries"
+ );
+ }
+
+ /**
+ * Construct a URI based on initial path, query params, and paging
+ * information
+ *
+ * We want to use the query params, unless we have a next_page_uri from the
+ * API.
+ *
+ * :param string $path: The request path (may contain query params if it's
+ * a next_page_uri)
+ * :param array $params: Query parameters to use with the request
+ * :param boolean $full_uri: Whether the $path contains the full uri
+ *
+ * :return: the URI that should be requested by the library
+ * :returntype: string
+ */
+ public function getRequestUri($path, $params, $full_uri = false)
+ {
+ if (!$full_uri && !empty($params)) {
+ $query_path = $path . '?' . http_build_query($params, '', '&');
+ } else {
+ $query_path = $path;
+ }
+ return $query_path;
+ }
+
+ protected function _getBaseUri() {
+ return 'https://pricing.twilio.com';
+ }
+
+}
+
+/**
+ * Create a client to talk to the Twilio Monitor API.
+ *
+ *
+ * :param string $sid: Your Account SID
+ * :param string $token: Your Auth Token from `your dashboard
+ * <https://www.twilio.com/user/account>`_
+ * :param string $version: API version to use
+ * :param $_http: A HTTP client for making requests.
+ * :type $_http: :php:class:`Services_Twilio_TinyHttp`
+ * :param int $retryAttempts:
+ * Number of times to retry failed requests. Currently only idempotent
+ * requests (GET's and DELETE's) are retried.
+ *
+ * Here's an example:
+ *
+ * .. code-block:: php
+ *
+ * require('Services/Twilio.php');
+ * $client = new Monitor_Services_Twilio('AC123', '456bef', null, null, 3);
+ * // Take some action with the client, etc.
+ */
+class Monitor_Services_Twilio extends Base_Services_Twilio
+{
+ protected $versions = array('v1');
+
+ public function __construct(
+ $sid,
+ $token,
+ $version = null,
+ Services_Twilio_TinyHttp $_http = null,
+ $retryAttempts = 1
+ )
+ {
+ parent::__construct($sid, $token, $version, $_http, $retryAttempts);
+
+ $this->events = new Services_Twilio_Rest_Monitor_Events($this, "/{$this->version}/Events");
+ $this->alerts = new Services_Twilio_Rest_Monitor_Alerts($this, "/{$this->version}/Alerts");
+ }
+
+ /**
+ * Construct a URI based on initial path, query params, and paging
+ * information
+ *
+ * We want to use the query params, unless we have a next_page_uri from the
+ * API.
+ *
+ * :param string $path: The request path (may contain query params if it's
+ * a next_page_uri)
+ * :param array $params: Query parameters to use with the request
+ * :param boolean $full_uri: Whether the $path contains the full uri
+ *
+ * :return: the URI that should be requested by the library
+ * :returntype: string
+ */
+ public function getRequestUri($path, $params, $full_uri = false)
+ {
+ if (!$full_uri && !empty($params)) {
+ $query_path = $path . '?' . http_build_query($params, '', '&');
+ } else {
+ $query_path = $path;
+ }
+ return $query_path;
+ }
+
+ protected function _getBaseUri()
+ {
+ return 'https://monitor.twilio.com';
+ }
+
+}
diff --git a/Services/Twilio/MonitorInstanceResource.php b/Services/Twilio/MonitorInstanceResource.php
new file mode 100644
index 0000000..bf4c300
--- /dev/null
+++ b/Services/Twilio/MonitorInstanceResource.php
@@ -0,0 +1,15 @@
+<?php
+
+abstract class Services_Twilio_MonitorInstanceResource extends Services_Twilio_NextGenInstanceResource {
+
+ protected function setupSubresources() {
+ foreach (func_get_args() as $name) {
+ $constantized = ucfirst(self::camelize($name));
+ $type = "Services_Twilio_Rest_Monitor_" . $constantized;
+ $this->subresources[$name] = new $type(
+ $this->client, $this->uri . "/$constantized"
+ );
+ }
+ }
+
+}
diff --git a/Services/Twilio/MonitorListResource.php b/Services/Twilio/MonitorListResource.php
new file mode 100644
index 0000000..70604e3
--- /dev/null
+++ b/Services/Twilio/MonitorListResource.php
@@ -0,0 +1,18 @@
+<?php
+
+abstract class Services_Twilio_MonitorListResource extends Services_Twilio_NextGenListResource {
+
+ public function __construct($client, $uri) {
+ $name = $this->getResourceName(true);
+ /*
+ * By default trim the 's' from the end of the list name to get the
+ * instance name (ex Accounts -> Account). This behavior can be
+ * overridden by child classes if the rule doesn't work.
+ */
+ if (!isset($this->instance_name)) {
+ $this->instance_name = "Services_Twilio_Rest_Monitor_" . rtrim($name, 's');
+ }
+
+ parent::__construct($client, $uri);
+ }
+}
diff --git a/Services/Twilio/PricingInstanceResource.php b/Services/Twilio/PricingInstanceResource.php
new file mode 100644
index 0000000..6ae1e18
--- /dev/null
+++ b/Services/Twilio/PricingInstanceResource.php
@@ -0,0 +1,14 @@
+<?php
+
+abstract class Services_Twilio_PricingInstanceResource extends Services_Twilio_NextGenInstanceResource {
+
+ protected function setupSubresources() {
+ foreach (func_get_args() as $name) {
+ $constantized = ucfirst(self::camelize($name));
+ $type = 'Services_Twilio_Rest_Pricing' . $constantized;
+ $this->subresources[$name] = new $type(
+ $this->client, $this->uri . "/$constantized"
+ );
+ }
+ }
+}
diff --git a/Services/Twilio/PricingListResource.php b/Services/Twilio/PricingListResource.php
new file mode 100644
index 0000000..cc663e4
--- /dev/null
+++ b/Services/Twilio/PricingListResource.php
@@ -0,0 +1,14 @@
+<?php
+
+abstract class Services_Twilio_PricingListResource extends Services_Twilio_NextGenListResource {
+ public function __construct($client, $uri) {
+ $name = $this->getResourceName(true);
+
+ if (!isset($this->instance_name)) {
+ $this->instance_name = 'Services_Twilio_Rest_Pricing_'. rtrim($name, 's');
+ }
+
+ parent::__construct($client, $uri);
+ }
+
+}
diff --git a/Services/Twilio/Rest/Monitor/Alert.php b/Services/Twilio/Rest/Monitor/Alert.php
new file mode 100644
index 0000000..31bc1b4
--- /dev/null
+++ b/Services/Twilio/Rest/Monitor/Alert.php
@@ -0,0 +1,5 @@
+<?php
+
+class Services_Twilio_Rest_Monitor_Alert extends Services_Twilio_MonitorInstanceResource {
+
+}
diff --git a/Services/Twilio/Rest/Monitor/Alerts.php b/Services/Twilio/Rest/Monitor/Alerts.php
new file mode 100644
index 0000000..6d4811a
--- /dev/null
+++ b/Services/Twilio/Rest/Monitor/Alerts.php
@@ -0,0 +1,5 @@
+<?php
+
+class Services_Twilio_Rest_Monitor_Alerts extends Services_Twilio_MonitorListResource {
+
+}
diff --git a/Services/Twilio/Rest/Monitor/Event.php b/Services/Twilio/Rest/Monitor/Event.php
new file mode 100644
index 0000000..cf8311b
--- /dev/null
+++ b/Services/Twilio/Rest/Monitor/Event.php
@@ -0,0 +1,5 @@
+<?php
+
+class Services_Twilio_Rest_Monitor_Event extends Services_Twilio_MonitorInstanceResource {
+
+}
diff --git a/Services/Twilio/Rest/Monitor/Events.php b/Services/Twilio/Rest/Monitor/Events.php
new file mode 100644
index 0000000..7b4601e
--- /dev/null
+++ b/Services/Twilio/Rest/Monitor/Events.php
@@ -0,0 +1,5 @@
+<?php
+
+class Services_Twilio_Rest_Monitor_Events extends Services_Twilio_MonitorListResource {
+
+}
diff --git a/Services/Twilio/Rest/Pricing/PhoneNumberCountries.php b/Services/Twilio/Rest/Pricing/PhoneNumberCountries.php
new file mode 100644
index 0000000..9d493f7
--- /dev/null
+++ b/Services/Twilio/Rest/Pricing/PhoneNumberCountries.php
@@ -0,0 +1,23 @@
+<?php
+
+class Services_Twilio_Rest_Pricing_PhoneNumberCountries
+ extends Services_Twilio_PricingListResource {
+
+ public function __construct($client, $uri) {
+ $this->instance_name = 'Services_Twilio_Rest_Pricing_PhoneNumberCountry';
+ parent::__construct($client, $uri);
+ }
+
+ public function getResourceName($camelized = false) {
+ if ($camelized) {
+ return 'Countries';
+ }
+ return 'countries';
+ }
+
+ public function get($isoCountry) {
+ $instance = new $this->instance_name($this->client, $this->uri . "/$isoCountry");
+ $instance->iso_country = $isoCountry;
+ return $instance;
+ }
+} \ No newline at end of file
diff --git a/Services/Twilio/Rest/Pricing/PhoneNumberCountry.php b/Services/Twilio/Rest/Pricing/PhoneNumberCountry.php
new file mode 100644
index 0000000..ac840b8
--- /dev/null
+++ b/Services/Twilio/Rest/Pricing/PhoneNumberCountry.php
@@ -0,0 +1,4 @@
+<?php
+class Services_Twilio_Rest_Pricing_PhoneNumberCountry
+ extends Services_Twilio_PricingInstanceResource {
+} \ No newline at end of file
diff --git a/Services/Twilio/Rest/Pricing/VoiceCountries.php b/Services/Twilio/Rest/Pricing/VoiceCountries.php
new file mode 100644
index 0000000..869ac61
--- /dev/null
+++ b/Services/Twilio/Rest/Pricing/VoiceCountries.php
@@ -0,0 +1,24 @@
+<?php
+
+class Services_Twilio_Rest_Pricing_VoiceCountries
+ extends Services_Twilio_PricingListResource {
+
+ public function getResourceName($camelized = false) {
+ if ($camelized) {
+ return 'Countries';
+ }
+ return 'countries';
+
+ }
+
+ public function __construct($client, $uri) {
+ $this->instance_name = "Services_Twilio_Rest_Pricing_VoiceCountry";
+ parent::__construct($client, $uri);
+ }
+
+ public function get($isoCountry) {
+ $instance = new $this->instance_name($this->client, $this->uri . "/$isoCountry");
+ $instance->iso_country = $isoCountry;
+ return $instance;
+ }
+} \ No newline at end of file
diff --git a/Services/Twilio/Rest/Pricing/VoiceCountry.php b/Services/Twilio/Rest/Pricing/VoiceCountry.php
new file mode 100644
index 0000000..5252694
--- /dev/null
+++ b/Services/Twilio/Rest/Pricing/VoiceCountry.php
@@ -0,0 +1,5 @@
+<?php
+
+class Services_Twilio_Rest_Pricing_VoiceCountry
+ extends Services_Twilio_PricingInstanceResource {
+} \ No newline at end of file
diff --git a/Services/Twilio/Rest/Pricing/VoiceNumber.php b/Services/Twilio/Rest/Pricing/VoiceNumber.php
new file mode 100644
index 0000000..80ee3e9
--- /dev/null
+++ b/Services/Twilio/Rest/Pricing/VoiceNumber.php
@@ -0,0 +1,5 @@
+<?php
+
+class Services_Twilio_Rest_Pricing_VoiceNumber
+ extends Services_Twilio_PricingInstanceResource {
+} \ No newline at end of file
diff --git a/Services/Twilio/Rest/Pricing/VoiceNumbers.php b/Services/Twilio/Rest/Pricing/VoiceNumbers.php
new file mode 100644
index 0000000..5a449a0
--- /dev/null
+++ b/Services/Twilio/Rest/Pricing/VoiceNumbers.php
@@ -0,0 +1,11 @@
+<?php
+
+class Services_Twilio_Rest_Pricing_VoiceNumbers
+ extends Services_Twilio_PricingListResource {
+
+ public function get($number) {
+ $instance = new $this->instance_name($this->client, $this->uri . "/$number");
+ $instance->number = $number;
+ return $instance;
+ }
+} \ No newline at end of file
diff --git a/docs/conf.py b/docs/conf.py
index 81bbc43..a15cff6 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -51,9 +51,9 @@ copyright = unicode(datetime.utcnow().year) + u', Twilio Inc'
# built documents.
#
# The short X.Y version.
-version = '4.0'
+version = '4.1'
# The full version, including alpha/beta/rc tags.
-release = '4.0.3'
+release = '4.1.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/docs/faq.rst b/docs/faq.rst
index 8e56fad..1fb2f8d 100644
--- a/docs/faq.rst
+++ b/docs/faq.rst
@@ -63,23 +63,6 @@ You can also try changing the ``require`` line like this:
require('/path/to/twilio-php/Services/Twilio.php');
-You could also try downloading the library via PEAR, a package manager for PHP,
-which will add the library to your PHP path, so you can load the Twilio library
-from anywhere. Run this at the command line:
-
-.. code-block:: bash
-
- $ pear channel-discover twilio-pear.herokuapp.com/pear
- $ pear install twilio/Services_Twilio
-
-If you get the following message:
-
-.. code-block:: bash
-
- $ -bash: pear: command not found
-
-you can install PEAR from their website.
-
SSL Validation Exceptions
-------------------------
diff --git a/docs/index.rst b/docs/index.rst
index 6c65053..1f05a27 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -10,7 +10,7 @@
Status
=======
-This documentation is for version 4.0.3 of `twilio-php
+This documentation is for version 4.1.0 of `twilio-php
<https://www.github.com/twilio/twilio-php>`_.
Quickstart
diff --git a/docs/usage/rest/pricing.rst b/docs/usage/rest/pricing.rst
new file mode 100644
index 0000000..2263282
--- /dev/null
+++ b/docs/usage/rest/pricing.rst
@@ -0,0 +1,137 @@
+.. _ref-rest:
+
+============================
+Using the Twilio Pricing API
+============================
+
+The Twilio Pricing API works similarly to the main Twilio REST API,
+but is located on a new domain: `pricing.twilio.com`.
+
+The Pricing API is accessible through a new :php:class:`Pricing_Services_Twilio`
+class that works much like the :php:class:`Services_Twilio` object you already
+use for the main Twilio REST API.
+
+Creating a Pricing Client
+=========================
+
+.. code-block:: php
+
+ $ACCOUNT_SID = "AC123";
+ $AUTH_TOKEN = "secret";
+ $client = new Pricing_Services_Twilio($ACCOUNT_SID, $AUTH_TOKEN);
+
+Accessing Resources
+===================
+
+The Pricing API resources function similarly to those available in the main
+Twilio API. For basic examples, see :doc:`/usage/rest`.
+
+Voice Pricing
+=============
+
+Twilio Voice pricing is available by country and by phone number.
+
+Voice calls are priced per minute and reflect the current Twilio list
+price as well as any discounts available for your account at the time
+you request pricing information.
+
+Voice Countries
+---------------
+
+To retrieve a list of countries where Twilio voice services are available:
+
+.. code-block:: php
+
+ $ACCOUNT_SID = "AC123";
+ $AUTH_TOKEN = "secret";
+ $client = new Pricing_Services_Twilio($ACCOUNT_SID, $AUTH_TOKEN);
+
+ $countryList = $client->voiceCountries->getPage();
+ foreach ($countryList->countries as $c) {
+ echo $c->isoCountry . "\n";
+ }
+
+Note that the country objects in the returned list will not have pricing
+information populated; you will need to retrieve the specific information
+for each country you are interested in individually:
+
+.. code-block:: php
+
+ $ACCOUNT_SID = "AC123";
+ $AUTH_TOKEN = "secret";
+ $client = new Pricing_Services_Twilio($ACCOUNT_SID, $AUTH_TOKEN);
+
+ $country = $client->voiceCountries->get("GB");
+ echo $country->iso_country . "\n";
+ echo $country->price_unit . "\n";
+
+ foreach ($country->outbound_prefix_prices as $price) {
+ // Price per minute before discounts
+ echo $price->base_price . "\n";
+ // Price per minute after applying any discounts available
+ // to your account
+ echo $price->current_price . "\n";
+ // Prefixes of phone numbers to which these rates apply
+ foreach ($price->prefixes as $prefix) {
+ echo $prefix . "\n";
+ }
+ }
+
+Voice Numbers
+-------------
+
+To retrieve pricing information for calls to and from a specific phone number:
+
+.. code-block:: php
+
+ $ACCOUNT_SID = "AC123";
+ $AUTH_TOKEN = "secret";
+ $client = new Pricing_Services_Twilio($ACCOUNT_SID, $AUTH_TOKEN);
+
+ $number = $client->voiceNumbers->get("+15105551234");
+ echo $number->price_unit . "\n";
+ echo $number->outbound_call_price->call_base_price . "\n";
+ // $number->inbound_call_price is only set for Twilio-hosted numbers
+ echo $number->inbound_call_price->call_base_price . "\n";
+
+Phone Number Pricing
+====================
+
+Twilio Phone Numbers are priced per month.
+
+To retrieve a list of countries where Twilio Numbers are available:
+
+.. code-block:: php
+
+ $ACCOUNT_SID = "AC123";
+ $AUTH_TOKEN = "secret";
+ $client = new Pricing_Services_Twilio($ACCOUNT_SID, $AUTH_TOKEN);
+
+ $countryList = $client->phoneNumberCountries->getPage();
+ foreach ($countryList->countries as $c) {
+ echo $c->iso_country . "\n";
+ }
+
+Note that the country objects in the returned list will not have pricing
+information populated; you will need to retrieve the specific information
+for each country you are interested in individually:
+
+.. code-block:: php
+
+ $ACCOUNT_SID = "AC123";
+ $AUTH_TOKEN = "secret";
+ $client = new Pricing_Services_Twilio($ACCOUNT_SID, $AUTH_TOKEN);
+
+ $country = $client->phoneNumberCountries->get("GB");
+ echo $country->price_unit . "\n";
+
+ foreach ($country->phone_number_prices as $p) {
+ // "mobile", "toll_free", "local", or "national"
+ echo $p->number_type . "\n";
+ // Number price per month before discounts
+ echo $p->base_price . "\n";
+ // Number price per month after available discounts for your
+ // account have been applied
+ echo $p->current_price . "\n";
+ }
+
diff --git a/tests/TwilioTest.php b/tests/TwilioTest.php
index 0c632fc..7ef7539 100644
--- a/tests/TwilioTest.php
+++ b/tests/TwilioTest.php
@@ -374,6 +374,12 @@ class TwilioTest extends PHPUnit_Framework_TestCase {
$client->account->calls->create('123', '123', 'http://example.com');
}
+ function testPricingClient() {
+ $pricingClient = new Pricing_Services_Twilio('AC123', '123', 'v1');
+ $this->assertNotNull($pricingClient);
+ $this->assertEquals(1, $pricingClient->getRetryAttempts());
+ }
+
function testTaskRouterClient() {
$taskrouterClient = new TaskRouter_Services_Twilio('AC123', '123', 'WS123', 'v1');
$this->assertNotNull($taskrouterClient);
diff --git a/tests/resources/monitor/AlertsTest.php b/tests/resources/monitor/AlertsTest.php
new file mode 100644
index 0000000..3db7563
--- /dev/null
+++ b/tests/resources/monitor/AlertsTest.php
@@ -0,0 +1,42 @@
+<?php
+
+use \Mockery as m;
+
+class MonitorAlertsTest extends PHPUnit_Framework_TestCase
+{
+
+ function testGet() {
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('get')->once()
+ ->with('/v1/Alerts/NO123')
+ ->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array('sid' => 'NO123', 'alert_text' => 'Test'))
+ ));
+ $monitorClient = new Monitor_Services_Twilio('AC123', '123', 'v1', $http);
+ $alert = $monitorClient->alerts->get('NO123');
+ $this->assertNotNull($alert);
+ $this->assertEquals('Test', $alert->alert_text);
+ }
+
+ function testGetList()
+ {
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('get')->once()
+ ->with('/v1/Alerts?Page=0&PageSize=50')
+ ->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array(
+ 'meta' => array('key' => 'alerts', 'next_page_url' => null),
+ 'alerts' => array(array('sid' => 'NO123'))
+ ))
+ ));
+ $monitorClient = new Monitor_Services_Twilio('AC123', '123', 'v1', $http);
+ foreach ($monitorClient->alerts->getIterator(0, 50) as $alert) {
+ $this->assertEquals('NO123', $alert->sid);
+ }
+ }
+
+ function tearDown()
+ {
+ m::close();
+ }
+}
diff --git a/tests/resources/monitor/EventsTest.php b/tests/resources/monitor/EventsTest.php
new file mode 100644
index 0000000..76b5859
--- /dev/null
+++ b/tests/resources/monitor/EventsTest.php
@@ -0,0 +1,42 @@
+<?php
+
+use \Mockery as m;
+
+class MonitorEventsTest extends PHPUnit_Framework_TestCase
+{
+
+ function testGet() {
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('get')->once()
+ ->with('/v1/Events/AE123')
+ ->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array('sid' => 'AE123', 'description' => 'Test'))
+ ));
+ $monitorClient = new Monitor_Services_Twilio('AC123', '123', 'v1', $http);
+ $event = $monitorClient->events->get('AE123');
+ $this->assertNotNull($event);
+ $this->assertEquals('Test', $event->description);
+ }
+
+ function testGetList()
+ {
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('get')->once()
+ ->with('/v1/Events?Page=0&PageSize=50')
+ ->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array(
+ 'meta' => array('key' => 'events', 'next_page_url' => null),
+ 'events' => array(array('sid' => 'AE123'))
+ ))
+ ));
+ $monitorClient = new Monitor_Services_Twilio('AC123', '123', 'v1', $http);
+ foreach ($monitorClient->events->getIterator(0, 50) as $event) {
+ $this->assertEquals('AE123', $event->sid);
+ }
+ }
+
+ function tearDown()
+ {
+ m::close();
+ }
+}
diff --git a/tests/resources/pricing/PhoneNumbersTest.php b/tests/resources/pricing/PhoneNumbersTest.php
new file mode 100644
index 0000000..ee09414
--- /dev/null
+++ b/tests/resources/pricing/PhoneNumbersTest.php
@@ -0,0 +1,47 @@
+<?php
+
+use \Mockery as m;
+require_once 'Twilio.php';
+
+class PhoneNumberTest extends PHPUnit_Framework_TestCase {
+
+ function testGetCountries() {
+ $data = array(
+ 'meta' => array(
+ 'key' => 'countries',
+ 'next_page_url' => null
+ ),
+ 'countries' => array(
+ array('iso_country' => 'US')
+ )
+ );
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('get')->once()->with(
+ '/v1/PhoneNumbers/Countries?Page=0&PageSize=50'
+ )->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode($data)));
+
+ $pricingClient = new Pricing_Services_Twilio('AC123', '123', 'v1',
+ $http, 1);
+ $countries = $pricingClient->phoneNumberCountries->getPage();
+ $this->assertNotNull($countries);
+
+ $countryList = $countries->getItems();
+ $country = $countryList[0];
+ $this->assertNotNull($country);
+ $this->assertEquals($country->iso_country, 'US');
+ }
+
+ function testGetCountry() {
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('get')->once()->with('/v1/PhoneNumbers/Countries/EE')
+ ->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array('country' => 'Estonia'))));
+ $pricingClient = new Pricing_Services_Twilio('AC123', '123', 'v1', $http, 1);
+
+ $country = $pricingClient->phoneNumberCountries->get('EE');
+ $this->assertNotNull($country);
+ $this->assertEquals($country->iso_country, 'EE');
+ $this->assertEquals($country->country, 'Estonia');
+ }
+}
diff --git a/tests/resources/pricing/VoiceTest.php b/tests/resources/pricing/VoiceTest.php
new file mode 100644
index 0000000..eb283aa
--- /dev/null
+++ b/tests/resources/pricing/VoiceTest.php
@@ -0,0 +1,63 @@
+<?php
+
+use \Mockery as m;
+require_once 'Twilio.php';
+
+class VoiceTest extends PHPUnit_Framework_TestCase {
+
+ function testGetCountries() {
+ $data = array(
+ 'meta' => array(
+ 'key' => 'countries',
+ 'next_page_url' => null
+ ),
+ 'countries' => array(
+ array('iso_country' => 'US')
+ )
+ );
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('get')->once()->with(
+ '/v1/Voice/Countries?Page=0&PageSize=50'
+ )->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode($data)));
+
+ $pricingClient = new Pricing_Services_Twilio('AC123', '123', 'v1',
+ $http, 1);
+ $countries = $pricingClient->voiceCountries->getPage();
+ $this->assertNotNull($countries);
+
+ $countryList = $countries->getItems();
+ $country = $countryList[0];
+ $this->assertNotNull($country);
+ $this->assertEquals($country->iso_country, 'US');
+ }
+
+ function testGetCountry() {
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('get')->once()->with('/v1/Voice/Countries/EE')
+ ->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array('country' => 'Estonia'))));
+ $pricingClient = new Pricing_Services_Twilio('AC123', '123', 'v1', $http, 1);
+
+ $country = $pricingClient->voiceCountries->get('EE');
+ $this->assertNotNull($country);
+ $this->assertEquals($country->iso_country, 'EE');
+ $this->assertEquals($country->country, 'Estonia');
+ }
+
+ function testGetNumber() {
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('get')->once()->with(
+ '/v1/Voice/Numbers/+14155551234'
+ )->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array('iso_country' => 'US'))));
+
+ $pricingClient = new Pricing_Services_Twilio('AC123', '123', 'v1', $http, 1);
+
+ $number = $pricingClient->voiceNumbers->get('+14155551234');
+ $this->assertNotNull($number);
+ $this->assertEquals($number->number, '+14155551234');
+ $this->assertEquals($number->iso_country, 'US');
+ }
+
+}