Skip to content

Commit

Permalink
Remove mastosoc default instance
Browse files Browse the repository at this point in the history
  • Loading branch information
halcy authored and halcy committed Nov 24, 2022
1 parent 5d7ca19 commit 617c30a
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions mastodon/Mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ class Mastodon:
If anything is unclear, check the official API docs at
https://github.com/mastodon/documentation/blob/master/content/en/client/intro.md
"""
__DEFAULT_BASE_URL = 'https://mastodon.social'
__DEFAULT_TIMEOUT = 300
__DEFAULT_STREAM_TIMEOUT = 300
__DEFAULT_STREAM_RECONNECT_WAIT_SEC = 5
Expand Down Expand Up @@ -260,17 +259,17 @@ class Mastodon:
###
@staticmethod
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"
- 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.
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.
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 `session` with a requests.Session for it to be used instead of the default. This can be
Expand All @@ -282,6 +281,8 @@ def create_app(client_name, scopes=__DEFAULT_SCOPES, redirect_uris=None, website
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)

request_data = {
Expand All @@ -299,12 +300,10 @@ def create_app(client_name, scopes=__DEFAULT_SCOPES, redirect_uris=None, website
if website is not None:
request_data['website'] = website
if session:
ret = session.post(api_base_url + '/api/v1/apps',
data=request_data, timeout=request_timeout)
ret = session.post(api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout)
response = ret.json()
else:
response = requests.post(
api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout)
response = requests.post(api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout)
response = response.json()
except Exception as e:
raise MastodonNetworkError("Could not complete request: %s" % e)
Expand All @@ -327,11 +326,11 @@ def __init__(self, client_id=None, client_secret=None, access_token=None,
request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None,
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
give a `client_id` and it is not a file, you must also give a secret. If you specify an
`access_token` then you don't need to specify a `client_id`. It is allowed to specify
neither - in this case, you will be restricted to only using endpoints that do not
require authentication. If a file is given as `client_id`, client ID, secret and
Create a new API wrapper instance based on the given `client_secret` and `client_id` on the
instance given by `api_base_url`. If you give a `client_id` and it is not a file, you must
also give a secret. If you specify an `access_token` then you don't need to specify a `client_id`.
It is allowed to specify neither - in this case, you will be restricted to only using endpoints
that do not require authentication. If a file is given as `client_id`, client ID, secret and
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
Expand All @@ -347,10 +346,6 @@ def __init__(self, client_id=None, client_secret=None, access_token=None,
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. 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,
pass the desired timeout (in seconds) as `request_timeout`.
Expand Down Expand Up @@ -378,9 +373,9 @@ def __init__(self, client_id=None, client_secret=None, access_token=None,
If no other `User-Agent` is specified, "mastodonpy" will be used.
"""
self.api_base_url = None
if api_base_url is not None:
self.api_base_url = Mastodon.__protocolize(api_base_url)
if api_base_url is None:
raise MastodonIllegalArgumentError("API base URL is required.")
self.api_base_url = Mastodon.__protocolize(api_base_url)

self.client_id = client_id
self.client_secret = client_secret
Expand Down

0 comments on commit 617c30a

Please sign in to comment.