Change default version check behaviour

This commit is contained in:
Lorenz Diener 2017-12-14 13:29:42 +01:00
pare af81088fb0
commit 5a94c46bb4
S'han modificat 2 arxius amb 38 adicions i 18 eliminacions

Veure arxiu

@ -110,7 +110,7 @@ in the API, so don't do that.
ID unpacking ID unpacking
~~~~~~~~~~~~ ~~~~~~~~~~~~
Wherever Mastodon.py expects an ID as a parameter, you can also pass a Wherever Mastodon.py expects an ID as a parameter, you can also pass a
dict that contains an id - this means that, for example, instead of saying dict that contains an id - this means that, for example, instead of writing
.. code-block:: python .. code-block:: python
@ -156,6 +156,23 @@ Unless otherwise specified, all data is returned as python dictionaries, matchin
the JSON format used by the API. Dates returned by the API are in ISO 8601 format the JSON format used by the API. Dates returned by the API are in ISO 8601 format
and are parsed into python datetime objects. and are parsed into python datetime objects.
To make access easier, the dictionaries returned are wrapped by a class that adds
read-only attributes for all dict values - this means that, for example, instead of
writing
.. code-block:: python
description = mastodon.account_verify_credentials()["source"]["note"]
you can also just write
.. code-block:: python
description = mastodon.account_verify_credentials().source.note
and everything will work as intended.
User dicts User dicts
~~~~~~~~~~ ~~~~~~~~~~
.. _user dict: .. _user dict:
@ -182,6 +199,8 @@ User dicts
'header_static': # URL for their header image, never animated 'header_static': # URL for their header image, never animated
'source': # Additional information - only present for user dict returned 'source': # Additional information - only present for user dict returned
# from account_verify_credentials() # from account_verify_credentials()
'moved_to_account': # If set, an account dict of the account this user has
# set up as their moved-to address.
} }
mastodon.account_verify_credentials()["source"] mastodon.account_verify_credentials()["source"]
@ -474,10 +493,11 @@ Versioning
Mastodon.py will check if a certain endpoint is available before doing API Mastodon.py will check if a certain endpoint is available before doing API
calls. By default, it checks against the version of Mastodon retrieved on calls. By default, it checks against the version of Mastodon retrieved on
init(), or the version you specified. Mastodon.py can be set (in the init(), or the version you specified. Mastodon.py can be set (in the
constructor) to either check if an endpoint is available at all or to check constructor) to either check if an endpoint is available at all (this is the
if the endpoint is available and behaves as in the newest Mastodon version default) or to check if the endpoint is available and behaves as in the newest
(this is the default). Version checking can also be disabled altogether. Mastodon version (with regards to parameters as well as return values).
If a version check fails, Mastodon.py throws a `MastodonVersionError`. Version checking can also be disabled altogether. If a version check fails,
Mastodon.py throws a `MastodonVersionError`.
With the following functions, you can make Mastodon.py re-check the server With the following functions, you can make Mastodon.py re-check the server
version or explicitly determine if a specific minimum Version is available. version or explicitly determine if a specific minimum Version is available.

Veure arxiu

@ -123,7 +123,7 @@ class Mastodon:
api_base_url=__DEFAULT_BASE_URL, debug_requests=False, api_base_url=__DEFAULT_BASE_URL, debug_requests=False,
ratelimit_method="wait", ratelimit_pacefactor=1.1, ratelimit_method="wait", ratelimit_pacefactor=1.1,
request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None, request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None,
version_check_mode = "changed"): version_check_mode = "created"):
""" """
Create a new API wrapper instance based on the given `client_secret` and `client_id`. If you 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. give a `client_id` and it is not a file, you must also give a secret.
@ -150,7 +150,7 @@ class Mastodon:
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. detected version.
The version check mode can be set to "created", "changed" (the default behaviour) or "none". If set to The version check mode can be set to "created" (the default behaviour), "changed" or "none". If set to
"created", Mastodon.py will throw an error if the version of Mastodon it is connected to is too old "created", Mastodon.py will throw an error if the version of Mastodon it is connected to is too old
to have an endpoint. If it is set to "changed", it will throw an error if the endpoints behaviour has to have an endpoint. If it is set to "changed", it will throw an error if the endpoints behaviour has
changed after the version of Mastodon that is connected has been released. If it is set to "none", changed after the version of Mastodon that is connected has been released. If it is set to "none",
@ -478,7 +478,7 @@ class Mastodon:
url = '/api/v1/statuses/{0}/context'.format(str(id)) url = '/api/v1/statuses/{0}/context'.format(str(id))
return self.__api_request('GET', url) return self.__api_request('GET', url)
@api_version("1.0.0", "1.0.0") @api_version("1.0.0", "2.1.0")
def status_reblogged_by(self, id): def status_reblogged_by(self, id):
""" """
Fetch a list of users that have reblogged a status. Fetch a list of users that have reblogged a status.
@ -491,7 +491,7 @@ class Mastodon:
url = '/api/v1/statuses/{0}/reblogged_by'.format(str(id)) url = '/api/v1/statuses/{0}/reblogged_by'.format(str(id))
return self.__api_request('GET', url) return self.__api_request('GET', url)
@api_version("1.0.0", "1.0.0") @api_version("1.0.0", "2.1.0")
def status_favourited_by(self, id): def status_favourited_by(self, id):
""" """
Fetch a list of users that have favourited a status. Fetch a list of users that have favourited a status.
@ -545,7 +545,7 @@ class Mastodon:
url = '/api/v1/accounts/{0}'.format(str(id)) url = '/api/v1/accounts/{0}'.format(str(id))
return self.__api_request('GET', url) return self.__api_request('GET', url)
@api_version("1.0.0", "1.5.0") @api_version("1.0.0", "2.1.0")
def account_verify_credentials(self): def account_verify_credentials(self):
""" """
Fetch logged-in user's account information. Fetch logged-in user's account information.
@ -587,7 +587,7 @@ class Mastodon:
url = '/api/v1/accounts/{0}/statuses'.format(str(id)) url = '/api/v1/accounts/{0}/statuses'.format(str(id))
return self.__api_request('GET', url, params) return self.__api_request('GET', url, params)
@api_version("1.0.0", "1.0.0") @api_version("1.0.0", "2.1.0")
def account_following(self, id, max_id=None, since_id=None, limit=None): def account_following(self, id, max_id=None, since_id=None, limit=None):
""" """
Fetch users the given user is following. Fetch users the given user is following.
@ -605,7 +605,7 @@ class Mastodon:
url = '/api/v1/accounts/{0}/following'.format(str(id)) url = '/api/v1/accounts/{0}/following'.format(str(id))
return self.__api_request('GET', url, params) return self.__api_request('GET', url, params)
@api_version("1.0.0", "1.0.0") @api_version("1.0.0", "2.1.0")
def account_followers(self, id, max_id=None, since_id=None, limit=None): def account_followers(self, id, max_id=None, since_id=None, limit=None):
""" """
Fetch users the given user is followed by. Fetch users the given user is followed by.
@ -636,7 +636,7 @@ class Mastodon:
return self.__api_request('GET', '/api/v1/accounts/relationships', return self.__api_request('GET', '/api/v1/accounts/relationships',
params) params)
@api_version("1.0.0", "1.0.0") @api_version("1.0.0", "2.1.0")
def account_search(self, q, limit=None): def account_search(self, q, limit=None):
""" """
Fetch matching accounts. Will lookup an account remotely if the search term is Fetch matching accounts. Will lookup an account remotely if the search term is
@ -717,7 +717,7 @@ class Mastodon:
### ###
# Reading data: Mutes and Blocks # Reading data: Mutes and Blocks
### ###
@api_version("1.1.0", "1.1.0") @api_version("1.1.0", "2.1.0")
def mutes(self, max_id=None, since_id=None, limit=None): def mutes(self, max_id=None, since_id=None, limit=None):
""" """
Fetch a list of users muted by the logged-in user. Fetch a list of users muted by the logged-in user.
@ -733,7 +733,7 @@ class Mastodon:
params = self.__generate_params(locals()) params = self.__generate_params(locals())
return self.__api_request('GET', '/api/v1/mutes', params) return self.__api_request('GET', '/api/v1/mutes', params)
@api_version("1.0.0", "1.0.0") @api_version("1.0.0", "2.1.0")
def blocks(self, max_id=None, since_id=None, limit=None): def blocks(self, max_id=None, since_id=None, limit=None):
""" """
Fetch a list of users blocked by the logged-in user. Fetch a list of users blocked by the logged-in user.
@ -786,7 +786,7 @@ class Mastodon:
### ###
# Reading data: Follow requests # Reading data: Follow requests
### ###
@api_version("1.0.0", "1.0.0") @api_version("1.0.0", "2.1.0")
def follow_requests(self, max_id=None, since_id=None, limit=None): def follow_requests(self, max_id=None, since_id=None, limit=None):
""" """
Fetch the logged-in user's incoming follow requests. Fetch the logged-in user's incoming follow requests.
@ -1021,7 +1021,7 @@ class Mastodon:
url = '/api/v1/accounts/{0}/follow'.format(str(id)) url = '/api/v1/accounts/{0}/follow'.format(str(id))
return self.__api_request('POST', url) return self.__api_request('POST', url)
@api_version("1.0.0", "1.0.0") @api_version("1.0.0", "2.1.0")
def follows(self, uri): def follows(self, uri):
""" """
Follow a remote user by uri (username@domain). Follow a remote user by uri (username@domain).
@ -1086,7 +1086,7 @@ class Mastodon:
url = '/api/v1/accounts/{0}/unmute'.format(str(id)) url = '/api/v1/accounts/{0}/unmute'.format(str(id))
return self.__api_request('POST', url) return self.__api_request('POST', url)
@api_version("1.1.1", "1.6.0") @api_version("1.1.1", "2.1.0")
def account_update_credentials(self, display_name=None, note=None, def account_update_credentials(self, display_name=None, note=None,
avatar=None, header=None): avatar=None, header=None):
""" """