diff options
-rw-r--r-- | mastodon/Mastodon.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index b186344..5171d9b 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -174,7 +174,7 @@ class Mastodon: | |||
174 | ### | 174 | ### |
175 | # Authentication, including constructor | 175 | # Authentication, including constructor |
176 | ### | 176 | ### |
177 | def __init__(self, client_id, client_secret=None, access_token=None, | 177 | def __init__(self, client_id=None, client_secret=None, access_token=None, |
178 | api_base_url=__DEFAULT_BASE_URL, debug_requests=False, | 178 | api_base_url=__DEFAULT_BASE_URL, debug_requests=False, |
179 | ratelimit_method="wait", ratelimit_pacefactor=1.1, | 179 | ratelimit_method="wait", ratelimit_pacefactor=1.1, |
180 | request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None, | 180 | request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None, |
@@ -248,17 +248,20 @@ class Mastodon: | |||
248 | raise MastodonIllegalArgumentError("Invalid ratelimit method.") | 248 | raise MastodonIllegalArgumentError("Invalid ratelimit method.") |
249 | 249 | ||
250 | # Token loading | 250 | # Token loading |
251 | if os.path.isfile(self.client_id): | 251 | if self.client_id is None and self.access_token is None: |
252 | with open(self.client_id, 'r') as secret_file: | 252 | raise MastodonIllegalArgumentError('No credentials were given.') |
253 | self.client_id = secret_file.readline().rstrip() | 253 | if self.client_id is not None: |
254 | self.client_secret = secret_file.readline().rstrip() | 254 | if os.path.isfile(self.client_id): |
255 | else: | 255 | with open(self.client_id, 'r') as secret_file: |
256 | if self.client_secret is None: | 256 | self.client_id = secret_file.readline().rstrip() |
257 | raise MastodonIllegalArgumentError('Specified client id directly, but did not supply secret') | 257 | self.client_secret = secret_file.readline().rstrip() |
258 | else: | ||
259 | if self.client_secret is None: | ||
260 | raise MastodonIllegalArgumentError('Specified client id directly, but did not supply secret') | ||
258 | 261 | ||
259 | if self.access_token is not None and os.path.isfile(self.access_token): | 262 | if self.access_token is not None and os.path.isfile(self.access_token): |
260 | with open(self.access_token, 'r') as token_file: | 263 | with open(self.access_token, 'r') as token_file: |
261 | self.access_token = token_file.readline().rstrip() | 264 | self.access_token = token_file.readline().rstrip() |
262 | 265 | ||
263 | def retrieve_mastodon_version(self): | 266 | def retrieve_mastodon_version(self): |
264 | """ | 267 | """ |