Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function getBaseUri($server = Servers::DEFAULT_)
Environments::PRODUCTION => array(
Servers::DEFAULT_ => 'api.bandwidth.com',
Servers::MESSAGINGDEFAULT => 'https://messaging.bandwidth.com/api/v2',
Servers::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1/',
Servers::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1',
Servers::VOICEDEFAULT => 'https://voice.bandwidth.com',
Servers::WEBRTCDEFAULT => 'https://api.webrtc.bandwidth.com/v1',
),
Expand Down
10 changes: 9 additions & 1 deletion src/Messaging/Models/BandwidthMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,18 @@ class BandwidthMessage implements \JsonSerializable
*/
public $tag;

/**
* The priority specified by the user
* @var string|null $priority public property
*/
public $priority;

/**
* Constructor to set initial or default values of member properties
*/
public function __construct()
{
if (11 == func_num_args()) {
if (12 == func_num_args()) {
$this->id = func_get_arg(0);
$this->owner = func_get_arg(1);
$this->applicationId = func_get_arg(2);
Expand All @@ -96,6 +102,7 @@ public function __construct()
$this->media = func_get_arg(8);
$this->text = func_get_arg(9);
$this->tag = func_get_arg(10);
$this->priority = func_get_arg(11);
}
}

Expand All @@ -118,6 +125,7 @@ public function jsonSerialize()
array_values($this->media) : null;
$json['text'] = $this->text;
$json['tag'] = $this->tag;
$json['priority'] = $this->priority;

return array_filter($json);
}
Expand Down
11 changes: 10 additions & 1 deletion src/Messaging/Models/MessageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,26 @@ class MessageRequest implements \JsonSerializable
*/
public $tag;

/**
* The message's priority, currently for toll-free or short code SMS only. Messages with a priority
* value of `"high"` are given preference over your other traffic.
* @var string|null $priority public property
*/
public $priority;

/**
* Constructor to set initial or default values of member properties
*/
public function __construct()
{
if (6 == func_num_args()) {
if (7 == func_num_args()) {
$this->applicationId = func_get_arg(0);
$this->to = func_get_arg(1);
$this->from = func_get_arg(2);
$this->text = func_get_arg(3);
$this->media = func_get_arg(4);
$this->tag = func_get_arg(5);
$this->priority = func_get_arg(6);
}
}

Expand All @@ -80,6 +88,7 @@ public function jsonSerialize()
$json['media'] = isset($this->media) ?
array_values($this->media) : null;
$json['tag'] = $this->tag;
$json['priority'] = $this->priority;

return array_filter($json);
}
Expand Down
25 changes: 25 additions & 0 deletions src/Messaging/Models/PriorityEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/*
* BandwidthLib
*
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
*/

namespace BandwidthLib\Messaging\Models;

/**
* The message's priority, currently for toll-free or short code SMS only. Messages with a priority
* value of `"high"` are given preference over your other traffic.
*/
class PriorityEnum
{
/**
* TODO: Write general description for this element
*/
const DEFAULT_ = "default";

/**
* TODO: Write general description for this element
*/
const HIGH = "high";
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
/**
* @todo Add a general description for this controller.
*/
class APIController extends BaseController
class MFAController extends BaseController
{
public function __construct($config, $httpCallBack = null)
{
parent::__construct($config, $httpCallBack);
}

/**
* Two-Factor authentication with Bandwidth Voice services
* Allows a user to send a MFA code through a phone call
*
* @param string $accountId Bandwidth Account ID with Voice service enabled
* @param Models\TwoFactorCodeRequestSchema $body TODO: type description here
Expand Down Expand Up @@ -89,7 +89,28 @@ public function createVoiceTwoFactor(

//Error handling using HTTP status codes
if ($response->code == 400) {
throw new Exceptions\InvalidRequestException('client request error', $_httpContext);
throw new Exceptions\ErrorWithRequestException(
'If there is any issue with values passed in by the user',
$_httpContext
);
}

if ($response->code == 401) {
throw new Exceptions\UnauthorizedRequestException(
'Authentication is either incorrect or not present',
$_httpContext
);
}

if ($response->code == 403) {
throw new Exceptions\ForbiddenRequestException(
'The user is not authorized to access this resource',
$_httpContext
);
}

if ($response->code == 500) {
throw new Exceptions\ErrorWithRequestException('An internal server error occurred', $_httpContext);
}

//handle errors defined at the API level
Expand All @@ -103,7 +124,7 @@ public function createVoiceTwoFactor(
}

/**
* Two-Factor authentication with Bandwidth messaging services
* Allows a user to send a MFA code through a text message (SMS)
*
* @param string $accountId Bandwidth Account ID with Messaging service enabled
* @param Models\TwoFactorCodeRequestSchema $body TODO: type description here
Expand Down Expand Up @@ -161,7 +182,28 @@ public function createMessagingTwoFactor(

//Error handling using HTTP status codes
if ($response->code == 400) {
throw new Exceptions\InvalidRequestException('client request error', $_httpContext);
throw new Exceptions\ErrorWithRequestException(
'If there is any issue with values passed in by the user',
$_httpContext
);
}

if ($response->code == 401) {
throw new Exceptions\UnauthorizedRequestException(
'Authentication is either incorrect or not present',
$_httpContext
);
}

if ($response->code == 403) {
throw new Exceptions\ForbiddenRequestException(
'The user is not authorized to access this resource',
$_httpContext
);
}

if ($response->code == 500) {
throw new Exceptions\ErrorWithRequestException('An internal server error occurred', $_httpContext);
}

//handle errors defined at the API level
Expand All @@ -175,7 +217,7 @@ public function createMessagingTwoFactor(
}

/**
* Verify a previously sent two-factor authentication code
* Allows a user to verify an MFA code
*
* @param string $accountId Bandwidth Account ID with Two-Factor enabled
* @param Models\TwoFactorVerifyRequestSchema $body TODO: type description here
Expand Down Expand Up @@ -233,7 +275,35 @@ public function createVerifyTwoFactor(

//Error handling using HTTP status codes
if ($response->code == 400) {
throw new Exceptions\InvalidRequestException('client request error', $_httpContext);
throw new Exceptions\ErrorWithRequestException(
'If there is any issue with values passed in by the user',
$_httpContext
);
}

if ($response->code == 401) {
throw new Exceptions\UnauthorizedRequestException(
'Authentication is either incorrect or not present',
$_httpContext
);
}

if ($response->code == 403) {
throw new Exceptions\ForbiddenRequestException(
'The user is not authorized to access this resource',
$_httpContext
);
}

if ($response->code == 429) {
throw new Exceptions\ErrorWithRequestException(
'The user has made too many bad requests and is temporarily locked out',
$_httpContext
);
}

if ($response->code == 500) {
throw new Exceptions\ErrorWithRequestException('An internal server error occurred', $_httpContext);
}

//handle errors defined at the API level
Expand Down
44 changes: 44 additions & 0 deletions src/TwoFactorAuth/Exceptions/ErrorWithRequestException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/*
* BandwidthLib
*
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
*/

namespace BandwidthLib\TwoFactorAuth\Exceptions;

use BandwidthLib\APIHelper;

/**
* @todo Write general description for this model
*/
class ErrorWithRequestException extends \BandwidthLib\APIException
{
/**
* An error message pertaining to what the issue could be
* @var string|null $error public property
*/
public $error;

/**
* The associated requestId from AWS
* @var string|null $requestId public property
*/
public $requestId;

/**
* Constructor to set initial or default values of member properties
*/
public function __construct($reason, $context)
{
parent::__construct($reason, $context);
}

/**
* Unbox response into this exception class
*/
public function unbox()
{
APIHelper::deserialize(self::getResponseBody(), $this, false);
}
}
39 changes: 39 additions & 0 deletions src/TwoFactorAuth/Exceptions/ForbiddenRequestException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/*
* BandwidthLib
*
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
*/

namespace BandwidthLib\TwoFactorAuth\Exceptions;

use BandwidthLib\APIHelper;

/**
* @todo Write general description for this model
*/
class ForbiddenRequestException extends \BandwidthLib\APIException
{
/**
* The message containing the reason behind the request being forbidden
* @maps Message
* @var string|null $message public property
*/
public $message;

/**
* Constructor to set initial or default values of member properties
*/
public function __construct($reason, $context)
{
parent::__construct($reason, $context);
}

/**
* Unbox response into this exception class
*/
public function unbox()
{
APIHelper::deserialize(self::getResponseBody(), $this, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
/**
* @todo Write general description for this model
*/
class InvalidRequestException extends \BandwidthLib\APIException
class UnauthorizedRequestException extends \BandwidthLib\APIException
{
/**
* An error message pertaining to what the issue could be
* @var string|null $result public property
* The message containing the reason behind the request being unauthorized
* @var string|null $message public property
*/
public $result;
public $message;

/**
* Constructor to set initial or default values of member properties
Expand Down
14 changes: 7 additions & 7 deletions src/TwoFactorAuth/TwoFactorAuthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public function __construct($config)
}


private $client;
private $mFA;

/**
* Provides access to API controller
* @return Controllers\APIController
* Provides access to MFA controller
* @return Controllers\MFAController
*/
public function getClient()
public function getMFA()
{
if ($this->client == null) {
$this->client = new Controllers\APIController($this->config);
if ($this->mFA == null) {
$this->mFA = new Controllers\MFAController($this->config);
}
return $this->client;
return $this->mFA;
}
}