Skip to content

Commit

Permalink
Merge pull request #11 from Bandwidth/release/2021-01-27-20-39-24
Browse files Browse the repository at this point in the history
New deploy
  • Loading branch information
jmulford-bw authored Feb 1, 2021
2 parents 9256912 + bd0ccda commit 9d34f78
Show file tree
Hide file tree
Showing 15 changed files with 600 additions and 138 deletions.
140 changes: 124 additions & 16 deletions bandwidth/messaging/controllers/api_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from bandwidth.messaging.controllers.base_controller import BaseController
from bandwidth.http.auth.messaging_basic_auth import MessagingBasicAuth
from bandwidth.messaging.models.media import Media
from bandwidth.messaging.models.bandwidth_messages_list import BandwidthMessagesList
from bandwidth.messaging.models.bandwidth_message import BandwidthMessage
from bandwidth.messaging.exceptions.messaging_exception import MessagingException

Expand All @@ -32,9 +33,9 @@ def list_media(self,
listMedia
Args:
user_id (string): TODO: type description here.
continuation_token (string, optional): TODO: type description
here.
user_id (string): User's account ID
continuation_token (string, optional): Continuation token used to
retrieve subsequent media.
Returns:
ApiResponse: An object with the response value as well as other
Expand Down Expand Up @@ -96,8 +97,8 @@ def get_media(self,
getMedia
Args:
user_id (string): TODO: type description here.
media_id (string): TODO: type description here.
user_id (string): User's account ID
media_id (string): Media ID to retrieve
Returns:
ApiResponse: An object with the response value as well as other
Expand Down Expand Up @@ -158,13 +159,15 @@ def upload_media(self,
uploadMedia
Args:
user_id (string): TODO: type description here.
media_id (string): TODO: type description here.
content_length (long|int): TODO: type description here.
user_id (string): User's account ID
media_id (string): The user supplied custom media ID
content_length (long|int): The size of the entity-body
body (typing.BinaryIO): TODO: type description here.
content_type (string, optional): TODO: type description here.
Example: application/octet-stream
cache_control (string, optional): TODO: type description here.
content_type (string, optional): The media type of the
entity-body
cache_control (string, optional): General-header field is used to
specify directives that MUST be obeyed by all caching
mechanisms along the request/response chain.
Returns:
ApiResponse: An object with the response value as well as other
Expand Down Expand Up @@ -233,8 +236,8 @@ def delete_media(self,
deleteMedia
Args:
user_id (string): TODO: type description here.
media_id (string): TODO: type description here.
user_id (string): User's account ID
media_id (string): The media ID to delete
Returns:
ApiResponse: An object with the response value as well as other
Expand Down Expand Up @@ -281,16 +284,121 @@ def delete_media(self,
# Return appropriate type
return ApiResponse(_response)

def get_messages(self,
user_id,
message_id=None,
source_tn=None,
destination_tn=None,
message_status=None,
error_code=None,
from_date_time=None,
to_date_time=None,
page_token=None,
limit=None):
"""Does a GET request to /users/{userId}/messages.
getMessages
Args:
user_id (string): User's account ID
message_id (string, optional): The ID of the message to search
for. Special characters need to be encoded using URL encoding
source_tn (string, optional): The phone number that sent the
message
destination_tn (string, optional): The phone number that received
the message
message_status (string, optional): The status of the message. One
of RECEIVED, QUEUED, SENDING, SENT, FAILED, DELIVERED,
DLR_EXPIRED
error_code (int, optional): The error code of the message
from_date_time (string, optional): The start of the date range to
search in ISO 8601 format. Uses the message receive time. The
date range to search in is currently 14 days.
to_date_time (string, optional): The end of the date range to
search in ISO 8601 format. Uses the message receive time. The
date range to search in is currently 14 days.
page_token (string, optional): A base64 encoded value used for
pagination of results
limit (int, optional): The maximum records requested in search
result. Default 100. The sum of limit and after cannot be more
than 10000
Returns:
ApiResponse: An object with the response value as well as other
useful information such as status codes and headers.
successful operation
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""

# Prepare query URL
_url_path = '/users/{userId}/messages'
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
'userId': {'value': user_id, 'encode': False}
})
_query_builder = self.config.get_base_uri(Server.MESSAGINGDEFAULT)
_query_builder += _url_path
_query_parameters = {
'messageId': message_id,
'sourceTn': source_tn,
'destinationTn': destination_tn,
'messageStatus': message_status,
'errorCode': error_code,
'fromDateTime': from_date_time,
'toDateTime': to_date_time,
'pageToken': page_token,
'limit': limit
}
_query_builder = APIHelper.append_url_with_query_parameters(
_query_builder,
_query_parameters
)
_query_url = APIHelper.clean_url(_query_builder)

# Prepare headers
_headers = {
'accept': 'application/json'
}

# Prepare and execute request
_request = self.config.http_client.get(_query_url, headers=_headers)
MessagingBasicAuth.apply(self.config, _request)
_response = self.execute_request(_request)

# Endpoint and global error handling using HTTP status codes.
if _response.status_code == 400:
raise MessagingException('400 Request is malformed or invalid', _response)
elif _response.status_code == 401:
raise MessagingException('401 The specified user does not have access to the account', _response)
elif _response.status_code == 403:
raise MessagingException('403 The user does not have access to this API', _response)
elif _response.status_code == 404:
raise MessagingException('404 Path not found', _response)
elif _response.status_code == 415:
raise MessagingException('415 The content-type of the request is incorrect', _response)
elif _response.status_code == 429:
raise MessagingException('429 The rate limit has been reached', _response)
self.validate_response(_response)

decoded = APIHelper.json_deserialize(_response.text, BandwidthMessagesList.from_dictionary)
_result = ApiResponse(_response, body=decoded)
return _result

def create_message(self,
user_id,
body=None):
body):
"""Does a POST request to /users/{userId}/messages.
createMessage
Args:
user_id (string): TODO: type description here.
body (MessageRequest, optional): TODO: type description here.
user_id (string): User's account ID
body (MessageRequest): TODO: type description here.
Returns:
ApiResponse: An object with the response value as well as other
Expand Down
3 changes: 3 additions & 0 deletions bandwidth/messaging/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
__all__ = [
'bandwidth_messages_list',
'bandwidth_message_item',
'page_info',
'media',
'tag',
'deferred_result',
Expand Down
26 changes: 15 additions & 11 deletions bandwidth/messaging/models/bandwidth_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ class BandwidthMessage(object):
TODO: type model description here.
Attributes:
id (string): TODO: type description here.
owner (string): TODO: type description here.
application_id (string): TODO: type description here.
time (string): TODO: type description here.
segment_count (int): TODO: type description here.
direction (string): TODO: type description here.
to (list of string): TODO: type description here.
mfrom (string): TODO: type description here.
media (list of string): TODO: type description here.
text (string): TODO: type description here.
tag (string): TODO: type description here.
id (string): The id of the message
owner (string): The Bandwidth phone number associated with the
message
application_id (string): The application ID associated with the
message
time (string): The datetime stamp of the message in ISO 8601
segment_count (int): The number of segments the original message from
the user is broken into before sending over to carrier networks
direction (string): The direction of the message relative to
Bandwidth. Can be in or out
to (list of string): The phone number recipients of the message
mfrom (string): The phone number the message was sent from
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
"""

Expand Down
116 changes: 116 additions & 0 deletions bandwidth/messaging/models/bandwidth_message_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# -*- coding: utf-8 -*-

"""
bandwidth
This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
"""


class BandwidthMessageItem(object):

"""Implementation of the 'BandwidthMessageItem' model.
TODO: type model description here.
Attributes:
message_id (string): The message id
account_id (string): The account id of the message
source_tn (string): The source phone number of the message
destination_tn (string): The recipient phone number of the message
message_status (string): The status of the message
message_direction (string): The direction of the message relative to
Bandwidth. INBOUND or OUTBOUND
message_type (string): The type of message. sms or mms
segment_count (int): The number of segments the message was sent as
error_code (int): The numeric error code of the message
receive_time (string): The ISO 8601 datetime of the message
carrier_name (string): The name of the carrier. Not currently
supported for MMS, coming soon
"""

# Create a mapping from Model property names to API property names
_names = {
"message_id": 'messageId',
"account_id": 'accountId',
"source_tn": 'sourceTn',
"destination_tn": 'destinationTn',
"message_status": 'messageStatus',
"message_direction": 'messageDirection',
"message_type": 'messageType',
"segment_count": 'segmentCount',
"error_code": 'errorCode',
"receive_time": 'receiveTime',
"carrier_name": 'carrierName'
}

def __init__(self,
message_id=None,
account_id=None,
source_tn=None,
destination_tn=None,
message_status=None,
message_direction=None,
message_type=None,
segment_count=None,
error_code=None,
receive_time=None,
carrier_name=None):
"""Constructor for the BandwidthMessageItem class"""

# Initialize members of the class
self.message_id = message_id
self.account_id = account_id
self.source_tn = source_tn
self.destination_tn = destination_tn
self.message_status = message_status
self.message_direction = message_direction
self.message_type = message_type
self.segment_count = segment_count
self.error_code = error_code
self.receive_time = receive_time
self.carrier_name = carrier_name

@classmethod
def from_dictionary(cls,
dictionary):
"""Creates an instance of this model 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.
Returns:
object: An instance of this structure class.
"""
if dictionary is None:
return None

# Extract variables from the dictionary
message_id = dictionary.get('messageId')
account_id = dictionary.get('accountId')
source_tn = dictionary.get('sourceTn')
destination_tn = dictionary.get('destinationTn')
message_status = dictionary.get('messageStatus')
message_direction = dictionary.get('messageDirection')
message_type = dictionary.get('messageType')
segment_count = dictionary.get('segmentCount')
error_code = dictionary.get('errorCode')
receive_time = dictionary.get('receiveTime')
carrier_name = dictionary.get('carrierName')

# Return an object of this model
return cls(message_id,
account_id,
source_tn,
destination_tn,
message_status,
message_direction,
message_type,
segment_count,
error_code,
receive_time,
carrier_name)
Loading

0 comments on commit 9d34f78

Please sign in to comment.