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 bandwidth/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand Down
3 changes: 2 additions & 1 deletion bandwidth/messaging/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
'deferred_result',
'bandwidth_callback_message',
'bandwidth_message',
'message_request',
'message_request',
'priority_enum',
]
12 changes: 9 additions & 3 deletions bandwidth/messaging/models/bandwidth_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""

Expand All @@ -44,7 +45,8 @@ class BandwidthMessage(object):
"mfrom": 'from',
"media": 'media',
"text": 'text',
"tag": 'tag'
"tag": 'tag',
"priority": 'priority'
}

def __init__(self,
Expand All @@ -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
Expand All @@ -73,6 +76,7 @@ def __init__(self,
self.media = media
self.text = text
self.tag = tag
self.priority = priority

@classmethod
def from_dictionary(cls,
Expand Down Expand Up @@ -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,
Expand All @@ -115,4 +120,5 @@ def from_dictionary(cls,
mfrom,
media,
text,
tag)
tag,
priority)
14 changes: 11 additions & 3 deletions bandwidth/messaging/models/message_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

"""

Expand All @@ -36,7 +39,8 @@ class MessageRequest(object):
"mfrom": 'from',
"text": 'text',
"media": 'media',
"tag": 'tag'
"tag": 'tag',
"priority": 'priority'
}

def __init__(self,
Expand All @@ -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
Expand All @@ -55,6 +60,7 @@ def __init__(self,
self.text = text
self.media = media
self.tag = tag
self.priority = priority

@classmethod
def from_dictionary(cls,
Expand All @@ -80,11 +86,13 @@ 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,
to,
mfrom,
text,
media,
tag)
tag,
priority)
26 changes: 26 additions & 0 deletions bandwidth/messaging/models/priority_enum.py
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion bandwidth/twofactorauth/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = [
'base_controller',
'api_controller',
'mfa_controller',
]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion bandwidth/twofactorauth/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__all__ = [
'invalid_request_exception',
'error_with_request_exception',
'unauthorized_request_exception',
'forbidden_request_exception',
]
Original file line number Diff line number Diff line change
@@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
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
to be raised.
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)
Expand All @@ -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')
Original file line number Diff line number Diff line change
@@ -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')
6 changes: 3 additions & 3 deletions bandwidth/twofactorauth/two_factor_auth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name='bandwidth-sdk',
version='8.0.0',
version='9.0.0',
description='Bandwidth\'s set of APIs',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down