Skip to content

Commit d68569d

Browse files
MFA error update and message priority (#20)
* New deploy * Update APIController.php Co-authored-by: jmulford-bw <[email protected]>
1 parent 4329b75 commit d68569d

File tree

9 files changed

+216
-21
lines changed

9 files changed

+216
-21
lines changed

src/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function getBaseUri($server = Servers::DEFAULT_)
247247
Environments::PRODUCTION => array(
248248
Servers::DEFAULT_ => 'api.bandwidth.com',
249249
Servers::MESSAGINGDEFAULT => 'https://messaging.bandwidth.com/api/v2',
250-
Servers::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1/',
250+
Servers::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1',
251251
Servers::VOICEDEFAULT => 'https://voice.bandwidth.com',
252252
Servers::WEBRTCDEFAULT => 'https://api.webrtc.bandwidth.com/v1',
253253
),

src/Messaging/Models/BandwidthMessage.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,18 @@ class BandwidthMessage implements \JsonSerializable
7979
*/
8080
public $tag;
8181

82+
/**
83+
* The priority specified by the user
84+
* @var string|null $priority public property
85+
*/
86+
public $priority;
87+
8288
/**
8389
* Constructor to set initial or default values of member properties
8490
*/
8591
public function __construct()
8692
{
87-
if (11 == func_num_args()) {
93+
if (12 == func_num_args()) {
8894
$this->id = func_get_arg(0);
8995
$this->owner = func_get_arg(1);
9096
$this->applicationId = func_get_arg(2);
@@ -96,6 +102,7 @@ public function __construct()
96102
$this->media = func_get_arg(8);
97103
$this->text = func_get_arg(9);
98104
$this->tag = func_get_arg(10);
105+
$this->priority = func_get_arg(11);
99106
}
100107
}
101108

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

122130
return array_filter($json);
123131
}

src/Messaging/Models/MessageRequest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,26 @@ class MessageRequest implements \JsonSerializable
5252
*/
5353
public $tag;
5454

55+
/**
56+
* The message's priority, currently for toll-free or short code SMS only. Messages with a priority
57+
* value of `"high"` are given preference over your other traffic.
58+
* @var string|null $priority public property
59+
*/
60+
public $priority;
61+
5562
/**
5663
* Constructor to set initial or default values of member properties
5764
*/
5865
public function __construct()
5966
{
60-
if (6 == func_num_args()) {
67+
if (7 == func_num_args()) {
6168
$this->applicationId = func_get_arg(0);
6269
$this->to = func_get_arg(1);
6370
$this->from = func_get_arg(2);
6471
$this->text = func_get_arg(3);
6572
$this->media = func_get_arg(4);
6673
$this->tag = func_get_arg(5);
74+
$this->priority = func_get_arg(6);
6775
}
6876
}
6977

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

8493
return array_filter($json);
8594
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/*
3+
* BandwidthLib
4+
*
5+
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
6+
*/
7+
8+
namespace BandwidthLib\Messaging\Models;
9+
10+
/**
11+
* The message's priority, currently for toll-free or short code SMS only. Messages with a priority
12+
* value of `"high"` are given preference over your other traffic.
13+
*/
14+
class PriorityEnum
15+
{
16+
/**
17+
* TODO: Write general description for this element
18+
*/
19+
const DEFAULT_ = "default";
20+
21+
/**
22+
* TODO: Write general description for this element
23+
*/
24+
const HIGH = "high";
25+
}

src/TwoFactorAuth/Controllers/APIController.php renamed to src/TwoFactorAuth/Controllers/MFAController.php

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
/**
2424
* @todo Add a general description for this controller.
2525
*/
26-
class APIController extends BaseController
26+
class MFAController extends BaseController
2727
{
2828
public function __construct($config, $httpCallBack = null)
2929
{
3030
parent::__construct($config, $httpCallBack);
3131
}
3232

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

9090
//Error handling using HTTP status codes
9191
if ($response->code == 400) {
92-
throw new Exceptions\InvalidRequestException('client request error', $_httpContext);
92+
throw new Exceptions\ErrorWithRequestException(
93+
'If there is any issue with values passed in by the user',
94+
$_httpContext
95+
);
96+
}
97+
98+
if ($response->code == 401) {
99+
throw new Exceptions\UnauthorizedRequestException(
100+
'Authentication is either incorrect or not present',
101+
$_httpContext
102+
);
103+
}
104+
105+
if ($response->code == 403) {
106+
throw new Exceptions\ForbiddenRequestException(
107+
'The user is not authorized to access this resource',
108+
$_httpContext
109+
);
110+
}
111+
112+
if ($response->code == 500) {
113+
throw new Exceptions\ErrorWithRequestException('An internal server error occurred', $_httpContext);
93114
}
94115

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

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

162183
//Error handling using HTTP status codes
163184
if ($response->code == 400) {
164-
throw new Exceptions\InvalidRequestException('client request error', $_httpContext);
185+
throw new Exceptions\ErrorWithRequestException(
186+
'If there is any issue with values passed in by the user',
187+
$_httpContext
188+
);
189+
}
190+
191+
if ($response->code == 401) {
192+
throw new Exceptions\UnauthorizedRequestException(
193+
'Authentication is either incorrect or not present',
194+
$_httpContext
195+
);
196+
}
197+
198+
if ($response->code == 403) {
199+
throw new Exceptions\ForbiddenRequestException(
200+
'The user is not authorized to access this resource',
201+
$_httpContext
202+
);
203+
}
204+
205+
if ($response->code == 500) {
206+
throw new Exceptions\ErrorWithRequestException('An internal server error occurred', $_httpContext);
165207
}
166208

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

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

234276
//Error handling using HTTP status codes
235277
if ($response->code == 400) {
236-
throw new Exceptions\InvalidRequestException('client request error', $_httpContext);
278+
throw new Exceptions\ErrorWithRequestException(
279+
'If there is any issue with values passed in by the user',
280+
$_httpContext
281+
);
282+
}
283+
284+
if ($response->code == 401) {
285+
throw new Exceptions\UnauthorizedRequestException(
286+
'Authentication is either incorrect or not present',
287+
$_httpContext
288+
);
289+
}
290+
291+
if ($response->code == 403) {
292+
throw new Exceptions\ForbiddenRequestException(
293+
'The user is not authorized to access this resource',
294+
$_httpContext
295+
);
296+
}
297+
298+
if ($response->code == 429) {
299+
throw new Exceptions\ErrorWithRequestException(
300+
'The user has made too many bad requests and is temporarily locked out',
301+
$_httpContext
302+
);
303+
}
304+
305+
if ($response->code == 500) {
306+
throw new Exceptions\ErrorWithRequestException('An internal server error occurred', $_httpContext);
237307
}
238308

239309
//handle errors defined at the API level
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/*
3+
* BandwidthLib
4+
*
5+
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
6+
*/
7+
8+
namespace BandwidthLib\TwoFactorAuth\Exceptions;
9+
10+
use BandwidthLib\APIHelper;
11+
12+
/**
13+
* @todo Write general description for this model
14+
*/
15+
class ErrorWithRequestException extends \BandwidthLib\APIException
16+
{
17+
/**
18+
* An error message pertaining to what the issue could be
19+
* @var string|null $error public property
20+
*/
21+
public $error;
22+
23+
/**
24+
* The associated requestId from AWS
25+
* @var string|null $requestId public property
26+
*/
27+
public $requestId;
28+
29+
/**
30+
* Constructor to set initial or default values of member properties
31+
*/
32+
public function __construct($reason, $context)
33+
{
34+
parent::__construct($reason, $context);
35+
}
36+
37+
/**
38+
* Unbox response into this exception class
39+
*/
40+
public function unbox()
41+
{
42+
APIHelper::deserialize(self::getResponseBody(), $this, false);
43+
}
44+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/*
3+
* BandwidthLib
4+
*
5+
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
6+
*/
7+
8+
namespace BandwidthLib\TwoFactorAuth\Exceptions;
9+
10+
use BandwidthLib\APIHelper;
11+
12+
/**
13+
* @todo Write general description for this model
14+
*/
15+
class ForbiddenRequestException extends \BandwidthLib\APIException
16+
{
17+
/**
18+
* The message containing the reason behind the request being forbidden
19+
* @maps Message
20+
* @var string|null $message public property
21+
*/
22+
public $message;
23+
24+
/**
25+
* Constructor to set initial or default values of member properties
26+
*/
27+
public function __construct($reason, $context)
28+
{
29+
parent::__construct($reason, $context);
30+
}
31+
32+
/**
33+
* Unbox response into this exception class
34+
*/
35+
public function unbox()
36+
{
37+
APIHelper::deserialize(self::getResponseBody(), $this, false);
38+
}
39+
}

src/TwoFactorAuth/Exceptions/InvalidRequestException.php renamed to src/TwoFactorAuth/Exceptions/UnauthorizedRequestException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
/**
1313
* @todo Write general description for this model
1414
*/
15-
class InvalidRequestException extends \BandwidthLib\APIException
15+
class UnauthorizedRequestException extends \BandwidthLib\APIException
1616
{
1717
/**
18-
* An error message pertaining to what the issue could be
19-
* @var string|null $result public property
18+
* The message containing the reason behind the request being unauthorized
19+
* @var string|null $message public property
2020
*/
21-
public $result;
21+
public $message;
2222

2323
/**
2424
* Constructor to set initial or default values of member properties

src/TwoFactorAuth/TwoFactorAuthClient.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ public function __construct($config)
2121
}
2222

2323

24-
private $client;
24+
private $mFA;
2525

2626
/**
27-
* Provides access to API controller
28-
* @return Controllers\APIController
27+
* Provides access to MFA controller
28+
* @return Controllers\MFAController
2929
*/
30-
public function getClient()
30+
public function getMFA()
3131
{
32-
if ($this->client == null) {
33-
$this->client = new Controllers\APIController($this->config);
32+
if ($this->mFA == null) {
33+
$this->mFA = new Controllers\MFAController($this->config);
3434
}
35-
return $this->client;
35+
return $this->mFA;
3636
}
3737
}

0 commit comments

Comments
 (0)