Skip to content

Commit 9d34f78

Browse files
authored
Merge pull request #11 from Bandwidth/release/2021-01-27-20-39-24
New deploy
2 parents 9256912 + bd0ccda commit 9d34f78

15 files changed

+600
-138
lines changed

bandwidth/messaging/controllers/api_controller.py

Lines changed: 124 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from bandwidth.messaging.controllers.base_controller import BaseController
1414
from bandwidth.http.auth.messaging_basic_auth import MessagingBasicAuth
1515
from bandwidth.messaging.models.media import Media
16+
from bandwidth.messaging.models.bandwidth_messages_list import BandwidthMessagesList
1617
from bandwidth.messaging.models.bandwidth_message import BandwidthMessage
1718
from bandwidth.messaging.exceptions.messaging_exception import MessagingException
1819

@@ -32,9 +33,9 @@ def list_media(self,
3233
listMedia
3334
3435
Args:
35-
user_id (string): TODO: type description here.
36-
continuation_token (string, optional): TODO: type description
37-
here.
36+
user_id (string): User's account ID
37+
continuation_token (string, optional): Continuation token used to
38+
retrieve subsequent media.
3839
3940
Returns:
4041
ApiResponse: An object with the response value as well as other
@@ -96,8 +97,8 @@ def get_media(self,
9697
getMedia
9798
9899
Args:
99-
user_id (string): TODO: type description here.
100-
media_id (string): TODO: type description here.
100+
user_id (string): User's account ID
101+
media_id (string): Media ID to retrieve
101102
102103
Returns:
103104
ApiResponse: An object with the response value as well as other
@@ -158,13 +159,15 @@ def upload_media(self,
158159
uploadMedia
159160
160161
Args:
161-
user_id (string): TODO: type description here.
162-
media_id (string): TODO: type description here.
163-
content_length (long|int): TODO: type description here.
162+
user_id (string): User's account ID
163+
media_id (string): The user supplied custom media ID
164+
content_length (long|int): The size of the entity-body
164165
body (typing.BinaryIO): TODO: type description here.
165-
content_type (string, optional): TODO: type description here.
166-
Example: application/octet-stream
167-
cache_control (string, optional): TODO: type description here.
166+
content_type (string, optional): The media type of the
167+
entity-body
168+
cache_control (string, optional): General-header field is used to
169+
specify directives that MUST be obeyed by all caching
170+
mechanisms along the request/response chain.
168171
169172
Returns:
170173
ApiResponse: An object with the response value as well as other
@@ -233,8 +236,8 @@ def delete_media(self,
233236
deleteMedia
234237
235238
Args:
236-
user_id (string): TODO: type description here.
237-
media_id (string): TODO: type description here.
239+
user_id (string): User's account ID
240+
media_id (string): The media ID to delete
238241
239242
Returns:
240243
ApiResponse: An object with the response value as well as other
@@ -281,16 +284,121 @@ def delete_media(self,
281284
# Return appropriate type
282285
return ApiResponse(_response)
283286

287+
def get_messages(self,
288+
user_id,
289+
message_id=None,
290+
source_tn=None,
291+
destination_tn=None,
292+
message_status=None,
293+
error_code=None,
294+
from_date_time=None,
295+
to_date_time=None,
296+
page_token=None,
297+
limit=None):
298+
"""Does a GET request to /users/{userId}/messages.
299+
300+
getMessages
301+
302+
Args:
303+
user_id (string): User's account ID
304+
message_id (string, optional): The ID of the message to search
305+
for. Special characters need to be encoded using URL encoding
306+
source_tn (string, optional): The phone number that sent the
307+
message
308+
destination_tn (string, optional): The phone number that received
309+
the message
310+
message_status (string, optional): The status of the message. One
311+
of RECEIVED, QUEUED, SENDING, SENT, FAILED, DELIVERED,
312+
DLR_EXPIRED
313+
error_code (int, optional): The error code of the message
314+
from_date_time (string, optional): The start of the date range to
315+
search in ISO 8601 format. Uses the message receive time. The
316+
date range to search in is currently 14 days.
317+
to_date_time (string, optional): The end of the date range to
318+
search in ISO 8601 format. Uses the message receive time. The
319+
date range to search in is currently 14 days.
320+
page_token (string, optional): A base64 encoded value used for
321+
pagination of results
322+
limit (int, optional): The maximum records requested in search
323+
result. Default 100. The sum of limit and after cannot be more
324+
than 10000
325+
326+
Returns:
327+
ApiResponse: An object with the response value as well as other
328+
useful information such as status codes and headers.
329+
successful operation
330+
331+
Raises:
332+
APIException: When an error occurs while fetching the data from
333+
the remote API. This exception includes the HTTP Response
334+
code, an error message, and the HTTP body that was received in
335+
the request.
336+
337+
"""
338+
339+
# Prepare query URL
340+
_url_path = '/users/{userId}/messages'
341+
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
342+
'userId': {'value': user_id, 'encode': False}
343+
})
344+
_query_builder = self.config.get_base_uri(Server.MESSAGINGDEFAULT)
345+
_query_builder += _url_path
346+
_query_parameters = {
347+
'messageId': message_id,
348+
'sourceTn': source_tn,
349+
'destinationTn': destination_tn,
350+
'messageStatus': message_status,
351+
'errorCode': error_code,
352+
'fromDateTime': from_date_time,
353+
'toDateTime': to_date_time,
354+
'pageToken': page_token,
355+
'limit': limit
356+
}
357+
_query_builder = APIHelper.append_url_with_query_parameters(
358+
_query_builder,
359+
_query_parameters
360+
)
361+
_query_url = APIHelper.clean_url(_query_builder)
362+
363+
# Prepare headers
364+
_headers = {
365+
'accept': 'application/json'
366+
}
367+
368+
# Prepare and execute request
369+
_request = self.config.http_client.get(_query_url, headers=_headers)
370+
MessagingBasicAuth.apply(self.config, _request)
371+
_response = self.execute_request(_request)
372+
373+
# Endpoint and global error handling using HTTP status codes.
374+
if _response.status_code == 400:
375+
raise MessagingException('400 Request is malformed or invalid', _response)
376+
elif _response.status_code == 401:
377+
raise MessagingException('401 The specified user does not have access to the account', _response)
378+
elif _response.status_code == 403:
379+
raise MessagingException('403 The user does not have access to this API', _response)
380+
elif _response.status_code == 404:
381+
raise MessagingException('404 Path not found', _response)
382+
elif _response.status_code == 415:
383+
raise MessagingException('415 The content-type of the request is incorrect', _response)
384+
elif _response.status_code == 429:
385+
raise MessagingException('429 The rate limit has been reached', _response)
386+
self.validate_response(_response)
387+
388+
decoded = APIHelper.json_deserialize(_response.text, BandwidthMessagesList.from_dictionary)
389+
_result = ApiResponse(_response, body=decoded)
390+
return _result
391+
284392
def create_message(self,
285393
user_id,
286-
body=None):
394+
body):
287395
"""Does a POST request to /users/{userId}/messages.
288396
289397
createMessage
290398
291399
Args:
292-
user_id (string): TODO: type description here.
293-
body (MessageRequest, optional): TODO: type description here.
400+
user_id (string): User's account ID
401+
body (MessageRequest): TODO: type description here.
294402
295403
Returns:
296404
ApiResponse: An object with the response value as well as other

bandwidth/messaging/models/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
__all__ = [
2+
'bandwidth_messages_list',
3+
'bandwidth_message_item',
4+
'page_info',
25
'media',
36
'tag',
47
'deferred_result',

bandwidth/messaging/models/bandwidth_message.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@ class BandwidthMessage(object):
1414
TODO: type model description here.
1515
1616
Attributes:
17-
id (string): TODO: type description here.
18-
owner (string): TODO: type description here.
19-
application_id (string): TODO: type description here.
20-
time (string): TODO: type description here.
21-
segment_count (int): TODO: type description here.
22-
direction (string): TODO: type description here.
23-
to (list of string): TODO: type description here.
24-
mfrom (string): TODO: type description here.
25-
media (list of string): TODO: type description here.
26-
text (string): TODO: type description here.
27-
tag (string): TODO: type description here.
17+
id (string): The id of the message
18+
owner (string): The Bandwidth phone number associated with the
19+
message
20+
application_id (string): The application ID associated with the
21+
message
22+
time (string): The datetime stamp of the message in ISO 8601
23+
segment_count (int): The number of segments the original message from
24+
the user is broken into before sending over to carrier networks
25+
direction (string): The direction of the message relative to
26+
Bandwidth. Can be in or out
27+
to (list of string): The phone number recipients of the message
28+
mfrom (string): The phone number the message was sent from
29+
media (list of string): The list of media URLs sent in the message
30+
text (string): The contents of the message
31+
tag (string): The custom string set by the user
2832
2933
"""
3034

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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 BandwidthMessageItem(object):
11+
12+
"""Implementation of the 'BandwidthMessageItem' model.
13+
14+
TODO: type model description here.
15+
16+
Attributes:
17+
message_id (string): The message id
18+
account_id (string): The account id of the message
19+
source_tn (string): The source phone number of the message
20+
destination_tn (string): The recipient phone number of the message
21+
message_status (string): The status of the message
22+
message_direction (string): The direction of the message relative to
23+
Bandwidth. INBOUND or OUTBOUND
24+
message_type (string): The type of message. sms or mms
25+
segment_count (int): The number of segments the message was sent as
26+
error_code (int): The numeric error code of the message
27+
receive_time (string): The ISO 8601 datetime of the message
28+
carrier_name (string): The name of the carrier. Not currently
29+
supported for MMS, coming soon
30+
31+
"""
32+
33+
# Create a mapping from Model property names to API property names
34+
_names = {
35+
"message_id": 'messageId',
36+
"account_id": 'accountId',
37+
"source_tn": 'sourceTn',
38+
"destination_tn": 'destinationTn',
39+
"message_status": 'messageStatus',
40+
"message_direction": 'messageDirection',
41+
"message_type": 'messageType',
42+
"segment_count": 'segmentCount',
43+
"error_code": 'errorCode',
44+
"receive_time": 'receiveTime',
45+
"carrier_name": 'carrierName'
46+
}
47+
48+
def __init__(self,
49+
message_id=None,
50+
account_id=None,
51+
source_tn=None,
52+
destination_tn=None,
53+
message_status=None,
54+
message_direction=None,
55+
message_type=None,
56+
segment_count=None,
57+
error_code=None,
58+
receive_time=None,
59+
carrier_name=None):
60+
"""Constructor for the BandwidthMessageItem class"""
61+
62+
# Initialize members of the class
63+
self.message_id = message_id
64+
self.account_id = account_id
65+
self.source_tn = source_tn
66+
self.destination_tn = destination_tn
67+
self.message_status = message_status
68+
self.message_direction = message_direction
69+
self.message_type = message_type
70+
self.segment_count = segment_count
71+
self.error_code = error_code
72+
self.receive_time = receive_time
73+
self.carrier_name = carrier_name
74+
75+
@classmethod
76+
def from_dictionary(cls,
77+
dictionary):
78+
"""Creates an instance of this model from a dictionary
79+
80+
Args:
81+
dictionary (dictionary): A dictionary representation of the object
82+
as obtained from the deserialization of the server's response. The
83+
keys MUST match property names in the API description.
84+
85+
Returns:
86+
object: An instance of this structure class.
87+
88+
"""
89+
if dictionary is None:
90+
return None
91+
92+
# Extract variables from the dictionary
93+
message_id = dictionary.get('messageId')
94+
account_id = dictionary.get('accountId')
95+
source_tn = dictionary.get('sourceTn')
96+
destination_tn = dictionary.get('destinationTn')
97+
message_status = dictionary.get('messageStatus')
98+
message_direction = dictionary.get('messageDirection')
99+
message_type = dictionary.get('messageType')
100+
segment_count = dictionary.get('segmentCount')
101+
error_code = dictionary.get('errorCode')
102+
receive_time = dictionary.get('receiveTime')
103+
carrier_name = dictionary.get('carrierName')
104+
105+
# Return an object of this model
106+
return cls(message_id,
107+
account_id,
108+
source_tn,
109+
destination_tn,
110+
message_status,
111+
message_direction,
112+
message_type,
113+
segment_count,
114+
error_code,
115+
receive_time,
116+
carrier_name)

0 commit comments

Comments
 (0)