Merge pull request #134 from keponk/dev

update constructor to support access_token only
This commit is contained in:
Lorenz Diener 2018-05-19 18:47:57 +02:00 cometido por GitHub
commit f8ba37b42e
No se encontró ninguna clave conocida en la base de datos para esta firma
ID de clave GPG: 4AEE18F83AFDEB23

Veure arxiu

@ -174,7 +174,7 @@ class Mastodon:
### ###
# Authentication, including constructor # Authentication, including constructor
### ###
def __init__(self, client_id, client_secret=None, access_token=None, def __init__(self, client_id=None, client_secret=None, access_token=None,
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,
@ -248,6 +248,9 @@ class Mastodon:
raise MastodonIllegalArgumentError("Invalid ratelimit method.") raise MastodonIllegalArgumentError("Invalid ratelimit method.")
# Token loading # Token loading
if self.client_id is None and self.access_token is None:
raise MastodonIllegalArgumentError('No credentials were given.')
if self.client_id is not None:
if os.path.isfile(self.client_id): if os.path.isfile(self.client_id):
with open(self.client_id, 'r') as secret_file: with open(self.client_id, 'r') as secret_file:
self.client_id = secret_file.readline().rstrip() self.client_id = secret_file.readline().rstrip()