From c06baa13b30fc5ce058940e681305f6c03dc0048 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 17:11:45 +0100 Subject: Update verify_credentials docs --- mastodon/Mastodon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 641b742..1c7b2ee 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -510,7 +510,7 @@ class Mastodon: """ Fetch authenticated user's account information. - Returns a user dict. + Returns a user dict (Starting from 2.1.0, with an additional "source" field). """ return self.__api_request('GET', '/api/v1/accounts/verify_credentials') -- cgit v1.2.3 From 75aebac744717216118afcdb89c96cfe8856e9ef Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 17:17:42 +0100 Subject: Add custom_emojis --- mastodon/Mastodon.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 1c7b2ee..8130b2c 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -713,6 +713,19 @@ class Mastodon: params = self.__generate_params(locals()) return self.__api_request('GET', '/api/v1/domain_blocks', params) + ### + # Reading data: Emoji + ### + @api_version("2.1.0") + def custom_emojis(self): + """ + Fetch the list of custom emoji the instance has installed. + + Returns a list of emoji dicts. + + """ + return self.__api_request('GET', '/api/v1/custom_emojis') + ### # Writing data: Statuses ### -- cgit v1.2.3 From 7ed769b37a9fc27e36023370ad265380cbc50c52 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 17:26:44 +0100 Subject: Add list streaming --- mastodon/Mastodon.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 8130b2c..d8410b3 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -1165,25 +1165,21 @@ class Mastodon: def stream_user(self, listener, async=False): """ Streams events that are relevant to the authorized user, i.e. home - timeline and notifications. 'listener' should be a subclass of - StreamListener which will receive callbacks for incoming events. + timeline and notifications. """ return self.__stream('/api/v1/streaming/user', listener, async=async) @api_version("1.1.0") def stream_public(self, listener, async=False): """ - Streams public events. 'listener' should be a subclass of StreamListener - which will receive callbacks for incoming events. + Streams public events. """ return self.__stream('/api/v1/streaming/public', listener, async=async) @api_version("1.1.0") def stream_local(self, listener, async=False): """ - Streams local events. 'listener' should be a subclass of StreamListener - which will receive callbacks for incoming events. - + Streams local public events. """ return self.__stream('/api/v1/streaming/public/local', listener, async=async) @@ -1191,13 +1187,21 @@ class Mastodon: def stream_hashtag(self, tag, listener, async=False): """ Stream for all public statuses for the hashtag 'tag' seen by the connected - instance. 'listener' should be a subclass of StreamListener which will receive - callbacks for incoming events. + instance. """ if tag.startswith("#"): raise MastodonIllegalArgumentError("Tag parameter should omit leading #") return self.__stream("/api/v1/streaming/hashtag?tag={}".format(tag), listener) + @api_version("2.1.0") + def stream_list(self, id, listener, async=False): + """ + Stream events for the current user, restricted to accounts on the given + list. + """ + id = self.__unpack_id(id) + return self.__stream("/api/v1/streaming/list?list={}".format(id), listener) + ### # Internal helpers, dragons probably ### -- cgit v1.2.3 From 48d54effc8444b7f119ded786a6e750accf22027 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 17:47:50 +0100 Subject: Add lists endpoint --- mastodon/Mastodon.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index d8410b3..e8d68a8 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -606,6 +606,18 @@ class Mastodon: params = self.__generate_params(locals()) return self.__api_request('GET', '/api/v1/search', params) + ### + # Reading data: Lists + ### + @api_version("2.1.0") + def lists(self): + """ + Fetch a list of all the Lists by the logged-in user. + + Returns a list of list dicts. + """ + return self.__api_request('GET', '/api/v1/lists') + ### # Reading data: Mutes and Blocks ### -- cgit v1.2.3 From d7d8f153a31b76493daf68a44e01d4c4e11b180d Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 17:55:14 +0100 Subject: Update docs for search function --- mastodon/Mastodon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index e8d68a8..2e3935c 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -601,7 +601,7 @@ class Mastodon: Fetch matching hashtags, accounts and statuses. Will search federated instances if resolve is True. - Returns a dict of lists. + Returns a search result dict. """ params = self.__generate_params(locals()) return self.__api_request('GET', '/api/v1/search', params) -- cgit v1.2.3 From 7d2f2441269fda71b72322825b5813a2aec4c7bd Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 18:40:17 +0100 Subject: Add internal links in docs --- mastodon/Mastodon.py | 209 +++++++++++++++++++++++++-------------------------- 1 file changed, 104 insertions(+), 105 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 2e3935c..af450ec 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -72,16 +72,16 @@ class Mastodon: def create_app(client_name, scopes=['read', 'write', 'follow'], redirect_uris=None, website=None, to_file=None, api_base_url=__DEFAULT_BASE_URL, request_timeout=__DEFAULT_TIMEOUT): """ - Create a new app with given client_name and scopes (read, write, follow) + Create a new app with given `client_name` and `scopes` (read, write, follow) - Specify redirect_uris if you want users to be redirected to a certain page after authenticating. - Specify to_file to persist your apps info to a file so you can use them in the constructor. - Specify api_base_url if you want to register an app on an instance different from the flagship one. + Specify `redirect_uris` if you want users to be redirected to a certain page after authenticating. + Specify `to_file` to persist your apps info to a file so you can use them in the constructor. + Specify `api_base_url` if you want to register an app on an instance different from the flagship one. Presently, app registration is open by default, but this is not guaranteed to be the case for all future mastodon instances or even the flagship instance in the future. - Returns client_id and client_secret. + Returns `client_id` and `client_secret`, both as strings. """ api_base_url = Mastodon.__protocolize(api_base_url) @@ -118,13 +118,13 @@ class Mastodon: ratelimit_method="wait", ratelimit_pacefactor=1.1, request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None): """ - Create a new API wrapper instance based on the given client_secret and client_id. If you - give a client_id and it is not a file, you must also give a secret. + Create a new API wrapper instance based on the given `client_secret` and `client_id`. If you + give a `client_id` and it is not a file, you must also give a secret. - You can also specify an access_token, directly or as a file (as written by log_in). + You can also specify an `access_token`, directly or as a file (as written by `log_in()`_). - Mastodon.py can try to respect rate limits in several ways, controlled by ratelimit_method. - "throw" makes functions throw a MastodonRatelimitError when the rate + Mastodon.py can try to respect rate limits in several ways, controlled by `ratelimit_method`. + "throw" makes functions throw a `MastodonRatelimitError` when the rate limit is hit. "wait" mode will, once the limit is hit, wait and retry the request as soon as the rate limit resets, until it succeeds. "pace" works like throw, but tries to wait in between calls so that the limit is generally not hit (How hard it tries to not hit the rate @@ -132,15 +132,15 @@ class Mastodon: even in "wait" and "pace" mode, requests can still fail due to network or other problems! Also note that "pace" and "wait" are NOT thread safe. - Specify api_base_url if you wish to talk to an instance other than the flagship one. - If a file is given as client_id, read client ID and secret from that file. + Specify `api_base_url` if you wish to talk to an instance other than the flagship one. + If a file is given as `client_id`, client ID and secret are read from that file. By default, a timeout of 300 seconds is used for all requests. If you wish to change this, - pass the desired timeout (in seconds) as request_timeout. + pass the desired timeout (in seconds) as `request_timeout`. - The mastodon_version parameter can be used to specify the version of Mastodon that Mastodon.py will + The `mastodon_version` parameter can be used to specify the version of Mastodon that Mastodon.py will expect to be installed on the server. The function will throw an error if an unparseable - Version is specified. If no version is specified, Mastodon.py will set mastodon_version to the + Version is specified. If no version is specified, Mastodon.py will set `mastodon_version` to the detected version. """ self.api_base_url = Mastodon.__protocolize(api_base_url) @@ -240,21 +240,21 @@ class Mastodon: code=None, redirect_uri="urn:ietf:wg:oauth:2.0:oob", refresh_token=None, scopes=['read', 'write', 'follow'], to_file=None): """ - Your username is the e-mail you use to log in into mastodon. - - Can persist access token to file, to be used in the constructor. - - Supports refresh_token but Mastodon.social doesn't implement it at the moment. + Get the access token for a user. + + The username is the e-mail used to log in into mastodon. - Handles password, authorization_code, and refresh_token authentication. + Can persist access token to file `to_file`, to be used in the constructor. - Will throw a MastodonIllegalArgumentError if username / password + Handles password and OAuth-based authorization. + + Will throw a `MastodonIllegalArgumentError` if username / password are wrong, scopes are not valid or granted scopes differ from requested. For OAuth2 documentation, compare https://github.com/doorkeeper-gem/doorkeeper/wiki/Interacting-as-an-OAuth-client-with-Doorkeeper - Returns the access token. + Returns the access token as a string. """ if username is not None and password is not None: params = self.__generate_params(locals(), ['scopes', 'to_file', 'code', 'refresh_token']) @@ -306,7 +306,7 @@ class Mastodon: """ Retrieve basic information about the instance, including the URI and administrative contact email. - Returns an instance dict. + Returns an `instance dict`_. """ return self.__instance() @@ -322,13 +322,13 @@ class Mastodon: @api_version("1.0.0") def timeline(self, timeline="home", max_id=None, since_id=None, limit=None): """ - Fetch statuses, most recent ones first. Timeline can be 'home', 'local', 'public', + Fetch statuses, most recent ones first. `timeline` can be 'home', 'local', 'public', or 'tag/hashtag'. See the following functions documentation for what those do. - Local hashtag timelines are supported via the timeline_hashtag() function. + Local hashtag timelines are supported via the `timeline_hashtag()`_ function. The default timeline is the "home" timeline. - Returns a list of toot dicts. + Returns a list of `toot dicts`_. """ if max_id != None: max_id = self.__unpack_id(max_id) @@ -349,9 +349,9 @@ class Mastodon: @api_version("1.0.0") def timeline_home(self, max_id=None, since_id=None, limit=None): """ - Fetch the authenticated users home timeline (i.e. followed users and self). + Fetch the logged-in users home timeline (i.e. followed users and self). - Returns a list of toot dicts. + Returns a list of `toot dicts`_. """ return self.timeline('home', max_id=max_id, since_id=since_id, limit=limit) @@ -361,7 +361,7 @@ class Mastodon: """ Fetches the local / instance-wide timeline, not including replies. - Returns a list of toot dicts. + Returns a list of `toot dicts`_. """ return self.timeline('local', max_id=max_id, since_id=since_id, limit=limit) @@ -371,7 +371,7 @@ class Mastodon: """ Fetches the public / visible-network timeline, not including replies. - Returns a list of toot dicts. + Returns a list of `toot dicts`_. """ return self.timeline('public', max_id=max_id, since_id=since_id, limit=limit) @@ -382,9 +382,9 @@ class Mastodon: Fetch a timeline of toots with a given hashtag. The hashtag parameter should not contain the leading #. - Set "local" to True to retrieve only instance-local tagged posts. + Set `local` to True to retrieve only instance-local tagged posts. - Returns a list of toot dicts. + Returns a list of `toot dicts`_. """ if hashtag.startswith("#"): raise MastodonIllegalArgumentError("Hashtag parameter should omit leading #") @@ -413,7 +413,7 @@ class Mastodon: """ Fetch information about a single toot. - Returns a toot dict. + Returns a `toot dict`_. """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}'.format(str(id)) @@ -425,7 +425,7 @@ class Mastodon: Fetch a card associated with a status. A card describes an object (such as an external video or link) embedded into a status. - Returns a card dict. + Returns a `card dict`_. """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}/card'.format(str(id)) @@ -436,7 +436,7 @@ class Mastodon: """ Fetch information about ancestors and descendants of a toot. - Returns a context dict. + Returns a `context dict`_. """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}/context'.format(str(id)) @@ -447,7 +447,7 @@ class Mastodon: """ Fetch a list of users that have reblogged a status. - Returns a list of user dicts. + Returns a list of `user dicts`_. """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}/reblogged_by'.format(str(id)) @@ -458,7 +458,7 @@ class Mastodon: """ Fetch a list of users that have favourited a status. - Returns a list of user dicts. + Returns a list of `user dicts`_. """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}/favourited_by'.format(str(id)) @@ -470,12 +470,12 @@ class Mastodon: @api_version("1.0.0") def notifications(self, id=None, max_id=None, since_id=None, limit=None): """ - Fetch notifications (mentions, favourites, reblogs, follows) for the authenticated + Fetch notifications (mentions, favourites, reblogs, follows) for the logged-in user. - Can be passed an id to fetch a single notification. + Can be passed an `id` to fetch a single notification. - Returns a list of notification dicts. + Returns a list of `notification dicts`_. """ if max_id != None: max_id = self.__unpack_id(max_id) @@ -497,9 +497,9 @@ class Mastodon: @api_version("1.0.0") def account(self, id): """ - Fetch account information by user id. + Fetch account information by user `id`. - Returns a user dict. + Returns a `user dict`_. """ id = self.__unpack_id(id) url = '/api/v1/accounts/{0}'.format(str(id)) @@ -508,18 +508,21 @@ class Mastodon: @api_version("1.0.0") def account_verify_credentials(self): """ - Fetch authenticated user's account information. + Fetch logged-in user's account information. - Returns a user dict (Starting from 2.1.0, with an additional "source" field). + Returns a `user dict`_ (Starting from 2.1.0, with an additional "source" field). """ return self.__api_request('GET', '/api/v1/accounts/verify_credentials') @api_version("1.0.0") def account_statuses(self, id, max_id=None, since_id=None, limit=None): """ - Fetch statuses by user id. Same options as timeline are permitted. + Fetch statuses by user `id`. Same options as `timeline()`_ are permitted. + Returned toots are from the perspective of the logged-in user, i.e. + all statuses visible to the logged-in user (including DMs) are + included. - Returns a list of toot dicts. + Returns a list of `toot dicts`_. """ id = self.__unpack_id(id) if max_id != None: @@ -537,7 +540,7 @@ class Mastodon: """ Fetch users the given user is following. - Returns a list of user dicts. + Returns a list of `user dicts`_. """ id = self.__unpack_id(id) if max_id != None: @@ -555,7 +558,7 @@ class Mastodon: """ Fetch users the given user is followed by. - Returns a list of user dicts. + Returns a list of `user dicts`_. """ id = self.__unpack_id(id) if max_id != None: @@ -572,9 +575,9 @@ class Mastodon: def account_relationships(self, id): """ Fetch relationship (following, followed_by, blocking, follow requested) of - the logged in user to a given account. id can be a list. + the logged in user to a given account. `id` can be a list. - Returns a list of relationship dicts. + Returns a list of `relationship dicts`_. """ id = self.__unpack_id(id) params = self.__generate_params(locals()) @@ -587,7 +590,7 @@ class Mastodon: Fetch matching accounts. Will lookup an account remotely if the search term is in the username@domain format and not yet in the database. - Returns a list of user dicts. + Returns a list of `user dicts`_. """ params = self.__generate_params(locals()) return self.__api_request('GET', '/api/v1/accounts/search', params) @@ -601,7 +604,7 @@ class Mastodon: Fetch matching hashtags, accounts and statuses. Will search federated instances if resolve is True. - Returns a search result dict. + Returns a `search result dict`_. """ params = self.__generate_params(locals()) return self.__api_request('GET', '/api/v1/search', params) @@ -614,7 +617,7 @@ class Mastodon: """ Fetch a list of all the Lists by the logged-in user. - Returns a list of list dicts. + Returns a list of `list dicts`_. """ return self.__api_request('GET', '/api/v1/lists') @@ -624,9 +627,9 @@ class Mastodon: @api_version("1.1.0") def mutes(self, max_id=None, since_id=None, limit=None): """ - Fetch a list of users muted by the authenticated user. + Fetch a list of users muted by the logged-in user. - Returns a list of user dicts. + Returns a list of `user dicts`_. """ if max_id != None: max_id = self.__unpack_id(max_id) @@ -640,9 +643,9 @@ class Mastodon: @api_version("1.0.0") def blocks(self, max_id=None, since_id=None, limit=None): """ - Fetch a list of users blocked by the authenticated user. + Fetch a list of users blocked by the logged-in user. - Returns a list of user dicts. + Returns a list of `user dicts`_. """ if max_id != None: max_id = self.__unpack_id(max_id) @@ -659,12 +662,12 @@ class Mastodon: @api_version("1.1.0") def reports(self): """ - Fetch a list of reports made by the authenticated user. + Fetch a list of reports made by the logged-in user. - Returns a list of report dicts. + Returns a list of `report dicts`_. Warning: According to the official API documentation, this - method is to be treated as not finalized as of Mastodon 2.0.0. + method is to be treated as not finalized as of Mastodon 2.1.0. """ return self.__api_request('GET', '/api/v1/reports') @@ -674,9 +677,9 @@ class Mastodon: @api_version("1.0.0") def favourites(self, max_id=None, since_id=None, limit=None): """ - Fetch the authenticated user's favourited statuses. + Fetch the logged-in user's favourited statuses. - Returns a list of toot dicts. + Returns a list of `toot dicts`_. """ if max_id != None: max_id = self.__unpack_id(max_id) @@ -693,9 +696,9 @@ class Mastodon: @api_version("1.0.0") def follow_requests(self, max_id=None, since_id=None, limit=None): """ - Fetch the authenticated user's incoming follow requests. + Fetch the logged-in user's incoming follow requests. - Returns a list of user dicts. + Returns a list of `user dicts`_. """ if max_id != None: max_id = self.__unpack_id(max_id) @@ -712,7 +715,7 @@ class Mastodon: @api_version("1.4.0") def domain_blocks(self, max_id=None, since_id=None, limit=None): """ - Fetch the authenticated user's blocked domains. + Fetch the logged-in user's blocked domains. Returns a list of blocked domain URLs (as strings, without protocol specifier). """ @@ -733,7 +736,7 @@ class Mastodon: """ Fetch the list of custom emoji the instance has installed. - Returns a list of emoji dicts. + Returns a list of `emoji dicts`_. """ return self.__api_request('GET', '/api/v1/custom_emojis') @@ -746,11 +749,11 @@ class Mastodon: sensitive=False, visibility='', spoiler_text=None): """ Post a status. Can optionally be in reply to another status and contain - up to four pieces of media (Uploaded via media_post()). media_ids can - also be the media dicts returned by media_post - they are unpacked + up to four pieces of media (Uploaded via `media_post()`_). media_ids can + also be the `media dicts`_ returned by `media_post()`_ - they are unpacked automatically. - The 'sensitive' boolean decides whether or not media attached to the post + The `sensitive` boolean decides whether or not media attached to the post should be marked as sensitive, which hides it by default on the Mastodon web front-end. @@ -766,11 +769,11 @@ class Mastodon: locked setting - private if the account is locked, public otherwise (for Mastodon versions lower than 1.6). - The spoiler_text parameter is a string to be shown as a warning before + The `spoiler_text` parameter is a string to be shown as a warning before the text of the status. If no text is passed in, no warning will be displayed. - Returns a toot dict with the new status. + Returns a `toot dict`_ with the new status. """ if in_reply_to_id != None: in_reply_to_id = self.__unpack_id(in_reply_to_id) @@ -806,11 +809,11 @@ class Mastodon: @api_version("1.0.0") def toot(self, status): """ - Synonym for status_post that only takes the status text as input. + Synonym for `status_post()`_ that only takes the status text as input. Usage in production code is not recommended. - Returns a toot dict with the new status. + Returns a `toot dict`_ with the new status. """ return self.status_post(status) @@ -818,19 +821,17 @@ class Mastodon: def status_delete(self, id): """ Delete a status - - Returns an empty dict for good measure. """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}'.format(str(id)) - return self.__api_request('DELETE', url) + self.__api_request('DELETE', url) @api_version("1.0.0") def status_reblog(self, id): """ Reblog a status. - Returns a toot dict with a new status that wraps around the reblogged one. + Returns a `toot dict`_ with a new status that wraps around the reblogged one. """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}/reblog'.format(str(id)) @@ -841,7 +842,7 @@ class Mastodon: """ Un-reblog a status. - Returns a toot dict with the status that used to be reblogged. + Returns a `toot dict`_ with the status that used to be reblogged. """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}/unreblog'.format(str(id)) @@ -852,7 +853,7 @@ class Mastodon: """ Favourite a status. - Returns a toot dict with the favourited status. + Returns a `toot dict`_ with the favourited status. """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}/favourite'.format(str(id)) @@ -863,7 +864,7 @@ class Mastodon: """ Un-favourite a status. - Returns a toot dict with the un-favourited status. + Returns a `toot dict`_ with the un-favourited status. """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}/unfavourite'.format(str(id)) @@ -874,7 +875,7 @@ class Mastodon: """ Mute notifications for a status. - Returns a toot dict with the now muted status + Returns a `toot dict`_ with the now muted status """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}/mute'.format(str(id)) @@ -885,7 +886,7 @@ class Mastodon: """ Unmute notifications for a status. - Returns a toot dict with the status that used to be muted. + Returns a `toot dict`_ with the status that used to be muted. """ id = self.__unpack_id(id) url = '/api/v1/statuses/{0}/unmute'.format(str(id)) @@ -899,7 +900,7 @@ class Mastodon: """ Clear out a users notifications """ - return self.__api_request('POST', '/api/v1/notifications/clear') + self.__api_request('POST', '/api/v1/notifications/clear') @api_version("1.3.0") @@ -909,7 +910,7 @@ class Mastodon: """ id = self.__unpack_id(id) params = self.__generate_params(locals()) - return self.__api_request('POST', '/api/v1/notifications/dismiss', params) + self.__api_request('POST', '/api/v1/notifications/dismiss', params) ### # Writing data: Accounts @@ -919,7 +920,7 @@ class Mastodon: """ Follow a user. - Returns a relationship dict containing the updated relationship to the user. + Returns a `relationship dict`_ containing the updated relationship to the user. """ id = self.__unpack_id(id) url = '/api/v1/accounts/{0}/follow'.format(str(id)) @@ -930,7 +931,7 @@ class Mastodon: """ Follow a remote user by uri (username@domain). - Returns a user dict. + Returns a `user dict`_. """ params = self.__generate_params(locals()) return self.__api_request('POST', '/api/v1/follows', params) @@ -940,7 +941,7 @@ class Mastodon: """ Unfollow a user. - Returns a relationship dict containing the updated relationship to the user. + Returns a `relationship dict`_ containing the updated relationship to the user. """ id = self.__unpack_id(id) url = '/api/v1/accounts/{0}/unfollow'.format(str(id)) @@ -951,7 +952,7 @@ class Mastodon: """ Block a user. - Returns a relationship dict containing the updated relationship to the user. + Returns a `relationship dict`_ containing the updated relationship to the user. """ id = self.__unpack_id(id) url = '/api/v1/accounts/{0}/block'.format(str(id)) @@ -962,7 +963,7 @@ class Mastodon: """ Unblock a user. - Returns a relationship dict containing the updated relationship to the user. + Returns a `relationship dict`_ containing the updated relationship to the user. """ id = self.__unpack_id(id) url = '/api/v1/accounts/{0}/unblock'.format(str(id)) @@ -973,7 +974,7 @@ class Mastodon: """ Mute a user. - Returns a relationship dict containing the updated relationship to the user. + Returns a `relationship dict`_ containing the updated relationship to the user. """ id = self.__unpack_id(id) url = '/api/v1/accounts/{0}/mute'.format(str(id)) @@ -984,7 +985,7 @@ class Mastodon: """ Unmute a user. - Returns a relationship dict containing the updated relationship to the user. + Returns a `relationship dict`_ containing the updated relationship to the user. """ id = self.__unpack_id(id) url = '/api/v1/accounts/{0}/unmute'.format(str(id)) @@ -994,12 +995,14 @@ class Mastodon: def account_update_credentials(self, display_name=None, note=None, avatar=None, header=None): """ - Update the profile for the currently authenticated user. + Update the profile for the currently logged-in user. 'note' is the user's bio. 'avatar' and 'header' are images encoded in base64, prepended by a content-type (for example: 'data:image/png;base64,iVBORw0KGgoAAAA[...]') + + Returns the updated `user dict` of the logged-in user. """ params = self.__generate_params(locals()) return self.__api_request('PATCH', '/api/v1/accounts/update_credentials', params) @@ -1014,7 +1017,7 @@ class Mastodon: Accepts a list of toot IDs associated with the report, and a comment. - Returns a report dict. + Returns a `report dict`_. """ account_id = self.__unpack_id(account_id) status_ids = map(lambda x: self.__unpack_id(x), status_ids) @@ -1028,23 +1031,19 @@ class Mastodon: def follow_request_authorize(self, id): """ Accept an incoming follow request. - - Returns an empty dict. """ id = self.__unpack_id(id) url = '/api/v1/follow_requests/{0}/authorize'.format(str(id)) - return self.__api_request('POST', url) + self.__api_request('POST', url) @api_version("1.0.0") def follow_request_reject(self, id): """ Reject an incoming follow request. - - Returns an empty dict. """ id = self.__unpack_id(id) url = '/api/v1/follow_requests/{0}/reject'.format(str(id)) - return self.__api_request('POST', url) + self.__api_request('POST', url) ### # Writing data: Media @@ -1052,15 +1051,15 @@ class Mastodon: @api_version("1.0.0") def media_post(self, media_file, mime_type=None, description=None): """ - Post an image. media_file can either be image data or + Post an image. `media_file` can either be image data or a file name. If image data is passed directly, the mime type has to be specified manually, otherwise, it is determined from the file name. - Throws a MastodonIllegalArgumentError if the mime type of the + Throws a `MastodonIllegalArgumentError` if the mime type of the passed data or file can not be determined properly. - Returns a media dict. This contains the id that can be used in + Returns a `media dict`_. This contains the id that can be used in status_post to attach the media file to a toot. """ if mime_type is None and os.path.isfile(media_file): @@ -1090,7 +1089,7 @@ class Mastodon: Add a block for all statuses originating from the specified domain for the logged-in user. """ params = self.__generate_params(locals()) - return self.__api_request('POST', '/api/v1/domain_blocks', params) + self.__api_request('POST', '/api/v1/domain_blocks', params) @api_version("1.4.0") def domain_unblock(self, domain=None): @@ -1098,7 +1097,7 @@ class Mastodon: Remove a domain block for the logged-in user. """ params = self.__generate_params(locals()) - return self.__api_request('DELETE', '/api/v1/domain_blocks', params) + self.__api_request('DELETE', '/api/v1/domain_blocks', params) ### # Pagination -- cgit v1.2.3 From c9cc8737142cf71ce5b6e2435b3bf4c00272cd80 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 18:45:28 +0100 Subject: Add information about unauthenticated methods --- mastodon/Mastodon.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index af450ec..35640fd 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -306,6 +306,8 @@ class Mastodon: """ Retrieve basic information about the instance, including the URI and administrative contact email. + Does not require authentication. + Returns an `instance dict`_. """ return self.__instance() @@ -413,6 +415,8 @@ class Mastodon: """ Fetch information about a single toot. + Does not require authentication for publicly visible statuses. + Returns a `toot dict`_. """ id = self.__unpack_id(id) @@ -425,6 +429,8 @@ class Mastodon: Fetch a card associated with a status. A card describes an object (such as an external video or link) embedded into a status. + Does not require authentication for publicly visible statuses. + Returns a `card dict`_. """ id = self.__unpack_id(id) @@ -436,6 +442,8 @@ class Mastodon: """ Fetch information about ancestors and descendants of a toot. + Does not require authentication for publicly visible statuses. + Returns a `context dict`_. """ id = self.__unpack_id(id) @@ -447,6 +455,8 @@ class Mastodon: """ Fetch a list of users that have reblogged a status. + Does not require authentication for publicly visible statuses. + Returns a list of `user dicts`_. """ id = self.__unpack_id(id) @@ -458,6 +468,8 @@ class Mastodon: """ Fetch a list of users that have favourited a status. + Does not require authentication for publicly visible statuses. + Returns a list of `user dicts`_. """ id = self.__unpack_id(id) @@ -736,6 +748,8 @@ class Mastodon: """ Fetch the list of custom emoji the instance has installed. + Does not require authentication. + Returns a list of `emoji dicts`_. """ -- cgit v1.2.3 From 7cf813b9744342d0be82330cf5fb81e85fea5642 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 18:59:32 +0100 Subject: Added account_lists(broken) --- mastodon/Mastodon.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 35640fd..0df1217 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -607,6 +607,20 @@ class Mastodon: params = self.__generate_params(locals()) return self.__api_request('GET', '/api/v1/accounts/search', params) + @api_version("2.1.0") + def account_lists(self, id): + """ + Get all of the logged in users lists which the specified user is + a member of. + + TODO: This doesn't work. + + Returns a list of `list dicts`_. + """ + params = self.__generate_params(locals(), ['id']) + url = '/api/v1/accounts/{0}/lists'.format(str(id)) + return self.__api_request('GET', url, params) + ### # Reading data: Searching ### -- cgit v1.2.3 From b840766ed77ea0cac84ada7cb27a9b23ffda0a09 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 21:16:02 +0100 Subject: Add more list endpoints --- mastodon/Mastodon.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 0df1217..44e0538 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -325,7 +325,7 @@ class Mastodon: def timeline(self, timeline="home", max_id=None, since_id=None, limit=None): """ Fetch statuses, most recent ones first. `timeline` can be 'home', 'local', 'public', - or 'tag/hashtag'. See the following functions documentation for what those do. + 'tag/hashtag' or 'list/id'. See the following functions documentation for what those do. Local hashtag timelines are supported via the `timeline_hashtag()`_ function. The default timeline is the "home" timeline. @@ -407,6 +407,17 @@ class Mastodon: return self.__api_request('GET', url, params) + @api_version("2.1.0") + def timeline_list(self, id, max_id=None, since_id=None, limit=None): + """ + Fetches a timeline containing all the toots by users in a given list. + + Returns a list of `toot dicts`_. + """ + id = self.__unpack_id(id) + return self.timeline('list/{0}'.format(id), max_id=max_id, + since_id=since_id, limit=limit) + ### # Reading data: Statuses ### @@ -613,8 +624,6 @@ class Mastodon: Get all of the logged in users lists which the specified user is a member of. - TODO: This doesn't work. - Returns a list of `list dicts`_. """ params = self.__generate_params(locals(), ['id']) @@ -647,6 +656,16 @@ class Mastodon: """ return self.__api_request('GET', '/api/v1/lists') + @api_version("2.1.0") + def list(self, id): + """ + Fetch info about a specific list. + + Returns a `list dict`_. + """ + id = self.__unpack_id(id) + return self.__api_request('GET', '/api/v1/lists/{0}'.format(id)) + ### # Reading data: Mutes and Blocks ### @@ -1035,6 +1054,38 @@ class Mastodon: params = self.__generate_params(locals()) return self.__api_request('PATCH', '/api/v1/accounts/update_credentials', params) + ### + # Writing data: Lists + ### + @api_version("2.1.0") + def list_create(self, title): + """ + Create a new list with the given `title`. + + Returns the `list dict`_ of the created list. + """ + params = self.__generate_params(locals()) + return self.__api_request('POST', '/api/v1/lists', params) + + @api_version("2.1.0") + def list_update(self, id, title): + """ + Update info about a list, where "info" is really the lists `title`. + + Returns the `list dict`_ of the modified list. + """ + id = self.__unpack_id(id) + params = self.__generate_params(locals(), ['id']) + return self.__api_request('PUT', '/api/v1/lists/{0}'.format(id), params) + + @api_version("2.1.0") + def list_delete(self, id): + """ + Delete a list. + """ + id = self.__unpack_id(id) + self.__api_request('DELETE', '/api/v1/lists/{0}'.format(id)) + ### # Writing data: Reports ### -- cgit v1.2.3 From 0b5c0ae5ccb61a42ed19ee9c5b46de65979b9060 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 22:16:10 +0100 Subject: Add remaining list endpoints --- mastodon/.Mastodon.py.kate-swp | Bin 0 -> 106 bytes mastodon/Mastodon.py | 61 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 mastodon/.Mastodon.py.kate-swp (limited to 'mastodon') diff --git a/mastodon/.Mastodon.py.kate-swp b/mastodon/.Mastodon.py.kate-swp new file mode 100644 index 0000000..60f8d57 Binary files /dev/null and b/mastodon/.Mastodon.py.kate-swp differ diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 44e0538..3b02881 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -666,6 +666,25 @@ class Mastodon: id = self.__unpack_id(id) return self.__api_request('GET', '/api/v1/lists/{0}'.format(id)) + @api_version("2.1.0") + def list_accounts(self, id, max_id=None, since_id=None, limit=None): + """ + Get the accounts that are on the given list. A `limit` of 0 can + be specified to get all accounts without pagination. + + Returns a list of `user dicts`_. + """ + id = self.__unpack_id(id) + + if max_id != None: + max_id = self.__unpack_id(max_id) + + if since_id != None: + since_id = self.__unpack_id(since_id) + + params = self.__generate_params(locals(), ['id']) + return self.__api_request('GET', '/api/v1/lists/{0}/accounts'.format(id)) + ### # Reading data: Mutes and Blocks ### @@ -1086,6 +1105,42 @@ class Mastodon: id = self.__unpack_id(id) self.__api_request('DELETE', '/api/v1/lists/{0}'.format(id)) + @api_version("2.1.0") + def list_delete(self, id): + """ + Delete a list. + """ + id = self.__unpack_id(id) + self.__api_request('DELETE', '/api/v1/lists/{0}'.format(id)) + + @api_version("2.1.0") + def list_accounts_add(self, id, account_ids): + """ + Add the account(s) given in `account_ids` to the list. + """ + id = self.__unpack_id(id) + + if not isinstance(account_ids, list): + account_ids = [account_ids] + account_ids = list(map(lambda x: self.__unpack_id(x), account_ids)) + + params = self.__generate_params(locals(), ['id']) + return self.__api_request('POST', '/api/v1/lists/{0}/accounts'.format(id), params) + + @api_version("2.1.0") + def list_accounts_delete(self, id, account_ids): + """ + Remove the account(s) given in `account_ids` from the list. + """ + id = self.__unpack_id(id) + + if not isinstance(account_ids, list): + account_ids = [account_ids] + account_ids = list(map(lambda x: self.__unpack_id(x), account_ids)) + + params = self.__generate_params(locals(), ['id']) + return self.__api_request('DELETE', '/api/v1/lists/{0}/accounts'.format(id), params) + ### # Writing data: Reports ### @@ -1099,7 +1154,11 @@ class Mastodon: Returns a `report dict`_. """ account_id = self.__unpack_id(account_id) - status_ids = map(lambda x: self.__unpack_id(x), status_ids) + + if not isinstance(status_ids, list): + status_ids = [status_ids] + status_ids = list(map(lambda x: self.__unpack_id(x), status_ids)) + params = self.__generate_params(locals()) return self.__api_request('POST', '/api/v1/reports/', params) -- cgit v1.2.3 From afaab2b8743a11f2a8567873df8ae6ed7873ebb5 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Wed, 13 Dec 2017 22:33:29 +0100 Subject: Document list endpoints --- mastodon/Mastodon.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 3b02881..f15ee23 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -1105,14 +1105,6 @@ class Mastodon: id = self.__unpack_id(id) self.__api_request('DELETE', '/api/v1/lists/{0}'.format(id)) - @api_version("2.1.0") - def list_delete(self, id): - """ - Delete a list. - """ - id = self.__unpack_id(id) - self.__api_request('DELETE', '/api/v1/lists/{0}'.format(id)) - @api_version("2.1.0") def list_accounts_add(self, id, account_ids): """ @@ -1125,7 +1117,7 @@ class Mastodon: account_ids = list(map(lambda x: self.__unpack_id(x), account_ids)) params = self.__generate_params(locals(), ['id']) - return self.__api_request('POST', '/api/v1/lists/{0}/accounts'.format(id), params) + self.__api_request('POST', '/api/v1/lists/{0}/accounts'.format(id), params) @api_version("2.1.0") def list_accounts_delete(self, id, account_ids): @@ -1139,7 +1131,7 @@ class Mastodon: account_ids = list(map(lambda x: self.__unpack_id(x), account_ids)) params = self.__generate_params(locals(), ['id']) - return self.__api_request('DELETE', '/api/v1/lists/{0}/accounts'.format(id), params) + self.__api_request('DELETE', '/api/v1/lists/{0}/accounts'.format(id), params) ### # Writing data: Reports -- cgit v1.2.3