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
~~~~~~~~~~~~
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
@ -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
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 dict:
@ -182,6 +199,8 @@ User dicts
'header_static': # URL for their header image, never animated
'source': # Additional information - only present for user dict returned
# 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"]
@ -474,10 +493,11 @@ Versioning
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
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
if the endpoint is available and behaves as in the newest Mastodon version
(this is the default). Version checking can also be disabled altogether.
If a version check fails, Mastodon.py throws a `MastodonVersionError`.
constructor) to either check if an endpoint is available at all (this is the
default) or to check if the endpoint is available and behaves as in the newest
Mastodon version (with regards to parameters as well as return values).
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
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,
ratelimit_method="wait", ratelimit_pacefactor=1.1,
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
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
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
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",
@ -478,7 +478,7 @@ class Mastodon:
url = '/api/v1/statuses/{0}/context'.format(str(id))
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):
"""
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))
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):
"""
Fetch a list of users that have favourited a status.
@ -545,7 +545,7 @@ class Mastodon:
url = '/api/v1/accounts/{0}'.format(str(id))
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):
"""
Fetch logged-in user's account information.
@ -587,7 +587,7 @@ class Mastodon:
url = '/api/v1/accounts/{0}/statuses'.format(str(id))
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):
"""
Fetch users the given user is following.
@ -605,7 +605,7 @@ class Mastodon:
url = '/api/v1/accounts/{0}/following'.format(str(id))
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):
"""
Fetch users the given user is followed by.
@ -636,7 +636,7 @@ class Mastodon:
return self.__api_request('GET', '/api/v1/accounts/relationships',
params)
@api_version("1.0.0", "1.0.0")
@api_version("1.0.0", "2.1.0")
def account_search(self, q, limit=None):
"""
Fetch matching accounts. Will lookup an account remotely if the search term is
@ -717,7 +717,7 @@ class Mastodon:
###
# 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):
"""
Fetch a list of users muted by the logged-in user.
@ -733,7 +733,7 @@ class Mastodon:
params = self.__generate_params(locals())
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):
"""
Fetch a list of users blocked by the logged-in user.
@ -786,7 +786,7 @@ class Mastodon:
###
# 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):
"""
Fetch the logged-in user's incoming follow requests.
@ -1021,7 +1021,7 @@ class Mastodon:
url = '/api/v1/accounts/{0}/follow'.format(str(id))
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):
"""
Follow a remote user by uri (username@domain).
@ -1086,7 +1086,7 @@ class Mastodon:
url = '/api/v1/accounts/{0}/unmute'.format(str(id))
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,
avatar=None, header=None):
"""