Skip to content

Commit a990bcb

Browse files
authored
Dx 1628 added application management (#69)
* DX-1628 added application management endpoints * Updated readme * Bumped version * Added check to always return a list for list items
1 parent 3450a17 commit a990bcb

File tree

4 files changed

+189
-1
lines changed

4 files changed

+189
-1
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PHP Client library for Bandwidth's Phone Number Dashboard (AKA: Dashboard, Iris)
2222
| 2.5.0 | Added `PortOutPasscode` for TnOption orders |
2323
| 2.5.1 | Fixed grabbing of response header for file uploads |
2424
| 3.0.0 | Updated to guzzle 7. This version no longer supports verisons of PHP less than 7.2. Older versions of this package will still work on PHP versions less than 7.2 |
25+
| 3.1.0 | Added application management |
2526

2627
## Supported PHP Versions
2728

@@ -1020,3 +1021,56 @@ $response = $account->getAlternateEndUserInformation();
10201021
```php
10211022
$response = $account->getAlternateCallerInformation("id");
10221023
```
1024+
1025+
## Application Management
1026+
1027+
### Get Applications
1028+
1029+
```php
1030+
$response = $account->getApplications();
1031+
print_r($response);
1032+
```
1033+
1034+
### Get Application
1035+
1036+
```php
1037+
$response = $account->getApplication("id");
1038+
print_r($response);
1039+
```
1040+
1041+
### Create Application
1042+
1043+
```php
1044+
$data = array(
1045+
'ServiceType' => 'Messaging-V2',
1046+
'AppName' => 'sample',
1047+
'MsgCallbackUrl' => 'https://test.com'
1048+
);
1049+
$response = $account->createApplication($data);
1050+
print_r($response);
1051+
```
1052+
1053+
### Update Application
1054+
1055+
```php
1056+
$data = array(
1057+
'ServiceType' => 'Messaging-V2',
1058+
'AppName' => 'sample',
1059+
'MsgCallbackUrl' => 'https://test2.com'
1060+
);
1061+
$response = $account->updateApplication("id", $data);
1062+
print_r($response);
1063+
```
1064+
1065+
### Delete Application
1066+
1067+
```php
1068+
$account->deleteApplication("id");
1069+
```
1070+
1071+
### Get Application SipPeers
1072+
1073+
```php
1074+
$response = $account->getApplicationSippeers("id");
1075+
print_r($response);
1076+
```

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": "v3.0.0",
7+
"reference": "v3.1.0",
88
"license": "MIT",
99
"authors": [
1010
],

src/Account.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,49 @@ public function deleteEmergencyNotificationRecipient($id) {
489489
$url = sprintf('%s/%s/%s', $this->account_id, 'emergencyNotificationRecipients', $id);
490490
parent::_delete($url);
491491
}
492+
493+
public function getApplications() {
494+
$url = sprintf('%s/%s', $this->account_id, 'applications');
495+
$data = parent::_get($url);
496+
$response = $data['ApplicationList']['Application'];
497+
if (array_values($response) == $response) {
498+
return $response;
499+
} else {
500+
return [$response];
501+
}
502+
}
503+
504+
public function getApplication($id) {
505+
$url = sprintf('%s/%s/%s', $this->account_id, 'applications', $id);
506+
$data = parent::_get($url);
507+
return $data['Application'];
508+
}
509+
510+
public function createApplication($application) {
511+
$url = sprintf('%s/%s', $this->account_id, 'applications');
512+
$data = parent::post($url, 'Application', $application);
513+
return $data['Application'];
514+
}
515+
516+
public function updateApplication($id, $application) {
517+
$url = sprintf('%s/%s/%s', $this->account_id, 'applications', $id);
518+
$data = parent::put($url, 'Application', $application);
519+
return $data['Application'];
520+
}
521+
522+
public function deleteApplication($id) {
523+
$url = sprintf('%s/%s/%s', $this->account_id, 'applications', $id);
524+
$data = parent::_delete($url);
525+
}
526+
527+
public function getApplicationSippeers($id) {
528+
$url = sprintf('%s/%s/%s/%s', $this->account_id, 'applications', $id, 'associatedsippeers');
529+
$data = parent::_get($url);
530+
$response = $data['AssociatedSipPeers']['AssociatedSipPeer'];
531+
if (array_values($response) == $response) {
532+
return $response;
533+
} else {
534+
return [$response];
535+
}
536+
}
492537
}

tests/AccountTest.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ public static function setUpBeforeClass() {
5757
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><EmergencyNotificationRecipientsResponse> <Links> <first> -- link to first page of results -- </first> <next> -- link to next page of results -- </next> </Links> <EmergencyNotificationRecipients> <EmergencyNotificationRecipient> <Identifier> 63865500-0904-46b1-9b4f-7bd237a26363 </Identifier> <CreatedDate>2020-03-18T21:26:47.403Z</CreatedDate> <LastModifiedDate>2020-03-18T21:26:47.403Z</LastModifiedDate> <ModifiedByUser>jgilmore</ModifiedByUser> <Description> This is a description of the emergency notification recipient. </Description> <Type>CALLBACK</Type> <Callback> <Url>https://foo.bar/baz</Url> <Credentials> <Username>jgilmore</Username> </Credentials> </Callback> </EmergencyNotificationRecipient> <EmergencyNotificationRecipient> <Identifier> 63865500-0904-46b1-9b4f-7bd237a26363 </Identifier> <CreatedDate>2020-03-22T12:13:25.782Z</CreatedDate> <LastModifiedDate>2020-03-22T12:13:25.782Z</LastModifiedDate> <ModifiedByUser>gfranklin</ModifiedByUser> <Description> This is a description of the emergency notification recipient. </Description> <Type>EMAIL</Type> <EmailAddress>[email protected]</EmailAddress> </EmergencyNotificationRecipient> <EmergencyNotificationRecipient> <Identifier> 63865500-0904-46b1-9b4f-7bd237a26363 </Identifier> <CreatedDate>2020-03-25T17:04:53.042Z</CreatedDate> <LastModifiedDate>2020-03-25T17:04:53.042Z</LastModifiedDate> <ModifiedByUser>msimpson</ModifiedByUser> <Description> This is a description of the emergency notification recipient. </Description> <Type>SMS</Type> <Sms> <TelephoneNumber>12015551212</TelephoneNumber> </Sms> </EmergencyNotificationRecipient> <EmergencyNotificationRecipient> <Identifier> 63865500-0904-46b1-9b4f-7bd237a26363 </Identifier> <CreatedDate>2020-03-29T20:14:01.736Z</CreatedDate> <LastModifiedDate>2020-03-29T20:17:53.294Z</LastModifiedDate> <ModifiedByUser>lsimpson</ModifiedByUser> <Description> This is a description of the emergency notification recipient. </Description> <Type>TTS</Type> <Tts> <TelephoneNumber>12015551212</TelephoneNumber> </Tts> </EmergencyNotificationRecipient> </EmergencyNotificationRecipients></EmergencyNotificationRecipientsResponse>"),
5858
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><EmergencyNotificationRecipientsResponse> <EmergencyNotificationRecipient> <Identifier> 63865500-0904-46b1-9b4f-7bd237a26363 </Identifier> <CreatedDate>2020-03-18T21:26:47.403Z</CreatedDate> <LastModifiedDate>2020-04-01T18:32:22.316Z</LastModifiedDate> <ModifiedByUser>jgilmore</ModifiedByUser> <Description> This is a description of the emergency notification recipient. </Description> <Type>CALLBACK</Type> <Callback> <Url>https://foo.bar/baz</Url> <Credentials> <Username>jgilmore</Username> </Credentials> </Callback> </EmergencyNotificationRecipient></EmergencyNotificationRecipientsResponse>"),
5959
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><EmergencyNotificationRecipientsResponse> <EmergencyNotificationRecipient> <Identifier> 63865500-0904-46b1-9b4f-7bd237a26363 </Identifier> <CreatedDate>2020-03-18T21:26:47.403Z</CreatedDate> <LastModifiedDate>2020-04-01T18:32:22.316Z</LastModifiedDate> <ModifiedByUser>jgilmore</ModifiedByUser> <Description> This is a description of the emergency notification recipient. </Description> <Type>CALLBACK</Type> <Callback> <Url>https://foo.bar/baz</Url> <Credentials> <Username>jgilmore</Username> </Credentials> </Callback> </EmergencyNotificationRecipient></EmergencyNotificationRecipientsResponse>"),
60+
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ApplicationProvisioningResponse> <ApplicationList> <Application> <ApplicationId>2cfcb382-161c-46d4-8c67-87ca09a72c85</ApplicationId> <ServiceType>Messaging-V2</ServiceType> <AppName>app1</AppName> <MsgCallbackUrl>http://a.com</MsgCallbackUrl> </Application> <Application> <ApplicationId>0cb0112b-5998-4c81-999a-0d3fb5e3f8e2</ApplicationId> <ServiceType>Voice-V2</ServiceType> <AppName>app2</AppName> <CallInitiatedCallbackUrl>http://b.com</CallInitiatedCallbackUrl> <CallbackCreds> <UserId>15jPWZmXdm</UserId> </CallbackCreds> <CallInitiatedFallbackUrl>https://fallback.com</CallInitiatedFallbackUrl> <CallInitiatedFallbackMethod>POST</CallInitiatedFallbackMethod> <CallInitiatedFallbackCreds> <UserId>login2</UserId> </CallInitiatedFallbackCreds> <CallbackTimeout>20</CallbackTimeout> </Application> </ApplicationList></ApplicationProvisioningResponse> "),
61+
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ApplicationProvisioningResponse> <ApplicationList> <Application> <ApplicationId>0cb0112b-5998-4c81-999a-0d3fb5e3f8e2</ApplicationId> <ServiceType>Voice-V2</ServiceType> <AppName>app2</AppName> <CallInitiatedCallbackUrl>http://b.com</CallInitiatedCallbackUrl> <CallbackCreds> <UserId>15jPWZmXdm</UserId> </CallbackCreds> <CallInitiatedFallbackUrl>https://fallback.com</CallInitiatedFallbackUrl> <CallInitiatedFallbackMethod>POST</CallInitiatedFallbackMethod> <CallInitiatedFallbackCreds> <UserId>login2</UserId> </CallInitiatedFallbackCreds> <CallbackTimeout>20</CallbackTimeout> </Application> </ApplicationList></ApplicationProvisioningResponse> "),
62+
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ApplicationProvisioningResponse> <Application> <ApplicationId>e5a9e103-097e-4ec4-87a0-50109fb7b4b1</ApplicationId> <ServiceType>Messaging-V2</ServiceType> <AppName>qMmmTT</AppName> <MsgCallbackUrl>http://example.com</MsgCallbackUrl> <CallbackCreds> <UserId>15jPWZmXdm</UserId> </CallbackCreds> </Application></ApplicationProvisioningResponse> "),
63+
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ApplicationProvisioningResponse> <Application> <ApplicationId>d4d1b41d-4c05-47d0-838a-34e4f14e4e3e</ApplicationId> <ServiceType>Messaging-V2</ServiceType> <AppName>EBVICs</AppName> <MsgCallbackUrl>http://example.com</MsgCallbackUrl> <CallbackCreds> <UserId>15jPWZmXdm</UserId> </CallbackCreds> </Application></ApplicationProvisioningResponse> "),
64+
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ApplicationProvisioningResponse> <Application> <ApplicationId>e5a9e103-097e-4ec4-87a0-50109fb7b4b1</ApplicationId> <ServiceType>Voice-V2</ServiceType> <AppName>EBVICs</AppName> <CallInitiatedCallbackUrl>https://example2.com</CallInitiatedCallbackUrl> <CallInitiatedMethod>GET</CallInitiatedMethod> <CallStatusCallbackUrl>https://example3.com</CallStatusCallbackUrl> <CallStatusMethod>GET</CallStatusMethod> </Application></ApplicationProvisioningResponse> "),
65+
new Response(200, []),
66+
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><AssociatedSipPeersResponse> <AssociatedSipPeers> <AssociatedSipPeer> <SiteId>482</SiteId> <SiteName>site_e867f</SiteName> <PeerId>500018</PeerId> <PeerName>sippeer-e867f</PeerName> </AssociatedSipPeer> <AssociatedSipPeer> <SiteId>483</SiteId> <SiteName>site_e867d</SiteName> <PeerId>500019</PeerId> <PeerName>sippeer-e867d</PeerName> </AssociatedSipPeer> </AssociatedSipPeers></AssociatedSipPeersResponse> "),
67+
new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><AssociatedSipPeersResponse> <AssociatedSipPeers> <AssociatedSipPeer> <SiteId>482</SiteId> <SiteName>site_e867f</SiteName> <PeerId>500018</PeerId> <PeerName>sippeer-e867f</PeerName> </AssociatedSipPeer> </AssociatedSipPeers></AssociatedSipPeersResponse> "),
6068
]);
6169

6270
self::$container = [];
@@ -469,4 +477,85 @@ public function testReplaceEmergencyNotificationRecipient() {
469477

470478
self::$index++;
471479
}
480+
481+
public function testGetApplications() {
482+
$response = self::$account->getApplications();
483+
484+
$this->assertEquals("GET", self::$container[self::$index]['request']->getMethod());
485+
$this->assertEquals("https://api.test.inetwork.com/v1.0/accounts/9500249/applications", (string) self::$container[self::$index]['request']->getUri());
486+
$this->assertEquals("0cb0112b-5998-4c81-999a-0d3fb5e3f8e2", $response[1]['ApplicationId']);
487+
488+
self::$index++;
489+
}
490+
491+
public function testGetApplicationsOneResponse() {
492+
$response = self::$account->getApplications();
493+
494+
$this->assertEquals("GET", self::$container[self::$index]['request']->getMethod());
495+
$this->assertEquals("https://api.test.inetwork.com/v1.0/accounts/9500249/applications", (string) self::$container[self::$index]['request']->getUri());
496+
$this->assertEquals("0cb0112b-5998-4c81-999a-0d3fb5e3f8e2", $response[0]['ApplicationId']);
497+
498+
self::$index++;
499+
}
500+
501+
public function testGetApplication() {
502+
$response = self::$account->getApplication("123");
503+
504+
$this->assertEquals("GET", self::$container[self::$index]['request']->getMethod());
505+
$this->assertEquals("https://api.test.inetwork.com/v1.0/accounts/9500249/applications/123", (string) self::$container[self::$index]['request']->getUri());
506+
$this->assertEquals("e5a9e103-097e-4ec4-87a0-50109fb7b4b1", $response['ApplicationId']);
507+
508+
self::$index++;
509+
}
510+
511+
public function testCreateApplication() {
512+
$data = array();
513+
$response = self::$account->createApplication($data);
514+
515+
$this->assertEquals("POST", self::$container[self::$index]['request']->getMethod());
516+
$this->assertEquals("https://api.test.inetwork.com/v1.0/accounts/9500249/applications", (string) self::$container[self::$index]['request']->getUri());
517+
$this->assertEquals("d4d1b41d-4c05-47d0-838a-34e4f14e4e3e", $response['ApplicationId']);
518+
519+
self::$index++;
520+
}
521+
522+
public function testUpdateApplication() {
523+
$data = array();
524+
$response = self::$account->updateApplication("123", $data);
525+
526+
$this->assertEquals("PUT", self::$container[self::$index]['request']->getMethod());
527+
$this->assertEquals("https://api.test.inetwork.com/v1.0/accounts/9500249/applications/123", (string) self::$container[self::$index]['request']->getUri());
528+
$this->assertEquals("e5a9e103-097e-4ec4-87a0-50109fb7b4b1", $response['ApplicationId']);
529+
530+
self::$index++;
531+
}
532+
533+
public function testDeleteApplication() {
534+
self::$account->deleteApplication("123");
535+
536+
$this->assertEquals("DELETE", self::$container[self::$index]['request']->getMethod());
537+
$this->assertEquals("https://api.test.inetwork.com/v1.0/accounts/9500249/applications/123", (string) self::$container[self::$index]['request']->getUri());
538+
539+
self::$index++;
540+
}
541+
542+
public function testGetApplicationSippeers() {
543+
$response = self::$account->getApplicationSippeers("123");
544+
545+
$this->assertEquals('site_e867f', $response[0]['SiteName']);
546+
$this->assertEquals("GET", self::$container[self::$index]['request']->getMethod());
547+
$this->assertEquals("https://api.test.inetwork.com/v1.0/accounts/9500249/applications/123/associatedsippeers", (string) self::$container[self::$index]['request']->getUri());
548+
549+
self::$index++;
550+
}
551+
552+
public function testGetApplicationSippeersOneResponse() {
553+
$response = self::$account->getApplicationSippeers("123");
554+
555+
$this->assertEquals('site_e867f', $response[0]['SiteName']);
556+
$this->assertEquals("GET", self::$container[self::$index]['request']->getMethod());
557+
$this->assertEquals("https://api.test.inetwork.com/v1.0/accounts/9500249/applications/123/associatedsippeers", (string) self::$container[self::$index]['request']->getUri());
558+
559+
self::$index++;
560+
}
472561
}

0 commit comments

Comments
 (0)