From 6f923ad1f9ef596a1de61452cc50148875666c09 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Sat, 26 Nov 2016 00:03:19 +0100 Subject: media_ids can not just be dicts, for extra lazyness --- mastodon/Mastodon.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index c437618..349bc03 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -312,11 +312,28 @@ class Mastodon: def status_post(self, status, in_reply_to_id = None, media_ids = None): """ Post a status. Can optionally be in reply to another status and contain - up to four pieces of media (Uploaded via media_post()). + up to four pieces of media (Uploaded via media_post()). media_ids can + also be the media dicts returned by media_post - they are unpacked + automatically. Returns a toot dict with the new status. """ - params = self.__generate_params(locals()) + params_initial = locals() + + if media_ids != None: + try: + media_ids_proper = [] + for media_id in media_ids: + if isinstance(media_id, dict): + media_ids_proper.append(media_id["id"]) + else: + media_ids_proper.append(media_id) + except: + raise MastodonIllegalArgumentError("Invalid media dict.") + + params_initial["media_ids"] = media_ids_proper + + params = self.__generate_params(params_initial) return self.__api_request('POST', '/api/v1/statuses', params) def toot(self, status): @@ -558,6 +575,11 @@ class Mastodon: def __generate_params(self, params, exclude = []): """ Internal named-parameters-to-dict helper. + + Note for developers: If called with locals() as params, + as is the usual practice in this code, the __generate_params call + (or at least the locals() call) should generally be the first thing + in your function. """ params = dict(params) -- cgit v1.2.3