Skip to content

Commit

Permalink
New deploy (#18)
Browse files Browse the repository at this point in the history
* New deploy

* Update APIController.php

Co-authored-by: jmulford-bw <[email protected]>
  • Loading branch information
jmulford-bw and DX-Bandwidth authored Feb 1, 2021
1 parent f439f0f commit 4329b75
Show file tree
Hide file tree
Showing 10 changed files with 435 additions and 146 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.7",
"phan/phan": "^1.2"
"phan/phan": "^1.2",
"phpunit/phpunit": "4.8.*"
},
"autoload": {
"psr-4": {
Expand Down
20 changes: 20 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
syntaxCheck="true"
verbose="true"
>
<testsuites>
<testsuite name="SDK Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
158 changes: 142 additions & 16 deletions src/Messaging/Controllers/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function __construct($config, $httpCallBack = null)
/**
* listMedia
*
* @param string $userId TODO: type description here
* @param string $continuationToken (optional) TODO: type description here
* @param string $userId User's account ID
* @param string $continuationToken (optional) Continuation token used to retrieve subsequent media.
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
Expand Down Expand Up @@ -122,8 +122,8 @@ public function listMedia(
/**
* getMedia
*
* @param string $userId TODO: type description here
* @param string $mediaId TODO: type description here
* @param string $userId User's account ID
* @param string $mediaId Media ID to retrieve
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
Expand Down Expand Up @@ -210,12 +210,13 @@ public function getMedia(
/**
* uploadMedia
*
* @param string $userId TODO: type description here
* @param string $mediaId TODO: type description here
* @param integer $contentLength TODO: type description here
* @param string $userId User's account ID
* @param string $mediaId The user supplied custom media ID
* @param integer $contentLength The size of the entity-body
* @param string $body TODO: type description here
* @param string $contentType (optional) Example: application/octet-stream
* @param string $cacheControl (optional) TODO: type description here
* @param string $contentType (optional) The media type of the entity-body
* @param string $cacheControl (optional) General-header field is used to specify directives that MUST be obeyed
* by all caching mechanisms along the request/response chain.
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
Expand All @@ -233,8 +234,8 @@ public function uploadMedia(

//process optional query parameters
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
'userId' => $userId,
'mediaId' => $mediaId,
'userId' => $userId,
'mediaId' => $mediaId,
), false
);

Expand Down Expand Up @@ -311,8 +312,8 @@ public function uploadMedia(
/**
* deleteMedia
*
* @param string $userId TODO: type description here
* @param string $mediaId TODO: type description here
* @param string $userId User's account ID
* @param string $mediaId The media ID to delete
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
Expand Down Expand Up @@ -395,17 +396,142 @@ public function deleteMedia(
return new ApiResponse($response->code, $response->headers, null);
}

/**
* getMessages
*
* @param string $userId User's account ID
* @param string $messageId (optional) The ID of the message to search for. Special characters need to be
* encoded using URL encoding
* @param string $sourceTn (optional) The phone number that sent the message
* @param string $destinationTn (optional) The phone number that received the message
* @param string $messageStatus (optional) The status of the message. One of RECEIVED, QUEUED, SENDING, SENT,
* FAILED, DELIVERED, DLR_EXPIRED
* @param integer $errorCode (optional) The error code of the message
* @param string $fromDateTime (optional) The start of the date range to search in ISO 8601 format. Uses the
* message receive time. The date range to search in is currently 14 days.
* @param string $toDateTime (optional) The end of the date range to search in ISO 8601 format. Uses the
* message receive time. The date range to search in is currently 14 days.
* @param string $pageToken (optional) A base64 encoded value used for pagination of results
* @param integer $limit (optional) The maximum records requested in search result. Default 100. The sum of
* limit and after cannot be more than 10000
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function getMessages(
$userId,
$messageId = null,
$sourceTn = null,
$destinationTn = null,
$messageStatus = null,
$errorCode = null,
$fromDateTime = null,
$toDateTime = null,
$pageToken = null,
$limit = null
) {

//prepare query string for API call
$_queryBuilder = '/users/{userId}/messages';

//process optional query parameters
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
'userId' => $userId,
));

//process optional query parameters
APIHelper::appendUrlWithQueryParameters($_queryBuilder, array (
'messageId' => $messageId,
'sourceTn' => $sourceTn,
'destinationTn' => $destinationTn,
'messageStatus' => $messageStatus,
'errorCode' => $errorCode,
'fromDateTime' => $fromDateTime,
'toDateTime' => $toDateTime,
'pageToken' => $pageToken,
'limit' => $limit,
));

//validate and preprocess url
$_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::MESSAGINGDEFAULT) . $_queryBuilder);

//prepare headers
$_headers = array (
'user-agent' => BaseController::USER_AGENT,
'Accept' => 'application/json'
);

//set HTTP basic auth parameters
Request::auth($this->config->getMessagingBasicAuthUserName(), $this->config->getMessagingBasicAuthPassword());

$_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);

//call on-before Http callback
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
}
// Set request timeout
Request::timeout($this->config->getTimeout());

// and invoke the API call request to fetch the response
$response = Request::get($_queryUrl, $_headers);

$_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
$_httpContext = new HttpContext($_httpRequest, $_httpResponse);

//call on-after Http callback
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnAfterRequest($_httpContext);
}

//Error handling using HTTP status codes
if ($response->code == 400) {
throw new Exceptions\MessagingException('400 Request is malformed or invalid', $_httpContext);
}

if ($response->code == 401) {
throw new Exceptions\MessagingException(
'401 The specified user does not have access to the account',
$_httpContext
);
}

if ($response->code == 403) {
throw new Exceptions\MessagingException('403 The user does not have access to this API', $_httpContext);
}

if ($response->code == 404) {
throw new Exceptions\MessagingException('404 Path not found', $_httpContext);
}

if ($response->code == 415) {
throw new Exceptions\MessagingException('415 The content-type of the request is incorrect', $_httpContext);
}

if ($response->code == 429) {
throw new Exceptions\MessagingException('429 The rate limit has been reached', $_httpContext);
}

//handle errors defined at the API level
$this->validateResponse($_httpResponse, $_httpContext);
$mapper = $this->getJsonMapper();
$deserializedResponse = $mapper->mapClass(
$response->body,
'BandwidthLib\\Messaging\\Models\\BandwidthMessagesList'
);
return new ApiResponse($response->code, $response->headers, $deserializedResponse);
}

/**
* createMessage
*
* @param string $userId TODO: type description here
* @param Models\MessageRequest $body (optional) TODO: type description here
* @param string $userId User's account ID
* @param Models\MessageRequest $body TODO: type description here
* @return ApiResponse response from the API call
* @throws APIException Thrown if API call fails
*/
public function createMessage(
$userId,
$body = null
$body
) {

//prepare query string for API call
Expand Down
23 changes: 12 additions & 11 deletions src/Messaging/Models/BandwidthMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,68 @@
class BandwidthMessage implements \JsonSerializable
{
/**
* @todo Write general description for this property
* The id of the message
* @var string|null $id public property
*/
public $id;

/**
* @todo Write general description for this property
* The Bandwidth phone number associated with the message
* @var string|null $owner public property
*/
public $owner;

/**
* @todo Write general description for this property
* The application ID associated with the message
* @var string|null $applicationId public property
*/
public $applicationId;

/**
* @todo Write general description for this property
* The datetime stamp of the message in ISO 8601
* @var string|null $time public property
*/
public $time;

/**
* @todo Write general description for this property
* The number of segments the original message from the user is broken into before sending over to
* carrier networks
* @var integer|null $segmentCount public property
*/
public $segmentCount;

/**
* @todo Write general description for this property
* The direction of the message relative to Bandwidth. Can be in or out
* @var string|null $direction public property
*/
public $direction;

/**
* @todo Write general description for this property
* The phone number recipients of the message
* @var array|null $to public property
*/
public $to;

/**
* @todo Write general description for this property
* The phone number the message was sent from
* @var string|null $from public property
*/
public $from;

/**
* @todo Write general description for this property
* The list of media URLs sent in the message
* @var array|null $media public property
*/
public $media;

/**
* @todo Write general description for this property
* The contents of the message
* @var string|null $text public property
*/
public $text;

/**
* @todo Write general description for this property
* The custom string set by the user
* @var string|null $tag public property
*/
public $tag;
Expand Down
Loading

0 comments on commit 4329b75

Please sign in to comment.