Remove mastosoc default instance
This commit is contained in:
parent
5d7ca19c30
commit
617c30a8c3
@ -167,7 +167,6 @@ class Mastodon:
|
|||||||
If anything is unclear, check the official API docs at
|
If anything is unclear, check the official API docs at
|
||||||
https://github.com/mastodon/documentation/blob/master/content/en/client/intro.md
|
https://github.com/mastodon/documentation/blob/master/content/en/client/intro.md
|
||||||
"""
|
"""
|
||||||
__DEFAULT_BASE_URL = 'https://mastodon.social'
|
|
||||||
__DEFAULT_TIMEOUT = 300
|
__DEFAULT_TIMEOUT = 300
|
||||||
__DEFAULT_STREAM_TIMEOUT = 300
|
__DEFAULT_STREAM_TIMEOUT = 300
|
||||||
__DEFAULT_STREAM_RECONNECT_WAIT_SEC = 5
|
__DEFAULT_STREAM_RECONNECT_WAIT_SEC = 5
|
||||||
@ -260,17 +259,17 @@ class Mastodon:
|
|||||||
###
|
###
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_app(client_name, scopes=__DEFAULT_SCOPES, redirect_uris=None, website=None, to_file=None,
|
def create_app(client_name, scopes=__DEFAULT_SCOPES, redirect_uris=None, website=None, to_file=None,
|
||||||
api_base_url=__DEFAULT_BASE_URL, request_timeout=__DEFAULT_TIMEOUT, session=None):
|
api_base_url=None, request_timeout=__DEFAULT_TIMEOUT, session=None):
|
||||||
"""
|
"""
|
||||||
Create a new app with given `client_name` and `scopes` (The basic scopes are "read", "write", "follow" and "push"
|
Create a new app with given `client_name` and `scopes` (The basic scopes are "read", "write", "follow" and "push"
|
||||||
- more granular scopes are available, please refer to Mastodon documentation for which).
|
- more granular scopes are available, please refer to Mastodon documentation for which) on the instance given
|
||||||
|
by `api_base_url`.
|
||||||
|
|
||||||
Specify `redirect_uris` if you want users to be redirected to a certain page after authenticating in an OAuth flow.
|
Specify `redirect_uris` if you want users to be redirected to a certain page after authenticating in an OAuth flow.
|
||||||
You can specify multiple URLs by passing a list. Note that if you wish to use OAuth authentication with redirects,
|
You can specify multiple URLs by passing a list. Note that if you wish to use OAuth authentication with redirects,
|
||||||
the redirect URI must be one of the URLs specified here.
|
the redirect URI must be one of the URLs specified here.
|
||||||
|
|
||||||
Specify `to_file` to persist your app's info to a file so you can use it in the constructor.
|
Specify `to_file` to persist your app's info to a file so you can use it in the constructor.
|
||||||
Specify `api_base_url` if you want to register an app on an instance different from the flagship one.
|
|
||||||
Specify `website` to give a website for your app.
|
Specify `website` to give a website for your app.
|
||||||
|
|
||||||
Specify `session` with a requests.Session for it to be used instead of the default. This can be
|
Specify `session` with a requests.Session for it to be used instead of the default. This can be
|
||||||
@ -282,6 +281,8 @@ class Mastodon:
|
|||||||
|
|
||||||
Returns `client_id` and `client_secret`, both as strings.
|
Returns `client_id` and `client_secret`, both as strings.
|
||||||
"""
|
"""
|
||||||
|
if api_base_url is None:
|
||||||
|
raise MastodonIllegalArgumentError("API base URL is required.")
|
||||||
api_base_url = Mastodon.__protocolize(api_base_url)
|
api_base_url = Mastodon.__protocolize(api_base_url)
|
||||||
|
|
||||||
request_data = {
|
request_data = {
|
||||||
@ -299,12 +300,10 @@ class Mastodon:
|
|||||||
if website is not None:
|
if website is not None:
|
||||||
request_data['website'] = website
|
request_data['website'] = website
|
||||||
if session:
|
if session:
|
||||||
ret = session.post(api_base_url + '/api/v1/apps',
|
ret = session.post(api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout)
|
||||||
data=request_data, timeout=request_timeout)
|
|
||||||
response = ret.json()
|
response = ret.json()
|
||||||
else:
|
else:
|
||||||
response = requests.post(
|
response = requests.post(api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout)
|
||||||
api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout)
|
|
||||||
response = response.json()
|
response = response.json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise MastodonNetworkError("Could not complete request: %s" % e)
|
raise MastodonNetworkError("Could not complete request: %s" % e)
|
||||||
@ -327,11 +326,11 @@ class Mastodon:
|
|||||||
request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None,
|
request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None,
|
||||||
version_check_mode="created", session=None, feature_set="mainline", user_agent="mastodonpy"):
|
version_check_mode="created", session=None, feature_set="mainline", user_agent="mastodonpy"):
|
||||||
"""
|
"""
|
||||||
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` on the
|
||||||
give a `client_id` and it is not a file, you must also give a secret. If you specify an
|
instance given by `api_base_url`. If you give a `client_id` and it is not a file, you must
|
||||||
`access_token` then you don't need to specify a `client_id`. It is allowed to specify
|
also give a secret. If you specify an `access_token` then you don't need to specify a `client_id`.
|
||||||
neither - in this case, you will be restricted to only using endpoints that do not
|
It is allowed to specify neither - in this case, you will be restricted to only using endpoints
|
||||||
require authentication. If a file is given as `client_id`, client ID, secret and
|
that do not require authentication. If a file is given as `client_id`, client ID, secret and
|
||||||
base url are read from that file.
|
base url are read from that file.
|
||||||
|
|
||||||
You can also specify an `access_token`, directly or as a file (as written by `log_in()`_). If
|
You can also specify an `access_token`, directly or as a file (as written by `log_in()`_). If
|
||||||
@ -347,10 +346,6 @@ class Mastodon:
|
|||||||
even in "wait" and "pace" mode, requests can still fail due to network or other problems! Also
|
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.
|
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. When
|
|
||||||
reading from client id or access token files as written by Mastodon.py 1.5.0 or larger,
|
|
||||||
this can be omitted.
|
|
||||||
|
|
||||||
By default, a timeout of 300 seconds is used for all requests. If you wish to change this,
|
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`.
|
||||||
|
|
||||||
@ -378,9 +373,9 @@ class Mastodon:
|
|||||||
|
|
||||||
If no other `User-Agent` is specified, "mastodonpy" will be used.
|
If no other `User-Agent` is specified, "mastodonpy" will be used.
|
||||||
"""
|
"""
|
||||||
self.api_base_url = None
|
if api_base_url is None:
|
||||||
if api_base_url is not None:
|
raise MastodonIllegalArgumentError("API base URL is required.")
|
||||||
self.api_base_url = Mastodon.__protocolize(api_base_url)
|
self.api_base_url = Mastodon.__protocolize(api_base_url)
|
||||||
|
|
||||||
self.client_id = client_id
|
self.client_id = client_id
|
||||||
self.client_secret = client_secret
|
self.client_secret = client_secret
|
||||||
|
Loading…
x
Reference in New Issue
Block a user