13
13
from bandwidth .messaging .controllers .base_controller import BaseController
14
14
from bandwidth .http .auth .messaging_basic_auth import MessagingBasicAuth
15
15
from bandwidth .messaging .models .media import Media
16
+ from bandwidth .messaging .models .bandwidth_messages_list import BandwidthMessagesList
16
17
from bandwidth .messaging .models .bandwidth_message import BandwidthMessage
17
18
from bandwidth .messaging .exceptions .messaging_exception import MessagingException
18
19
@@ -32,9 +33,9 @@ def list_media(self,
32
33
listMedia
33
34
34
35
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 .
38
39
39
40
Returns:
40
41
ApiResponse: An object with the response value as well as other
@@ -96,8 +97,8 @@ def get_media(self,
96
97
getMedia
97
98
98
99
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
101
102
102
103
Returns:
103
104
ApiResponse: An object with the response value as well as other
@@ -158,13 +159,15 @@ def upload_media(self,
158
159
uploadMedia
159
160
160
161
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
164
165
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.
168
171
169
172
Returns:
170
173
ApiResponse: An object with the response value as well as other
@@ -233,8 +236,8 @@ def delete_media(self,
233
236
deleteMedia
234
237
235
238
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
238
241
239
242
Returns:
240
243
ApiResponse: An object with the response value as well as other
@@ -281,16 +284,121 @@ def delete_media(self,
281
284
# Return appropriate type
282
285
return ApiResponse (_response )
283
286
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
+
284
392
def create_message (self ,
285
393
user_id ,
286
- body = None ):
394
+ body ):
287
395
"""Does a POST request to /users/{userId}/messages.
288
396
289
397
createMessage
290
398
291
399
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.
294
402
295
403
Returns:
296
404
ApiResponse: An object with the response value as well as other
0 commit comments