From 3cceebe991beab005a4b4e442d2d3728c3aa8500 Mon Sep 17 00:00:00 2001 From: jmulford-bw Date: Thu, 4 Feb 2021 18:11:52 +0000 Subject: [PATCH 1/3] New deploy --- bandwidth/configuration.py | 2 +- bandwidth/messaging/models/__init__.py | 3 +- .../messaging/models/bandwidth_message.py | 12 ++++-- bandwidth/messaging/models/message_request.py | 14 +++++-- bandwidth/messaging/models/priority_enum.py | 26 ++++++++++++ .../twofactorauth/controllers/__init__.py | 2 +- .../{api_controller.py => mfa_controller.py} | 40 ++++++++++++++----- .../twofactorauth/exceptions/__init__.py | 4 +- .../error_with_request_exception.py | 38 ++++++++++++++++++ ...tion.py => forbidden_request_exception.py} | 8 ++-- .../unauthorized_request_exception.py | 37 +++++++++++++++++ .../twofactorauth/two_factor_auth_client.py | 6 +-- bandwidth/voice/__init__.py | 5 +-- setup.py | 4 +- 14 files changed, 170 insertions(+), 31 deletions(-) create mode 100644 bandwidth/messaging/models/priority_enum.py rename bandwidth/twofactorauth/controllers/{api_controller.py => mfa_controller.py} (72%) create mode 100644 bandwidth/twofactorauth/exceptions/error_with_request_exception.py rename bandwidth/twofactorauth/exceptions/{invalid_request_exception.py => forbidden_request_exception.py} (76%) create mode 100644 bandwidth/twofactorauth/exceptions/unauthorized_request_exception.py diff --git a/bandwidth/configuration.py b/bandwidth/configuration.py index 4c6253c1..a5071857 100644 --- a/bandwidth/configuration.py +++ b/bandwidth/configuration.py @@ -188,7 +188,7 @@ def create_http_client(self): Environment.PRODUCTION: { Server.DEFAULT: 'api.bandwidth.com', Server.MESSAGINGDEFAULT: 'https://messaging.bandwidth.com/api/v2', - Server.TWOFACTORAUTHDEFAULT: 'https://mfa.bandwidth.com/api/v1/', + Server.TWOFACTORAUTHDEFAULT: 'https://mfa.bandwidth.com/api/v1', Server.VOICEDEFAULT: 'https://voice.bandwidth.com', Server.WEBRTCDEFAULT: 'https://api.webrtc.bandwidth.com/v1' }, diff --git a/bandwidth/messaging/models/__init__.py b/bandwidth/messaging/models/__init__.py index bbc74dce..ef3a90d5 100644 --- a/bandwidth/messaging/models/__init__.py +++ b/bandwidth/messaging/models/__init__.py @@ -7,5 +7,6 @@ 'deferred_result', 'bandwidth_callback_message', 'bandwidth_message', - 'message_request', + 'message_request', + 'priority_enum', ] diff --git a/bandwidth/messaging/models/bandwidth_message.py b/bandwidth/messaging/models/bandwidth_message.py index 04755a20..c2829cf6 100644 --- a/bandwidth/messaging/models/bandwidth_message.py +++ b/bandwidth/messaging/models/bandwidth_message.py @@ -29,6 +29,7 @@ class BandwidthMessage(object): media (list of string): The list of media URLs sent in the message text (string): The contents of the message tag (string): The custom string set by the user + priority (string): The priority specified by the user """ @@ -44,7 +45,8 @@ class BandwidthMessage(object): "mfrom": 'from', "media": 'media', "text": 'text', - "tag": 'tag' + "tag": 'tag', + "priority": 'priority' } def __init__(self, @@ -58,7 +60,8 @@ def __init__(self, mfrom=None, media=None, text=None, - tag=None): + tag=None, + priority=None): """Constructor for the BandwidthMessage class""" # Initialize members of the class @@ -73,6 +76,7 @@ def __init__(self, self.media = media self.text = text self.tag = tag + self.priority = priority @classmethod def from_dictionary(cls, @@ -103,6 +107,7 @@ def from_dictionary(cls, media = dictionary.get('media') text = dictionary.get('text') tag = dictionary.get('tag') + priority = dictionary.get('priority') # Return an object of this model return cls(id, @@ -115,4 +120,5 @@ def from_dictionary(cls, mfrom, media, text, - tag) + tag, + priority) diff --git a/bandwidth/messaging/models/message_request.py b/bandwidth/messaging/models/message_request.py index 5fabd7be..89c4a5ec 100644 --- a/bandwidth/messaging/models/message_request.py +++ b/bandwidth/messaging/models/message_request.py @@ -26,6 +26,9 @@ class MessageRequest(object): as part of the message. tag (string): A custom string that will be included in callback events of the message. Max 1024 characters + priority (PriorityEnum): 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. """ @@ -36,7 +39,8 @@ class MessageRequest(object): "mfrom": 'from', "text": 'text', "media": 'media', - "tag": 'tag' + "tag": 'tag', + "priority": 'priority' } def __init__(self, @@ -45,7 +49,8 @@ def __init__(self, mfrom=None, text=None, media=None, - tag=None): + tag=None, + priority=None): """Constructor for the MessageRequest class""" # Initialize members of the class @@ -55,6 +60,7 @@ def __init__(self, self.text = text self.media = media self.tag = tag + self.priority = priority @classmethod def from_dictionary(cls, @@ -80,6 +86,7 @@ def from_dictionary(cls, text = dictionary.get('text') media = dictionary.get('media') tag = dictionary.get('tag') + priority = dictionary.get('priority') # Return an object of this model return cls(application_id, @@ -87,4 +94,5 @@ def from_dictionary(cls, mfrom, text, media, - tag) + tag, + priority) diff --git a/bandwidth/messaging/models/priority_enum.py b/bandwidth/messaging/models/priority_enum.py new file mode 100644 index 00000000..ebd96c8a --- /dev/null +++ b/bandwidth/messaging/models/priority_enum.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +bandwidth + +This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + + +class PriorityEnum(object): + + """Implementation of the 'Priority' enum. + + 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. + + Attributes: + DEFAULT: TODO: type description here. + HIGH: TODO: type description here. + + """ + + DEFAULT = 'default' + + HIGH = 'high' diff --git a/bandwidth/twofactorauth/controllers/__init__.py b/bandwidth/twofactorauth/controllers/__init__.py index c1660224..e7f5add1 100644 --- a/bandwidth/twofactorauth/controllers/__init__.py +++ b/bandwidth/twofactorauth/controllers/__init__.py @@ -1,4 +1,4 @@ __all__ = [ 'base_controller', - 'api_controller', + 'mfa_controller', ] diff --git a/bandwidth/twofactorauth/controllers/api_controller.py b/bandwidth/twofactorauth/controllers/mfa_controller.py similarity index 72% rename from bandwidth/twofactorauth/controllers/api_controller.py rename to bandwidth/twofactorauth/controllers/mfa_controller.py index 70e1d82e..648ab148 100644 --- a/bandwidth/twofactorauth/controllers/api_controller.py +++ b/bandwidth/twofactorauth/controllers/mfa_controller.py @@ -14,22 +14,24 @@ from bandwidth.twofactorauth.models.two_factor_voice_response import TwoFactorVoiceResponse from bandwidth.twofactorauth.models.two_factor_messaging_response import TwoFactorMessagingResponse from bandwidth.twofactorauth.models.two_factor_verify_code_response import TwoFactorVerifyCodeResponse -from bandwidth.twofactorauth.exceptions.invalid_request_exception import InvalidRequestException +from bandwidth.twofactorauth.exceptions.error_with_request_exception import ErrorWithRequestException +from bandwidth.twofactorauth.exceptions.unauthorized_request_exception import UnauthorizedRequestException +from bandwidth.twofactorauth.exceptions.forbidden_request_exception import ForbiddenRequestException -class APIController(BaseController): +class MFAController(BaseController): """A Controller to access Endpoints in the bandwidth API.""" def __init__(self, config, call_back=None): - super(APIController, self).__init__(config, call_back) + super(MFAController, self).__init__(config, call_back) def create_voice_two_factor(self, account_id, body): """Does a POST request to /accounts/{accountId}/code/voice. - Two-Factor authentication with Bandwidth Voice services + Allows a user to send a MFA code through a phone call Args: account_id (string): Bandwidth Account ID with Voice service @@ -71,7 +73,13 @@ def create_voice_two_factor(self, # Endpoint and global error handling using HTTP status codes. if _response.status_code == 400: - raise InvalidRequestException('client request error', _response) + raise ErrorWithRequestException('If there is any issue with values passed in by the user', _response) + elif _response.status_code == 401: + raise UnauthorizedRequestException('Authentication is either incorrect or not present', _response) + elif _response.status_code == 403: + raise ForbiddenRequestException('The user is not authorized to access this resource', _response) + elif _response.status_code == 500: + raise ErrorWithRequestException('An internal server error occurred', _response) self.validate_response(_response) decoded = APIHelper.json_deserialize(_response.text, TwoFactorVoiceResponse.from_dictionary) @@ -83,7 +91,7 @@ def create_messaging_two_factor(self, body): """Does a POST request to /accounts/{accountId}/code/messaging. - Two-Factor authentication with Bandwidth messaging services + Allows a user to send a MFA code through a text message (SMS) Args: account_id (string): Bandwidth Account ID with Messaging service @@ -125,7 +133,13 @@ def create_messaging_two_factor(self, # Endpoint and global error handling using HTTP status codes. if _response.status_code == 400: - raise InvalidRequestException('client request error', _response) + raise ErrorWithRequestException('If there is any issue with values passed in by the user', _response) + elif _response.status_code == 401: + raise UnauthorizedRequestException('Authentication is either incorrect or not present', _response) + elif _response.status_code == 403: + raise ForbiddenRequestException('The user is not authorized to access this resource', _response) + elif _response.status_code == 500: + raise ErrorWithRequestException('An internal server error occurred', _response) self.validate_response(_response) decoded = APIHelper.json_deserialize(_response.text, TwoFactorMessagingResponse.from_dictionary) @@ -137,7 +151,7 @@ def create_verify_two_factor(self, body): """Does a POST request to /accounts/{accountId}/code/verify. - Verify a previously sent two-factor authentication code + Allows a user to verify an MFA code Args: account_id (string): Bandwidth Account ID with Two-Factor enabled @@ -178,7 +192,15 @@ def create_verify_two_factor(self, # Endpoint and global error handling using HTTP status codes. if _response.status_code == 400: - raise InvalidRequestException('client request error', _response) + raise ErrorWithRequestException('If there is any issue with values passed in by the user', _response) + elif _response.status_code == 401: + raise UnauthorizedRequestException('Authentication is either incorrect or not present', _response) + elif _response.status_code == 403: + raise ForbiddenRequestException('The user is not authorized to access this resource', _response) + elif _response.status_code == 429: + raise ErrorWithRequestException('The user has made too many bad requests and is temporarily locked out', _response) + elif _response.status_code == 500: + raise ErrorWithRequestException('An internal server error occurred', _response) self.validate_response(_response) decoded = APIHelper.json_deserialize(_response.text, TwoFactorVerifyCodeResponse.from_dictionary) diff --git a/bandwidth/twofactorauth/exceptions/__init__.py b/bandwidth/twofactorauth/exceptions/__init__.py index 62a035cd..1b04875f 100644 --- a/bandwidth/twofactorauth/exceptions/__init__.py +++ b/bandwidth/twofactorauth/exceptions/__init__.py @@ -1,3 +1,5 @@ __all__ = [ - 'invalid_request_exception', + 'error_with_request_exception', + 'unauthorized_request_exception', + 'forbidden_request_exception', ] diff --git a/bandwidth/twofactorauth/exceptions/error_with_request_exception.py b/bandwidth/twofactorauth/exceptions/error_with_request_exception.py new file mode 100644 index 00000000..3b606065 --- /dev/null +++ b/bandwidth/twofactorauth/exceptions/error_with_request_exception.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +""" +bandwidth + +This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from bandwidth.api_helper import APIHelper +import bandwidth.exceptions.api_exception + + +class ErrorWithRequestException(bandwidth.exceptions.api_exception.APIException): + def __init__(self, reason, response): + """Constructor for the ErrorWithRequestException class + + Args: + reason (string): The reason (or error message) for the Exception + to be raised. + response (HttpResponse): The HttpResponse of the API call. + + """ + super(ErrorWithRequestException, self).__init__(reason, response) + dictionary = APIHelper.json_deserialize(self.response.text) + if isinstance(dictionary, dict): + self.unbox(dictionary) + + def unbox(self, dictionary): + """Populates the properties of this object by extracting them from a dictionary. + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + """ + self.error = dictionary.get('error') + self.request_id = dictionary.get('requestId') diff --git a/bandwidth/twofactorauth/exceptions/invalid_request_exception.py b/bandwidth/twofactorauth/exceptions/forbidden_request_exception.py similarity index 76% rename from bandwidth/twofactorauth/exceptions/invalid_request_exception.py rename to bandwidth/twofactorauth/exceptions/forbidden_request_exception.py index 9c91cb66..41e5f82e 100644 --- a/bandwidth/twofactorauth/exceptions/invalid_request_exception.py +++ b/bandwidth/twofactorauth/exceptions/forbidden_request_exception.py @@ -10,9 +10,9 @@ import bandwidth.exceptions.api_exception -class InvalidRequestException(bandwidth.exceptions.api_exception.APIException): +class ForbiddenRequestException(bandwidth.exceptions.api_exception.APIException): def __init__(self, reason, response): - """Constructor for the InvalidRequestException class + """Constructor for the ForbiddenRequestException class Args: reason (string): The reason (or error message) for the Exception @@ -20,7 +20,7 @@ def __init__(self, reason, response): response (HttpResponse): The HttpResponse of the API call. """ - super(InvalidRequestException, self).__init__(reason, response) + super(ForbiddenRequestException, self).__init__(reason, response) dictionary = APIHelper.json_deserialize(self.response.text) if isinstance(dictionary, dict): self.unbox(dictionary) @@ -34,4 +34,4 @@ def unbox(self, dictionary): MUST match property names in the API description. """ - self.result = dictionary.get('result') + self.message = dictionary.get('Message') diff --git a/bandwidth/twofactorauth/exceptions/unauthorized_request_exception.py b/bandwidth/twofactorauth/exceptions/unauthorized_request_exception.py new file mode 100644 index 00000000..d9d8cd11 --- /dev/null +++ b/bandwidth/twofactorauth/exceptions/unauthorized_request_exception.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +""" +bandwidth + +This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from bandwidth.api_helper import APIHelper +import bandwidth.exceptions.api_exception + + +class UnauthorizedRequestException(bandwidth.exceptions.api_exception.APIException): + def __init__(self, reason, response): + """Constructor for the UnauthorizedRequestException class + + Args: + reason (string): The reason (or error message) for the Exception + to be raised. + response (HttpResponse): The HttpResponse of the API call. + + """ + super(UnauthorizedRequestException, self).__init__(reason, response) + dictionary = APIHelper.json_deserialize(self.response.text) + if isinstance(dictionary, dict): + self.unbox(dictionary) + + def unbox(self, dictionary): + """Populates the properties of this object by extracting them from a dictionary. + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + """ + self.message = dictionary.get('message') diff --git a/bandwidth/twofactorauth/two_factor_auth_client.py b/bandwidth/twofactorauth/two_factor_auth_client.py index 8da2ce1d..f8503d84 100644 --- a/bandwidth/twofactorauth/two_factor_auth_client.py +++ b/bandwidth/twofactorauth/two_factor_auth_client.py @@ -9,14 +9,14 @@ from bandwidth.decorators import lazy_property from bandwidth.configuration import Configuration from bandwidth.configuration import Environment -from bandwidth.twofactorauth.controllers.api_controller import APIController +from bandwidth.twofactorauth.controllers.mfa_controller import MFAController class TwoFactorAuthClient(object): @lazy_property - def client(self): - return APIController(self.config) + def mfa(self): + return MFAController(self.config) def __init__(self, timeout=60, max_retries=3, backoff_factor=0, environment=Environment.PRODUCTION, diff --git a/bandwidth/voice/__init__.py b/bandwidth/voice/__init__.py index 843fbc5d..f7f51aa9 100644 --- a/bandwidth/voice/__init__.py +++ b/bandwidth/voice/__init__.py @@ -1,7 +1,6 @@ -__all__ = [ - 'bxml', +__all__ = [ 'controllers', 'exceptions', 'models', - 'voice_client', + 'voice_client', ] diff --git a/setup.py b/setup.py index cea39701..a86f39ab 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='bandwidth-sdk', - version='8.0.0', + version='1.0.0', description='Bandwidth\'s set of APIs', long_description=long_description, long_description_content_type="text/markdown", @@ -28,4 +28,4 @@ 'enum34>=1.1.6', 'lxml>=4.3.4' ] -) +) \ No newline at end of file From f8d1490898c795fe4b2f529f8b11416fd422c30a Mon Sep 17 00:00:00 2001 From: Jacob Mulford <39915377+jmulford-bw@users.noreply.github.com> Date: Thu, 4 Feb 2021 13:20:38 -0500 Subject: [PATCH 2/3] Update setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index a86f39ab..f4168dc6 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='bandwidth-sdk', - version='1.0.0', + version='9.0.0', description='Bandwidth\'s set of APIs', long_description=long_description, long_description_content_type="text/markdown", @@ -28,4 +28,4 @@ 'enum34>=1.1.6', 'lxml>=4.3.4' ] -) \ No newline at end of file +) From 0ca9cbebc375cb26d5edfbcdf44fc1cdf8dd7011 Mon Sep 17 00:00:00 2001 From: Jacob Mulford <39915377+jmulford-bw@users.noreply.github.com> Date: Thu, 4 Feb 2021 13:20:52 -0500 Subject: [PATCH 3/3] Update __init__.py --- bandwidth/voice/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bandwidth/voice/__init__.py b/bandwidth/voice/__init__.py index f7f51aa9..843fbc5d 100644 --- a/bandwidth/voice/__init__.py +++ b/bandwidth/voice/__init__.py @@ -1,6 +1,7 @@ -__all__ = [ +__all__ = [ + 'bxml', 'controllers', 'exceptions', 'models', - 'voice_client', + 'voice_client', ]