[mastodon] Change mastodon_create to accept json instead of URL parameters
This commit is contained in:
parent
80a5e59e97
commit
3114faedb8
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue