Skip to content

Commit f0d8d57

Browse files
authored
Merge pull request #13 from Bandwidth/release/2021-02-04-18-11-52
MFA error update and message priority
2 parents 9d34f78 + 0ca9cbe commit f0d8d57

File tree

13 files changed

+167
-27
lines changed

13 files changed

+167
-27
lines changed

bandwidth/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def create_http_client(self):
188188
Environment.PRODUCTION: {
189189
Server.DEFAULT: 'api.bandwidth.com',
190190
Server.MESSAGINGDEFAULT: 'https://messaging.bandwidth.com/api/v2',
191-
Server.TWOFACTORAUTHDEFAULT: 'https://mfa.bandwidth.com/api/v1/',
191+
Server.TWOFACTORAUTHDEFAULT: 'https://mfa.bandwidth.com/api/v1',
192192
Server.VOICEDEFAULT: 'https://voice.bandwidth.com',
193193
Server.WEBRTCDEFAULT: 'https://api.webrtc.bandwidth.com/v1'
194194
},

bandwidth/messaging/models/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
'deferred_result',
88
'bandwidth_callback_message',
99
'bandwidth_message',
10-
'message_request',
10+
'message_request',
11+
'priority_enum',
1112
]

bandwidth/messaging/models/bandwidth_message.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class BandwidthMessage(object):
2929
media (list of string): The list of media URLs sent in the message
3030
text (string): The contents of the message
3131
tag (string): The custom string set by the user
32+
priority (string): The priority specified by the user
3233
3334
"""
3435

@@ -44,7 +45,8 @@ class BandwidthMessage(object):
4445
"mfrom": 'from',
4546
"media": 'media',
4647
"text": 'text',
47-
"tag": 'tag'
48+
"tag": 'tag',
49+
"priority": 'priority'
4850
}
4951

5052
def __init__(self,
@@ -58,7 +60,8 @@ def __init__(self,
5860
mfrom=None,
5961
media=None,
6062
text=None,
61-
tag=None):
63+
tag=None,
64+
priority=None):
6265
"""Constructor for the BandwidthMessage class"""
6366

6467
# Initialize members of the class
@@ -73,6 +76,7 @@ def __init__(self,
7376
self.media = media
7477
self.text = text
7578
self.tag = tag
79+
self.priority = priority
7680

7781
@classmethod
7882
def from_dictionary(cls,
@@ -103,6 +107,7 @@ def from_dictionary(cls,
103107
media = dictionary.get('media')
104108
text = dictionary.get('text')
105109
tag = dictionary.get('tag')
110+
priority = dictionary.get('priority')
106111

107112
# Return an object of this model
108113
return cls(id,
@@ -115,4 +120,5 @@ def from_dictionary(cls,
115120
mfrom,
116121
media,
117122
text,
118-
tag)
123+
tag,
124+
priority)

bandwidth/messaging/models/message_request.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class MessageRequest(object):
2626
as part of the message.
2727
tag (string): A custom string that will be included in callback events
2828
of the message. Max 1024 characters
29+
priority (PriorityEnum): The message's priority, currently for
30+
toll-free or short code SMS only. Messages with a priority value
31+
of `"high"` are given preference over your other traffic.
2932
3033
"""
3134

@@ -36,7 +39,8 @@ class MessageRequest(object):
3639
"mfrom": 'from',
3740
"text": 'text',
3841
"media": 'media',
39-
"tag": 'tag'
42+
"tag": 'tag',
43+
"priority": 'priority'
4044
}
4145

4246
def __init__(self,
@@ -45,7 +49,8 @@ def __init__(self,
4549
mfrom=None,
4650
text=None,
4751
media=None,
48-
tag=None):
52+
tag=None,
53+
priority=None):
4954
"""Constructor for the MessageRequest class"""
5055

5156
# Initialize members of the class
@@ -55,6 +60,7 @@ def __init__(self,
5560
self.text = text
5661
self.media = media
5762
self.tag = tag
63+
self.priority = priority
5864

5965
@classmethod
6066
def from_dictionary(cls,
@@ -80,11 +86,13 @@ def from_dictionary(cls,
8086
text = dictionary.get('text')
8187
media = dictionary.get('media')
8288
tag = dictionary.get('tag')
89+
priority = dictionary.get('priority')
8390

8491
# Return an object of this model
8592
return cls(application_id,
8693
to,
8794
mfrom,
8895
text,
8996
media,
90-
tag)
97+
tag,
98+
priority)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
bandwidth
5+
6+
This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
7+
"""
8+
9+
10+
class PriorityEnum(object):
11+
12+
"""Implementation of the 'Priority' enum.
13+
14+
The message's priority, currently for toll-free or short code SMS only.
15+
Messages with a priority value of `"high"` are given preference over your
16+
other traffic.
17+
18+
Attributes:
19+
DEFAULT: TODO: type description here.
20+
HIGH: TODO: type description here.
21+
22+
"""
23+
24+
DEFAULT = 'default'
25+
26+
HIGH = 'high'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
__all__ = [
22
'base_controller',
3-
'api_controller',
3+
'mfa_controller',
44
]

bandwidth/twofactorauth/controllers/api_controller.py renamed to bandwidth/twofactorauth/controllers/mfa_controller.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@
1414
from bandwidth.twofactorauth.models.two_factor_voice_response import TwoFactorVoiceResponse
1515
from bandwidth.twofactorauth.models.two_factor_messaging_response import TwoFactorMessagingResponse
1616
from bandwidth.twofactorauth.models.two_factor_verify_code_response import TwoFactorVerifyCodeResponse
17-
from bandwidth.twofactorauth.exceptions.invalid_request_exception import InvalidRequestException
17+
from bandwidth.twofactorauth.exceptions.error_with_request_exception import ErrorWithRequestException
18+
from bandwidth.twofactorauth.exceptions.unauthorized_request_exception import UnauthorizedRequestException
19+
from bandwidth.twofactorauth.exceptions.forbidden_request_exception import ForbiddenRequestException
1820

1921

20-
class APIController(BaseController):
22+
class MFAController(BaseController):
2123

2224
"""A Controller to access Endpoints in the bandwidth API."""
2325

2426
def __init__(self, config, call_back=None):
25-
super(APIController, self).__init__(config, call_back)
27+
super(MFAController, self).__init__(config, call_back)
2628

2729
def create_voice_two_factor(self,
2830
account_id,
2931
body):
3032
"""Does a POST request to /accounts/{accountId}/code/voice.
3133
32-
Two-Factor authentication with Bandwidth Voice services
34+
Allows a user to send a MFA code through a phone call
3335
3436
Args:
3537
account_id (string): Bandwidth Account ID with Voice service
@@ -71,7 +73,13 @@ def create_voice_two_factor(self,
7173

7274
# Endpoint and global error handling using HTTP status codes.
7375
if _response.status_code == 400:
74-
raise InvalidRequestException('client request error', _response)
76+
raise ErrorWithRequestException('If there is any issue with values passed in by the user', _response)
77+
elif _response.status_code == 401:
78+
raise UnauthorizedRequestException('Authentication is either incorrect or not present', _response)
79+
elif _response.status_code == 403:
80+
raise ForbiddenRequestException('The user is not authorized to access this resource', _response)
81+
elif _response.status_code == 500:
82+
raise ErrorWithRequestException('An internal server error occurred', _response)
7583
self.validate_response(_response)
7684

7785
decoded = APIHelper.json_deserialize(_response.text, TwoFactorVoiceResponse.from_dictionary)
@@ -83,7 +91,7 @@ def create_messaging_two_factor(self,
8391
body):
8492
"""Does a POST request to /accounts/{accountId}/code/messaging.
8593
86-
Two-Factor authentication with Bandwidth messaging services
94+
Allows a user to send a MFA code through a text message (SMS)
8795
8896
Args:
8997
account_id (string): Bandwidth Account ID with Messaging service
@@ -125,7 +133,13 @@ def create_messaging_two_factor(self,
125133

126134
# Endpoint and global error handling using HTTP status codes.
127135
if _response.status_code == 400:
128-
raise InvalidRequestException('client request error', _response)
136+
raise ErrorWithRequestException('If there is any issue with values passed in by the user', _response)
137+
elif _response.status_code == 401:
138+
raise UnauthorizedRequestException('Authentication is either incorrect or not present', _response)
139+
elif _response.status_code == 403:
140+
raise ForbiddenRequestException('The user is not authorized to access this resource', _response)
141+
elif _response.status_code == 500:
142+
raise ErrorWithRequestException('An internal server error occurred', _response)
129143
self.validate_response(_response)
130144

131145
decoded = APIHelper.json_deserialize(_response.text, TwoFactorMessagingResponse.from_dictionary)
@@ -137,7 +151,7 @@ def create_verify_two_factor(self,
137151
body):
138152
"""Does a POST request to /accounts/{accountId}/code/verify.
139153
140-
Verify a previously sent two-factor authentication code
154+
Allows a user to verify an MFA code
141155
142156
Args:
143157
account_id (string): Bandwidth Account ID with Two-Factor enabled
@@ -178,7 +192,15 @@ def create_verify_two_factor(self,
178192

179193
# Endpoint and global error handling using HTTP status codes.
180194
if _response.status_code == 400:
181-
raise InvalidRequestException('client request error', _response)
195+
raise ErrorWithRequestException('If there is any issue with values passed in by the user', _response)
196+
elif _response.status_code == 401:
197+
raise UnauthorizedRequestException('Authentication is either incorrect or not present', _response)
198+
elif _response.status_code == 403:
199+
raise ForbiddenRequestException('The user is not authorized to access this resource', _response)
200+
elif _response.status_code == 429:
201+
raise ErrorWithRequestException('The user has made too many bad requests and is temporarily locked out', _response)
202+
elif _response.status_code == 500:
203+
raise ErrorWithRequestException('An internal server error occurred', _response)
182204
self.validate_response(_response)
183205

184206
decoded = APIHelper.json_deserialize(_response.text, TwoFactorVerifyCodeResponse.from_dictionary)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
__all__ = [
2-
'invalid_request_exception',
2+
'error_with_request_exception',
3+
'unauthorized_request_exception',
4+
'forbidden_request_exception',
35
]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
bandwidth
5+
6+
This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
7+
"""
8+
9+
from bandwidth.api_helper import APIHelper
10+
import bandwidth.exceptions.api_exception
11+
12+
13+
class ErrorWithRequestException(bandwidth.exceptions.api_exception.APIException):
14+
def __init__(self, reason, response):
15+
"""Constructor for the ErrorWithRequestException class
16+
17+
Args:
18+
reason (string): The reason (or error message) for the Exception
19+
to be raised.
20+
response (HttpResponse): The HttpResponse of the API call.
21+
22+
"""
23+
super(ErrorWithRequestException, self).__init__(reason, response)
24+
dictionary = APIHelper.json_deserialize(self.response.text)
25+
if isinstance(dictionary, dict):
26+
self.unbox(dictionary)
27+
28+
def unbox(self, dictionary):
29+
"""Populates the properties of this object by extracting them from a dictionary.
30+
31+
Args:
32+
dictionary (dictionary): A dictionary representation of the object as
33+
obtained from the deserialization of the server's response. The keys
34+
MUST match property names in the API description.
35+
36+
"""
37+
self.error = dictionary.get('error')
38+
self.request_id = dictionary.get('requestId')

bandwidth/twofactorauth/exceptions/invalid_request_exception.py renamed to bandwidth/twofactorauth/exceptions/forbidden_request_exception.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
import bandwidth.exceptions.api_exception
1111

1212

13-
class InvalidRequestException(bandwidth.exceptions.api_exception.APIException):
13+
class ForbiddenRequestException(bandwidth.exceptions.api_exception.APIException):
1414
def __init__(self, reason, response):
15-
"""Constructor for the InvalidRequestException class
15+
"""Constructor for the ForbiddenRequestException class
1616
1717
Args:
1818
reason (string): The reason (or error message) for the Exception
1919
to be raised.
2020
response (HttpResponse): The HttpResponse of the API call.
2121
2222
"""
23-
super(InvalidRequestException, self).__init__(reason, response)
23+
super(ForbiddenRequestException, self).__init__(reason, response)
2424
dictionary = APIHelper.json_deserialize(self.response.text)
2525
if isinstance(dictionary, dict):
2626
self.unbox(dictionary)
@@ -34,4 +34,4 @@ def unbox(self, dictionary):
3434
MUST match property names in the API description.
3535
3636
"""
37-
self.result = dictionary.get('result')
37+
self.message = dictionary.get('Message')

0 commit comments

Comments
 (0)