Skip to content

Commit ac7170b

Browse files
authored
Dx 995 (#58)
* Added skeleton code * Added non file upload/download code * Added upload/download code * Updated readme and composer.json * Added tests * Fixed syntax and added get tests * Updated readme and fixed files as needed * Fixed file download * removed comments since code is correct * Reverted check on put upload since it's unnecessary
1 parent bbf7163 commit ac7170b

File tree

6 files changed

+178
-2
lines changed

6 files changed

+178
-2
lines changed

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ PHP Client library for Bandwidth's Phone Number Dashboard (AKA: Dashboard, Iris)
1717
| 2.0.8 | Fixed rate center check |
1818
| 2.1.0 | Added `importTnOrders`, `removeImportedTnOrders`, `inserviceNumbers`, and `importTnChecker` endpoints |
1919
| 2.2.0 | Added `csrs` endpoints |
20+
| 2.3.0 | Added `loas` endpoints for ImportTnOrders |
2021

2122
## Supported PHP Versions
2223

@@ -650,6 +651,74 @@ print_r($account->getImportTnOrder("some_id_value")->ProcessingStatus);
650651
print_r($account->getImportTnOrderHistory("some_id_value")->OrderHistory[0]->Status);
651652
```
652653

654+
### Get Import TN Order LOAs
655+
```PHP
656+
$response = $account->getImportTnOrderLoas("order_id");
657+
print_r($response->resultMessage);
658+
echo "\n";
659+
print_r($response->fileNames); //this can be a single string (if there's 1 file) or an array of strings (if there's multiple files)
660+
```
661+
662+
### Upload LOA file for an Import TN Order
663+
Valid `mime_types` can be found on the [Dashboard API Reference](https://dev.bandwidth.com/numbers/apiReference.html) under `/accounts /{accountId} /importTnOrders /{orderid} /loas`
664+
665+
Mime types are expected to be in the format `x/y`, such as `application/pdf` or `text/plain`
666+
667+
```PHP
668+
$account->uploadImportTnOrderLoaFile("order_id", "binary_file_contents", "mime_type");
669+
```
670+
671+
```PHP
672+
$filename = "loa.pdf";
673+
$file = fopen($filename, "rb") or die("Unable to open file");
674+
$file_contents = fread($file, filesize($filename));
675+
$account->uploadImportTnOrderLoaFile("order_id", $file_contents, "application/pdf");
676+
fclose($file);
677+
```
678+
679+
### Download LOA file for an Import TN Order (bonked. come back to this)
680+
Note: Make sure to grab the desired file ID from the response of `$account->getImportTnOrderLoas($order_id)` in the field `$response->fileNames`
681+
682+
```PHP
683+
$response = $account->downloadImportTnOrderLoaFile("order_id", "file_id");
684+
$file = fopen("write.pdf", "wb") or die("Unable to open file");
685+
fwrite($file, $response);
686+
fclose($file);
687+
```
688+
689+
### Replace LOA file for an Import TN Order
690+
```PHP
691+
$account->replaceImportTnOrderLoaFile("order_id", "file_id", "binary_file_contents", "mime_type");
692+
```
693+
694+
### Delete LOA file for an Import TN Order
695+
```PHP
696+
$account->deleteImportTnOrderLoaFile("order_id", "file_id");
697+
```
698+
699+
### Get LOA file metadata for an Import TN Order
700+
```PHP
701+
$response = $account->getImportTnOrderLoaFileMetadata("order_id", "file_id");
702+
print_r($response->DocumentName);
703+
echo "\n";
704+
print_r($response->DocumentType);
705+
706+
```
707+
708+
### Update LOA file metadata for an Import TN Order
709+
```PHP
710+
$file_metadata = new \Iris\FileMetaData(array(
711+
"DocumentName" => "Updated",
712+
"DocumentType" => "LOA"
713+
));
714+
$account->updateImportTnOrderLoaFileMetadata("order_id", "file_id", $file_metadata);
715+
```
716+
717+
### Delete LOA file metadata for an Import TN Order
718+
```PHP
719+
$account->deleteImportTnOrderLoaFileMetadata("order_id", "file_id");
720+
```
721+
653722
### Check TNs Portability
654723
```PHP
655724
print_r($account->checkTnsPortability(array("5554443333", "5553334444"))->ImportTnCheckerPayload);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Bandwidth's Iris SDK for PHP",
55
"keywords": ["iris","sdk","php"],
66
"homepage": "http://dev.bandwidth.com",
7-
"reference": "v2.2.0",
7+
"reference": "v2.3.0",
88
"license": "MIT",
99
"authors": [
1010
],

core/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function raw_file_post($url, $content, $headers = [])
232232
];
233233
$response = $this->request('post', $url, $options, false);
234234

235-
if (!isset($response['Location']))
235+
if (!is_array($response) || !isset($response['Location']))
236236
{
237237
return '';
238238
}

src/Account.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,50 @@ public function getImportTnOrderHistory($id) {
275275
return new OrderHistoryResponse($response);
276276
}
277277

278+
public function getImportTnOrderLoas($order_id) {
279+
$url = sprintf('%s/%s/%s/%s', $this->account_id, 'importtnorders', $order_id, 'loas');
280+
$response = parent::_get($url);
281+
return new FileListResponse($response);
282+
}
283+
284+
public function uploadImportTnOrderLoaFile($order_id, $file_contents, $mime_type) {
285+
$url = sprintf('%s/%s/%s/%s', $this->account_id, 'importtnorders', $order_id, 'loas');
286+
parent::raw_file_post($url, $file_contents, array("Content-Type" => $mime_type));
287+
}
288+
289+
public function downloadImportTnOrderLoaFile($order_id, $file_id) {
290+
$url = sprintf('accounts/%s/%s/%s/%s/%s', $this->account_id, 'importtnorders', $order_id, 'loas', $file_id);
291+
//using the request function directly in order to set $parse=false
292+
$response = $this->client->request('get', $url, $options=[], $parse=false)->getBody()->getContents();
293+
return $response;
294+
}
295+
296+
public function replaceImportTnOrderLoaFile($order_id, $file_id, $file_contents, $mime_type) {
297+
$url = sprintf('%s/%s/%s/%s/%s', $this->account_id, 'importtnorders', $order_id, 'loas', $file_id);
298+
parent::raw_file_put($url, $file_contents, array("Content-Type" => $mime_type));
299+
}
300+
301+
public function deleteImportTnOrderLoaFile($order_id, $file_id) {
302+
$url = sprintf('%s/%s/%s/%s/%s', $this->account_id, 'importtnorders', $order_id, 'loas', $file_id);
303+
parent::_delete($url);
304+
}
305+
306+
public function getImportTnOrderLoaFileMetadata($order_id, $file_id) {
307+
$url = sprintf('%s/%s/%s/%s/%s/%s', $this->account_id, 'importtnorders', $order_id, 'loas', $file_id, 'metadata');
308+
$response = parent::_get($url);
309+
return new FileMetaData($response);
310+
}
311+
312+
public function updateImportTnOrderLoaFileMetadata($order_id, $file_id, FileMetaData $file_metadata) {
313+
$url = sprintf('%s/%s/%s/%s/%s/%s', $this->account_id, 'importtnorders', $order_id, 'loas', $file_id, 'metadata');
314+
parent::put($url, 'FileMetaData', $file_metadata->to_array());
315+
}
316+
317+
public function deleteImportTnOrderLoaFileMetadata($order_id, $file_id) {
318+
$url = sprintf('%s/%s/%s/%s/%s/%s', $this->account_id, 'importtnorders', $order_id, 'loas', $file_id, 'metadata');
319+
parent::_delete($url);
320+
}
321+
278322
public function checkTnsPortability($tns) {
279323
$url = sprintf('%s/%s', $this->account_id, 'importTnChecker');
280324
$payload = new ImportTnCheckerPayload(array(

src/simpleModels/FileListResponse.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Iris;
4+
5+
class FileListResponse {
6+
use BaseModel;
7+
8+
protected $fields = array(
9+
"fileCount" => array("type" => "integer"),
10+
"fileNames" => array("type" => "string"),
11+
"resultCode" => array("type" => "integer"),
12+
"resultMessage" => array("type" => "string")
13+
);
14+
15+
public function __construct($data) {
16+
$this->set_data($data);
17+
}
18+
}

tests/AccountTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,26 @@ public static function setUpBeforeClass() {
203203
<LastDateModifier>2014-11-16T04:08:46.000Z</LastDateModifier>
204204
</Note>
205205
</Notes> "),
206+
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
207+
<fileListResponse>
208+
<fileCount>2</fileCount>
209+
<fileNames>803f3cc5-beae-469e-bd65-e9891ccdffb9-1092874634747.pdf</fileNames>
210+
<resultCode>0</resultCode>
211+
<resultMessage>LOA file list successfully returned</resultMessage>
212+
</fileListResponse>"),
213+
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
214+
<fileListResponse>
215+
<fileCount>2</fileCount>
216+
<fileNames>803f3cc5-beae-469e-bd65-e9891ccdffb9-1092874634747.pdf</fileNames>
217+
<fileNames>803f3cc5-beae-469e-bd65-e9891ccdffb9-1430814967669.pdf</fileNames>
218+
<resultCode>0</resultCode>
219+
<resultMessage>LOA file list successfully returned</resultMessage>
220+
</fileListResponse>"),
221+
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
222+
<FileMetaData>
223+
<DocumentName>file </DocumentName>
224+
<DocumentType>LOA</DocumentType>
225+
</FileMetaData>"),
206226
]);
207227

208228
self::$container = [];
@@ -488,4 +508,29 @@ public function testGetCsrOrderNotes() {
488508
$this->assertEquals("This is a second test note", $response->Note[1]->Description);
489509
self::$index++;
490510
}
511+
512+
public function testGetImportTnOrderLoas() {
513+
//1 element in fileNames
514+
$response = self::$account->getImportTnOrderLoas("order_id");
515+
516+
$this->assertEquals("803f3cc5-beae-469e-bd65-e9891ccdffb9-1092874634747.pdf", $response->fileNames);
517+
$this->assertEquals("LOA file list successfully returned", $response->resultMessage);
518+
self::$index++;
519+
520+
//2 elements in fileNames
521+
$response = self::$account->getImportTnOrderLoas("order_id");
522+
523+
$this->assertEquals("803f3cc5-beae-469e-bd65-e9891ccdffb9-1092874634747.pdf", $response->fileNames[0]);
524+
$this->assertEquals("803f3cc5-beae-469e-bd65-e9891ccdffb9-1430814967669.pdf", $response->fileNames[1]);
525+
$this->assertEquals("LOA file list successfully returned", $response->resultMessage);
526+
self::$index++;
527+
}
528+
529+
public function testGetImportTnOrderLoaFileMetadata() {
530+
$response = self::$account->getImportTnOrderLoaFileMetadata("order_id", "file_id");
531+
532+
$this->assertEquals("file", $response->DocumentName);
533+
$this->assertEquals("LOA", $response->DocumentType);
534+
self::$index++;
535+
}
491536
}

0 commit comments

Comments
 (0)