Skip to content
54 changes: 54 additions & 0 deletions src/Voice/Bxml/Connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Connect.php
*
* Implementation of the BXML Connect verb for BRTC endpoints
*
* @copyright Bandwidth INC
*/

namespace BandwidthLib\Voice\Bxml;

use DOMDocument;
use DOMElement;

require_once "Verb.php";

class Connect extends Verb {
/**
* @var array
*/
private $endpoints;

/**
* @param array $endpoints Array of Endpoint objects
*/
public function __construct(array $endpoints = []) {
$this->endpoints = $endpoints;
}

/**
* Add an Endpoint to the Connect verb
*
* @param Endpoint $endpoint
* @return $this
*/
public function addEndpoint(Endpoint $endpoint): Connect {
$this->endpoints[] = $endpoint;
return $this;
}

/**
* Converts the Connect verb into a DOMElement
*
* @param DOMDocument $doc
* @return DOMElement
*/
public function toBxml(DOMDocument $doc): DOMElement {
$element = $doc->createElement("Connect");
foreach ($this->endpoints as $endpoint) {
$element->appendChild($endpoint->toBxml($doc));
}
return $element;
}
}
41 changes: 41 additions & 0 deletions src/Voice/Bxml/Endpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Endpoint.php
*
* Implementation of the BXML Endpoint verb for BRTC endpoints
*
* @copyright Bandwidth INC
*/

namespace BandwidthLib\Voice\Bxml;

use DOMDocument;
use DOMElement;

require_once "Verb.php";

class Endpoint extends Verb {
/**
* @var string
*/
private $id;

/**
* @param string $id The endpointId to connect to
*/
public function __construct(string $id) {
$this->id = $id;
}

/**
* Converts the Endpoint verb into a DOMElement
*
* @param DOMDocument $doc
* @return DOMElement
*/
public function toBxml(DOMDocument $doc): DOMElement {
$element = $doc->createElement("Endpoint");
$element->setAttribute("id", $this->id);
return $element;
}
}
216 changes: 208 additions & 8 deletions src/Voice/Controllers/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ public function getDownloadCallRecording(
) {

//prepare query string for API call
$_queryBuilder =
$_queryBuilder =
'/api/v2/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media';

//process optional query parameters
Expand Down Expand Up @@ -1040,7 +1040,7 @@ public function deleteRecordingMedia(
) {

//prepare query string for API call
$_queryBuilder =
$_queryBuilder =
'/api/v2/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media';

//process optional query parameters
Expand Down Expand Up @@ -1149,7 +1149,7 @@ public function getCallTranscription(
) {

//prepare query string for API call
$_queryBuilder =
$_queryBuilder =
'/api/v2/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription';

//process optional query parameters
Expand Down Expand Up @@ -1266,7 +1266,7 @@ public function createTranscribeCallRecording(
) {

//prepare query string for API call
$_queryBuilder =
$_queryBuilder =
'/api/v2/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription';

//process optional query parameters
Expand Down Expand Up @@ -1386,7 +1386,7 @@ public function deleteCallTranscription(
) {

//prepare query string for API call
$_queryBuilder =
$_queryBuilder =
'/api/v2/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription';

//process optional query parameters
Expand Down Expand Up @@ -1952,7 +1952,7 @@ public function getConferenceMember(
) {

//prepare query string for API call
$_queryBuilder =
$_queryBuilder =
'/api/v2/accounts/{accountId}/conferences/{conferenceId}/members/{memberId}';

//process optional query parameters
Expand Down Expand Up @@ -2179,7 +2179,7 @@ public function getConferenceRecording(
) {

//prepare query string for API call
$_queryBuilder =
$_queryBuilder =
'/api/v2/accounts/{accountId}/conferences/{conferenceId}/recordings/{recordingId}';

//process optional query parameters
Expand Down Expand Up @@ -2294,7 +2294,7 @@ public function getDownloadConferenceRecording(
) {

//prepare query string for API call
$_queryBuilder =
$_queryBuilder =
'/api/v2/accounts/{accountId}/conferences/{conferenceId}/recordings/{recordingId}/media';

//process optional query parameters
Expand Down Expand Up @@ -2514,4 +2514,204 @@ public function getQueryCallRecordings(
);
return new ApiResponse($response->code, $response->headers, $deserializedResponse);
}

/**
* Creates a BRTC endpoint.
*
* @param string $accountId
* @param Models\CreateEndpointRequest $body
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function createEndpoint(
string $accountId,
Models\CreateEndpointRequest $body
) {
$_queryBuilder = '/accounts/{accountId}/endpoints';
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array(
'accountId' => $accountId,
));
$_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::PHONENUMBERLOOKUPDEFAULT) . $_queryBuilder);
$_headers = array(
'user-agent' => BaseController::USER_AGENT,
'Accept' => 'application/json',
'content-type' => 'application/json; charset=utf-8'
);
$_bodyJson = Request\Body::Json($body);
$this->configureAuth($_headers, 'voice');
$_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl);
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
}
Request::timeout($this->config->getTimeout());
$response = Request::post($_queryUrl, $_headers, $_bodyJson);
$_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
$_httpContext = new HttpContext($_httpRequest, $_httpResponse);
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnAfterRequest($_httpContext);
}
$this->validateResponse($_httpResponse, $_httpContext);
$mapper = $this->getJsonMapper();
$deserializedResponse = $mapper->mapClass($response->body, 'BandwidthLib\\Voice\\Models\\CreateEndpointResponse');
return new ApiResponse($response->code, $response->headers, $deserializedResponse);
}

/**
* Lists BRTC endpoints for an account.
*
* @param string $accountId
* @param array $queryParams Optional filter/pagination params
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function listEndpoints(
string $accountId,
array $queryParams = []
) {
$_queryBuilder = '/accounts/{accountId}/endpoints';
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array(
'accountId' => $accountId,
));
if (!empty($queryParams)) {
$_queryBuilder = APIHelper::appendUrlWithQueryParameters($_queryBuilder, $queryParams);
}
$_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::PHONENUMBERLOOKUPDEFAULT) . $_queryBuilder);
$_headers = array(
'user-agent' => BaseController::USER_AGENT,
'Accept' => 'application/json'
);
$this->configureAuth($_headers, 'voice');
$_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
}
Request::timeout($this->config->getTimeout());
$response = Request::get($_queryUrl, $_headers);
$_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
$_httpContext = new HttpContext($_httpRequest, $_httpResponse);
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnAfterRequest($_httpContext);
}
$this->validateResponse($_httpResponse, $_httpContext);
$mapper = $this->getJsonMapper();
$deserializedResponse = $mapper->mapClassArray($response->body, 'BandwidthLib\\Voice\\Models\\Endpoint');
return new ApiResponse($response->code, $response->headers, $deserializedResponse);
}

/**
* Gets details for a specific BRTC endpoint.
*
* @param string $accountId
* @param string $endpointId
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function getEndpoint(
string $accountId,
string $endpointId
) {
$_queryBuilder = '/accounts/{accountId}/endpoints/{endpointId}';
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array(
'accountId' => $accountId,
'endpointId' => $endpointId,
));
$_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::PHONENUMBERLOOKUPDEFAULT) . $_queryBuilder);
$_headers = array(
'user-agent' => BaseController::USER_AGENT,
'Accept' => 'application/json'
);
$this->configureAuth($_headers, 'voice');
$_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
}
Request::timeout($this->config->getTimeout());
$response = Request::get($_queryUrl, $_headers);
$_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
$_httpContext = new HttpContext($_httpRequest, $_httpResponse);
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnAfterRequest($_httpContext);
}
$this->validateResponse($_httpResponse, $_httpContext);
$mapper = $this->getJsonMapper();
$deserializedResponse = $mapper->mapClass($response->body, 'BandwidthLib\\Voice\\Models\\Endpoint');
return new ApiResponse($response->code, $response->headers, $deserializedResponse);
}

/**
* Deletes a BRTC endpoint.
*
* @param string $accountId
* @param string $endpointId
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function deleteEndpoint(
string $accountId,
string $endpointId
) {
$_queryBuilder = '/accounts/{accountId}/endpoints/{endpointId}';
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array(
'accountId' => $accountId,
'endpointId' => $endpointId,
));
$_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::PHONENUMBERLOOKUPDEFAULT) . $_queryBuilder);
$_headers = array(
'user-agent' => BaseController::USER_AGENT
);
$this->configureAuth($_headers, 'voice');
$_httpRequest = new HttpRequest(HttpMethod::DELETE, $_headers, $_queryUrl);
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
}
Request::timeout($this->config->getTimeout());
$response = Request::delete($_queryUrl, $_headers);
$_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
$_httpContext = new HttpContext($_httpRequest, $_httpResponse);
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnAfterRequest($_httpContext);
}
$this->validateResponse($_httpResponse, $_httpContext);
return new ApiResponse($response->code, $response->headers, null);
}

/**
* Updates the BXML for a BRTC endpoint.
*
* @param string $accountId
* @param string $endpointId
* @param string $body Valid BXML string
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function updateEndpointBxml(
string $accountId,
string $endpointId,
string $body
) {
$_queryBuilder = '/accounts/{accountId}/endpoints/{endpointId}/bxml';
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array(
'accountId' => $accountId,
'endpointId' => $endpointId,
));
$_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::PHONENUMBERLOOKUPDEFAULT) . $_queryBuilder);
$_headers = array(
'user-agent' => BaseController::USER_AGENT,
'content-type' => 'application/xml; charset=utf-8'
);
$this->configureAuth($_headers, 'voice');
$_httpRequest = new HttpRequest(HttpMethod::PUT, $_headers, $_queryUrl);
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
}
Request::timeout($this->config->getTimeout());
$response = Request::put($_queryUrl, $_headers, $body);
$_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
$_httpContext = new HttpContext($_httpRequest, $_httpResponse);
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnAfterRequest($_httpContext);
}
$this->validateResponse($_httpResponse, $_httpContext);
return new ApiResponse($response->code, $response->headers, null);
}
}
Loading
Loading