@@ -12,8 +12,9 @@ def initialize(config, http_call_back: nil)
1212 end
1313
1414 # listMedia
15- # @param [String] user_id Required parameter: Example:
16- # @param [String] continuation_token Optional parameter: Example:
15+ # @param [String] user_id Required parameter: User's account ID
16+ # @param [String] continuation_token Optional parameter: Continuation token
17+ # used to retrieve subsequent media.
1718 # @return [List of Media] response from the API call
1819 def list_media ( user_id ,
1920 continuation_token : nil )
@@ -83,8 +84,8 @@ def list_media(user_id,
8384 end
8485
8586 # getMedia
86- # @param [String] user_id Required parameter: Example:
87- # @param [String] media_id Required parameter: Example:
87+ # @param [String] user_id Required parameter: User's account ID
88+ # @param [String] media_id Required parameter: Media ID to retrieve
8889 # @return [Binary] response from the API call
8990 def get_media ( user_id ,
9091 media_id )
@@ -146,13 +147,17 @@ def get_media(user_id,
146147 end
147148
148149 # uploadMedia
149- # @param [String] user_id Required parameter: Example:
150- # @param [String] media_id Required parameter: Example:
151- # @param [Long] content_length Required parameter: Example:
150+ # @param [String] user_id Required parameter: User's account ID
151+ # @param [String] media_id Required parameter: The user supplied custom
152+ # media ID
153+ # @param [Long] content_length Required parameter: The size of the
154+ # entity-body
152155 # @param [File | UploadIO] body Required parameter: Example:
153- # @param [String] content_type Optional parameter:
154- # Example:application/octet-stream
155- # @param [String] cache_control Optional parameter: Example:
156+ # @param [String] content_type Optional parameter: The media type of the
157+ # entity-body
158+ # @param [String] cache_control Optional parameter: General-header field is
159+ # used to specify directives that MUST be obeyed by all caching mechanisms
160+ # along the request/response chain.
156161 # @return [void] response from the API call
157162 def upload_media ( user_id ,
158163 media_id ,
@@ -234,8 +239,8 @@ def upload_media(user_id,
234239 end
235240
236241 # deleteMedia
237- # @param [String] user_id Required parameter: Example:
238- # @param [String] media_id Required parameter: Example:
242+ # @param [String] user_id Required parameter: User's account ID
243+ # @param [String] media_id Required parameter: The media ID to delete
239244 # @return [void] response from the API call
240245 def delete_media ( user_id ,
241246 media_id )
@@ -294,12 +299,122 @@ def delete_media(user_id,
294299 ApiResponse . new ( _response )
295300 end
296301
302+ # getMessages
303+ # @param [String] user_id Required parameter: User's account ID
304+ # @param [String] message_id Optional parameter: The ID of the message to
305+ # search for. Special characters need to be encoded using URL encoding
306+ # @param [String] source_tn Optional parameter: The phone number that sent
307+ # the message
308+ # @param [String] destination_tn Optional parameter: The phone number that
309+ # received the message
310+ # @param [String] message_status Optional parameter: The status of the
311+ # message. One of RECEIVED, QUEUED, SENDING, SENT, FAILED, DELIVERED,
312+ # DLR_EXPIRED
313+ # @param [Integer] error_code Optional parameter: The error code of the
314+ # message
315+ # @param [String] from_date_time Optional parameter: The start of the date
316+ # range to search in ISO 8601 format. Uses the message receive time. The
317+ # date range to search in is currently 14 days.
318+ # @param [String] to_date_time Optional parameter: The end of the date range
319+ # to search in ISO 8601 format. Uses the message receive time. The date
320+ # range to search in is currently 14 days.
321+ # @param [String] page_token Optional parameter: A base64 encoded value used
322+ # for pagination of results
323+ # @param [Integer] limit Optional parameter: The maximum records requested
324+ # in search result. Default 100. The sum of limit and after cannot be more
325+ # than 10000
326+ # @return [BandwidthMessagesList] response from the API call
327+ def get_messages ( user_id ,
328+ message_id : nil ,
329+ source_tn : nil ,
330+ destination_tn : nil ,
331+ message_status : nil ,
332+ error_code : nil ,
333+ from_date_time : nil ,
334+ to_date_time : nil ,
335+ page_token : nil ,
336+ limit : nil )
337+ # Prepare query url.
338+ _query_builder = config . get_base_uri ( Server ::MESSAGINGDEFAULT )
339+ _query_builder << '/users/{userId}/messages'
340+ _query_builder = APIHelper . append_url_with_template_parameters (
341+ _query_builder ,
342+ 'userId' => { 'value' => user_id , 'encode' => false }
343+ )
344+ _query_builder = APIHelper . append_url_with_query_parameters (
345+ _query_builder ,
346+ 'messageId' => message_id ,
347+ 'sourceTn' => source_tn ,
348+ 'destinationTn' => destination_tn ,
349+ 'messageStatus' => message_status ,
350+ 'errorCode' => error_code ,
351+ 'fromDateTime' => from_date_time ,
352+ 'toDateTime' => to_date_time ,
353+ 'pageToken' => page_token ,
354+ 'limit' => limit
355+ )
356+ _query_url = APIHelper . clean_url _query_builder
357+
358+ # Prepare headers.
359+ _headers = {
360+ 'accept' => 'application/json'
361+ }
362+
363+ # Prepare and execute HttpRequest.
364+ _request = config . http_client . get (
365+ _query_url ,
366+ headers : _headers
367+ )
368+ MessagingBasicAuth . apply ( config , _request )
369+ _response = execute_request ( _request )
370+
371+ # Validate response against endpoint and global error codes.
372+ if _response . status_code == 400
373+ raise MessagingException . new (
374+ '400 Request is malformed or invalid' ,
375+ _response
376+ )
377+ elsif _response . status_code == 401
378+ raise MessagingException . new (
379+ '401 The specified user does not have access to the account' ,
380+ _response
381+ )
382+ elsif _response . status_code == 403
383+ raise MessagingException . new (
384+ '403 The user does not have access to this API' ,
385+ _response
386+ )
387+ elsif _response . status_code == 404
388+ raise MessagingException . new (
389+ '404 Path not found' ,
390+ _response
391+ )
392+ elsif _response . status_code == 415
393+ raise MessagingException . new (
394+ '415 The content-type of the request is incorrect' ,
395+ _response
396+ )
397+ elsif _response . status_code == 429
398+ raise MessagingException . new (
399+ '429 The rate limit has been reached' ,
400+ _response
401+ )
402+ end
403+ validate_response ( _response )
404+
405+ # Return appropriate response type.
406+ decoded = APIHelper . json_deserialize ( _response . raw_body )
407+ ApiResponse . new (
408+ _response , data : BandwidthMessagesList . from_hash ( decoded )
409+ )
410+ end
411+
297412 # createMessage
298- # @param [String] user_id Required parameter: Example:
299- # @param [MessageRequest] body Optional parameter: Example:
413+ # @param [String] user_id Required parameter: User's account ID
414+ # @param [MessageRequest] body Required parameter: Example:
300415 # @return [BandwidthMessage] response from the API call
301416 def create_message ( user_id ,
302- body : nil )
417+ body )
303418 # Prepare query url.
304419 _query_builder = config . get_base_uri ( Server ::MESSAGINGDEFAULT )
305420 _query_builder << '/users/{userId}/messages'
0 commit comments