From a3ed7385ab61756c96ed6fbdaab42374003ea41c Mon Sep 17 00:00:00 2001 From: Harmon Date: Wed, 7 Apr 2021 13:52:43 -0500 Subject: [PATCH] Update and improve documentation for API.create_friendship Automatically use docstring for documentation Improve method and documentation order Remove id parameter from documentation --- docs/api.rst | 14 ++------------ tweepy/api.py | 31 +++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 90025ea..7b53af7 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -135,6 +135,8 @@ Follow, search, and get users .. automethod:: API.get_user +.. automethod:: API.create_friendship + Direct Message Methods ---------------------- @@ -195,18 +197,6 @@ Direct Message Methods Friendship Methods ------------------ -.. method:: API.create_friendship(id/screen_name/user_id, [follow]) - - Create a new friendship with the specified user (aka follow). - - :param id: |uid| - :param screen_name: |screen_name| - :param user_id: |user_id| - :param follow: Enable notifications for the target user in addition to - becoming friends. - :rtype: :class:`User` object - - .. method:: API.destroy_friendship(id/screen_name/user_id) Destroy a friendship with the specified user (aka unfollow). diff --git a/tweepy/api.py b/tweepy/api.py index 9a7e36e..4006beb 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -1676,6 +1676,27 @@ class API: ), **kwargs ) + @payload('user') + def create_friendship(self, **kwargs): + """create_friendship(*, screen_name, user_id, follow) + + Create a new friendship with the specified user (aka follow). + + :param screen_name: |screen_name| + :param user_id: |user_id| + :param follow: Enable notifications for the target user in addition to + becoming friends. + + :rtype: :class:`User` object + + :reference: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create + """ + return self.request( + 'POST', 'friendships/create', endpoint_parameters=( + 'screen_name', 'user_id', 'follow' + ), **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 @@ -1905,16 +1926,6 @@ class API: ), id=id, **kwargs ) - @payload('user') - def create_friendship(self, **kwargs): - """ :reference: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create - """ - return self.request( - 'POST', 'friendships/create', endpoint_parameters=( - 'screen_name', 'user_id', 'follow' - ), **kwargs - ) - @payload('user') def destroy_friendship(self, **kwargs): """ :reference: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-destroy -- 2.25.1