From 8f4c992376ebc6008c1860a1b43881c0a705c08b Mon Sep 17 00:00:00 2001 From: Harmon Date: Sun, 11 Apr 2021 13:14:18 -0500 Subject: [PATCH] Update and improve documentation for API.create_media_metadata Automatically use docstring for documentation Improve method and documentation order Improve formatting --- docs/api.rst | 13 ++----------- tweepy/api.py | 36 +++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index cb5a9cc..8d79727 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -211,6 +211,8 @@ Upload media .. automethod:: API.get_media_upload_status +.. automethod:: API.create_media_metadata + Account Methods --------------- @@ -523,17 +525,6 @@ Media methods :rtype: :class:`Media` object -.. method:: API.create_media_metadata(media_id, alt_text) - - This endpoint can be used to provide additional information about the - uploaded media_id. This feature is currently only supported for images and - GIFs. Call this endpoint to attach additional metadata such as image alt - text. - - :param media_id: The ID of the media to add alt text to. - :param alt_text: The alt text to add to the image. - - :mod:`tweepy.error` --- Exceptions ================================== diff --git a/tweepy/api.py b/tweepy/api.py index 18570f3..38728a8 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -2322,6 +2322,29 @@ class API: ), command='STATUS', media_id=media_id, upload_api=True, **kwargs ) + def create_media_metadata(self, media_id, alt_text, **kwargs): + """create_media_metadata(media_id, alt_text) + + This endpoint can be used to provide additional information about the + uploaded ``media_id``. This feature is currently only supported for + images and GIFs. Call this endpoint to attach additional metadata such + as image alt text. + + :param media_id: The ID of the media to add alt text to. + :param alt_text: The alt text to add to the image. + + :reference: https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-metadata-create + """ + json_payload = { + 'media_id': media_id, + 'alt_text': {'text': alt_text} + } + + return self.request( + 'POST', 'media/metadata/create', json_payload=json_payload, + upload_api=True, **kwargs + ) + def media_upload(self, filename, *, file=None, chunked=False, media_category=None, additional_owners=None, **kwargs): """ :reference: https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/overview @@ -2466,19 +2489,6 @@ class API: upload_api=True, **kwargs ) - def create_media_metadata(self, media_id, alt_text, **kwargs): - """ :reference: https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-metadata-create - """ - json_payload = { - 'media_id': media_id, - 'alt_text': {'text': alt_text} - } - - return self.request( - 'POST', 'media/metadata/create', json_payload=json_payload, - upload_api=True, **kwargs - ) - @payload('json') def rate_limit_status(self, **kwargs): """ :reference: https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/rate-limit-status/api-reference/get-application-rate_limit_status -- 2.25.1