From cb88c24e2ea0a397df91919cdcc32e6d85991621 Mon Sep 17 00:00:00 2001 From: missytake Date: Sat, 18 Mar 2023 21:25:11 +0100 Subject: [PATCH] [mastodon] Change mastodon_create to accept json instead of URL parameters --- .../src/kibicara/platforms/mastodon/webapi.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/backend/src/kibicara/platforms/mastodon/webapi.py b/backend/src/kibicara/platforms/mastodon/webapi.py index 5c6c237..6647633 100644 --- a/backend/src/kibicara/platforms/mastodon/webapi.py +++ b/backend/src/kibicara/platforms/mastodon/webapi.py @@ -24,6 +24,12 @@ class BodyMastodonPublic(BaseModel): instance: str +class BodyMastodonAccount(BaseModel): + email: str + instance_url: str + password: str + + async def get_mastodon(mastodon_id, hood=Depends(get_hood)): try: return await MastodonAccount.objects.get(id=mastodon_id, hood=hood) @@ -138,24 +144,21 @@ async def mastodon_stop(mastodon=Depends(get_mastodon)): # TODO response_model operation_id="create_mastodon", ) -async def mastodon_create(instance_url, username, password, hood=Depends(get_hood)): +async def mastodon_create(values: BodyMastodonAccount, hood=Depends(get_hood)): """Add a Mastodon Account to a Ticketfrei account. open questions: - do we really get the username + password like this? can the instance_url have different ways of writing? - :param: instance_url: the API base URL of the mastodon server - :param: username: the username of the Mastodon account - :param: password: the password of the Mastodon account + :param: values: a BodyMastodonAccount object in json :param: hood: the hood ORM object """ - instance = await get_mastodon_instance(instance_url) + instance = await get_mastodon_instance(values.instance_url) account = Mastodon( - instance.client_id, instance.client_secret, api_base_url=instance_url + instance.client_id, instance.client_secret, api_base_url=values.instance_url ) try: - access_token = account.log_in(username, password) + access_token = account.log_in(values.email, values.password) except MastodonError: logger.warning("Login to Mastodon failed.", exc_info=True) return # show error to user