From 75ca4c00d8d0ed011bbade26887c96eb69e2a623 Mon Sep 17 00:00:00 2001 From: jmulford-bandwidth Date: Thu, 30 Jan 2020 10:24:47 -0500 Subject: [PATCH 1/4] First stab at importTnOrders endpoints --- README.md | 1 + composer.json | 2 +- src/Account.php | 25 +++++++++++++++++++ src/simpleModels/ImportTnOrder.php | 39 ++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/simpleModels/ImportTnOrder.php diff --git a/README.md b/README.md index 45af7be..37ea56e 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ PHP Client library for Bandwidth's Phone Number Dashboard (AKA: Dashboard, Iris) | 2.0.6 | Build `ReportsModel` functionality | | 2.0.7 | Fixed error handling for Errors fields | | 2.0.8 | Fixed rate center check | +| 2.1.0 | Added `importTnOrders` endpoints | ## Supported PHP Versions diff --git a/composer.json b/composer.json index 0b0842f..2633d92 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description": "Bandwidth's Iris SDK for PHP", "keywords": ["iris","sdk","php"], "homepage": "http://dev.bandwidth.com", - "reference": "v2.0.6", + "reference": "v2.1.0", "license": "MIT", "authors": [ ], diff --git a/src/Account.php b/src/Account.php index 04a93f9..3cd8ab1 100644 --- a/src/Account.php +++ b/src/Account.php @@ -250,4 +250,29 @@ public function get_relative_namespace() { public function get_rest_client() { return $this->client; } + + public function getImportTnOrders($filters = array()) { + $url = sprintf('%s/%s', $this->account_id, 'importTnOrders'); + $response = parent::_get($url, $filters); + return new ImportTnOrderResponse($response); + } + + public function createImportTnOrder(ImportTnOrder $order) { + $url = sprintf('%s/%s', $this->account_id, 'importTnOrders'); + $data = parent::post($url, 'ImportTnOrder', $order->to_array()); + return new ImportTnOrderResponse($data); + } + + public function getImportTnOrder($id) { + $url = sprintf('%s/%s/%s', $this->account_id, 'importTnOrders', $id); + $response = parent::_get($url); + return new ImportTnOrder($response); + } + + public function getImportTnOrderHistory($id) { + $url = sprintf('%s/%s/%s/%s', $this->account_id, 'importTnOrders', $id, 'history'); + $response = parent::_get($url); + //TODO: Figure out the actual response object + return $response; + } } diff --git a/src/simpleModels/ImportTnOrder.php b/src/simpleModels/ImportTnOrder.php new file mode 100644 index 0000000..d29a5b0 --- /dev/null +++ b/src/simpleModels/ImportTnOrder.php @@ -0,0 +1,39 @@ + array("type" => "\Iris\ImportTnOrder") + ); + + public function __construct($data) { + $this->set_data($data); + } +) + +class ImportTnOrder { + use BaseModel; + + protected $fields = array( + "CustomerOrderId" => array("type" => "string"), + "OrderCreateDate" => array("type" => "string"), + "AccountId" => array("type" => "string"), + "CreatedByUser" => array("type" => "string"), + "OrderId" => array("type" => "string"), + "LastModifiedDate" => array("type" => "string"), + "SiteId" => array("type" => "string"), + "SipPeerId" => array("type" => "string"), + "Subscriber" => array("type" => "\Iris\Subscriber"), + "LoaAuthorizingPerson" => array("type" => "string"), + "ProcessingStatus" => array("type" => "string"), + "Errors" => array("type" => "\Iris\Error"), + "TelephoneNumbers" => array("type" => "\Iris\Phones") + ); + + public function __construct($data) { + $this->set_data($data); + } +} From 36e21a7bb01804406c72c15b4993451d04e42442 Mon Sep 17 00:00:00 2001 From: jmulford-bandwidth Date: Thu, 30 Jan 2020 10:58:17 -0500 Subject: [PATCH 2/4] Broke up models into 2 classes --- src/simpleModels/ImportTnOrder.php | 12 ------------ src/simpleModels/ImportTnOrderResponse.php | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 src/simpleModels/ImportTnOrderResponse.php diff --git a/src/simpleModels/ImportTnOrder.php b/src/simpleModels/ImportTnOrder.php index d29a5b0..14eb756 100644 --- a/src/simpleModels/ImportTnOrder.php +++ b/src/simpleModels/ImportTnOrder.php @@ -2,18 +2,6 @@ namespace Iris; -class ImportTnOrderResponse { - use BaseModel; - - protected $fields = array( - "ImportTnOrder" => array("type" => "\Iris\ImportTnOrder") - ); - - public function __construct($data) { - $this->set_data($data); - } -) - class ImportTnOrder { use BaseModel; diff --git a/src/simpleModels/ImportTnOrderResponse.php b/src/simpleModels/ImportTnOrderResponse.php new file mode 100644 index 0000000..8eb49f6 --- /dev/null +++ b/src/simpleModels/ImportTnOrderResponse.php @@ -0,0 +1,15 @@ + array("type" => "\Iris\ImportTnOrder") + ); + + public function __construct($data) { + $this->set_data($data); + } +) From dd536aaf7bb04fa0c1390d3da567c99ad082d792 Mon Sep 17 00:00:00 2001 From: jmulford-bandwidth Date: Thu, 30 Jan 2020 13:24:50 -0500 Subject: [PATCH 3/4] Fixed syntax, updated readme with code example --- README.md | 32 ++++++++++++++++++++++ src/simpleModels/ImportTnOrderResponse.php | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37ea56e..87420b0 100644 --- a/README.md +++ b/README.md @@ -601,3 +601,35 @@ $data = array( ); $tnoptions->create($data); ``` + +## Import TN Orders + +### Get Import TN Orders +```PHP +$account->getImportTnOrders(array( + "createdDateFrom" => "2013-10-22T00:00:00.000Z", + "createdDateTo" => "2013-10-25T00:00:00.000Z" +)); +``` + +### Create Import TN Order +```PHP +$importTnOrder = new \Iris\ImportTnOrder(array( + "CustomerOrderId" => "custom string", + "TelephoneNumbers" => array( + "TelephoneNumber" => array("+15554443333", "+15553332222") + ) +)); + +$account->createImportTnOrder($importTnOrder); +``` + +### Get Import TN Order By ID +```PHP +$account->getImportTnOrder("some_id_value"); +``` + +### Get Import TN Order History +```PHP +$account->getImportTnOrderHistory("some_id_value"); +``` diff --git a/src/simpleModels/ImportTnOrderResponse.php b/src/simpleModels/ImportTnOrderResponse.php index 8eb49f6..6b957a3 100644 --- a/src/simpleModels/ImportTnOrderResponse.php +++ b/src/simpleModels/ImportTnOrderResponse.php @@ -12,4 +12,4 @@ class ImportTnOrderResponse { public function __construct($data) { $this->set_data($data); } -) +} From a96ebec5acb76e9f1837048557d21ab9665dcfdf Mon Sep 17 00:00:00 2001 From: jmulford-bandwidth Date: Thu, 30 Jan 2020 13:47:48 -0500 Subject: [PATCH 4/4] Added tests --- README.md | 4 ++-- src/Account.php | 2 +- tests/AccountTest.php | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 87420b0..faeb404 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,8 @@ $client = new \Iris\Client($login, $password, ['url' => 'https://dashboard.bandw ## Run tests ```bash -$ composer install -$ php ./bin/phpunit --bootstrap ./vendor/autoload.php tests/ +composer install +php ./bin/phpunit --bootstrap ./vendor/autoload.php tests/ ``` ======= ## Examples diff --git a/src/Account.php b/src/Account.php index 3cd8ab1..617ae37 100644 --- a/src/Account.php +++ b/src/Account.php @@ -266,7 +266,7 @@ public function createImportTnOrder(ImportTnOrder $order) { public function getImportTnOrder($id) { $url = sprintf('%s/%s/%s', $this->account_id, 'importTnOrders', $id); $response = parent::_get($url); - return new ImportTnOrder($response); + return new ImportTnOrderResponse($response); } public function getImportTnOrderHistory($id) { diff --git a/tests/AccountTest.php b/tests/AccountTest.php index 3099da7..859d6c0 100644 --- a/tests/AccountTest.php +++ b/tests/AccountTest.php @@ -59,6 +59,39 @@ public static function setUpBeforeClass() { new Response(201, ['Location' => 'https://api.test.inetwork.com:443/v1.0/accounts/9500249/billingreports/a12b456c8-abcd-1a3b-a1b2-0a2b4c6d8e0f2'], 'RECEIVEDThe report archive is currently being constructed.'), new Response(200, ['Location' => 'https://api.test.inetwork.com:443/v1.0/accounts/9500249/billingreports/a12b456c8-abcd-1a3b-a1b2-0a2b4c6d8e0f2/file'], 'COMPLETEDThe report archive is constructed.'), new Response(200, ['Content-Type' => 'application/zip'], 'zipcontent'), + new Response(200, [], " + + + SJM000001 + 2018-01-20T02:59:54.000Z + 9900012 + smckinnon + b05de7e6-0cab-4c83-81bb-9379cba8efd0 + 2018-01-20T02:59:54.000Z + 202 + 520565 + + ABC Inc. + + 11235 + Back + Denver + CO + 27541 + Canyon + + + The Authguy + + 9199918388 + 4158714245 + 4352154439 + 4352154466 + + PROCESSING + + + "), ]); self::$container = []; @@ -278,4 +311,11 @@ public function testBillingReportReadyAndDownload() { $this->assertEquals("https://api.test.inetwork.com/v1.0/accounts/9500249/billingreports/a12b456c8-abcd-1a3b-a1b2-0a2b4c6d8e0f2/file", self::$container[self::$index]['request']->getUri()); self::$index++; } + + public function testGetImportTnOrder() { + $importTnOrderResponse = self::$account->getImportTnOrder("b05de7e6-0cab-4c83-81bb-9379cba8efd0"); + + $this->assertEquals("b05de7e6-0cab-4c83-81bb-9379cba8efd0", $importTnOrderResponse->ImportTnOrder->OrderId); + self::$index++; + } }