From: Harmon Date: Sun, 11 Apr 2021 18:42:49 +0000 (-0500) Subject: Update and improve documentation for API.chunked_upload_append X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8169dc54ae6d41578ede979027f344ab47faba0d;p=tweepy.git Update and improve documentation for API.chunked_upload_append Automatically use docstring for documentation Improve method and documentation order --- diff --git a/docs/api.rst b/docs/api.rst index 69be3f7..257a97f 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -219,6 +219,8 @@ Upload media .. automethod:: API.chunked_upload +.. automethod:: API.chunked_upload_append + Account Methods --------------- @@ -449,19 +451,6 @@ Media methods :rtype: :class:`Media` object -.. method:: API.chunked_upload_append(media_id, media, segment_index) - - Use this endpoint to upload a chunk (consecutive byte range) of the media - file. - - :param media_id: The ``media_id`` returned from the initialization. - :param media: The raw binary file content being uploaded. It must be <= 5 - MB. - :param segment_index: An ordered index of file chunk. It must be between - 0-999 inclusive. The first segment has index 0, second - segment has index 1, and so on. - - .. method:: API.chunked_upload_finalize(media_id) Use this endpoint after the entire media file is uploaded via appending. diff --git a/tweepy/api.py b/tweepy/api.py index 3f1f525..4f7ba89 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -2488,6 +2488,32 @@ class API: return media + def chunked_upload_append(self, media_id, media, segment_index, **kwargs): + """chunked_upload_append(media_id, media, segment_index) + + Use this endpoint to upload a chunk (consecutive byte range) of the + media file. + + :param media_id: The ``media_id`` returned from the initialization. + :param media: The raw binary file content being uploaded. It must be <= + 5 MB. + :param segment_index: An ordered index of file chunk. It must be + between 0-999 inclusive. The first segment has index 0, second + segment has index 1, and so on. + + :reference https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload-append + """ + post_data = { + 'command': 'APPEND', + 'media_id': media_id, + 'segment_index': segment_index + } + files = {'media': media} + return self.request( + 'POST', 'media/upload', post_data=post_data, files=files, + upload_api=True, **kwargs + ) + @payload('media') def chunked_upload_init(self, total_bytes, media_type, *, media_category=None, additional_owners=None, @@ -2511,20 +2537,6 @@ class API: upload_api=True, **kwargs ) - def chunked_upload_append(self, media_id, media, segment_index, **kwargs): - """ :reference https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload-append - """ - post_data = { - 'command': 'APPEND', - 'media_id': media_id, - 'segment_index': segment_index - } - files = {'media': media} - return self.request( - 'POST', 'media/upload', post_data=post_data, files=files, - upload_api=True, **kwargs - ) - @payload('media') def chunked_upload_finalize(self, media_id, **kwargs): """ :reference https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload-finalize