From 8f93b255ad936a08575d0b1b211bc9204d44af46 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Wed, 13 Jun 2018 12:43:31 +0200 Subject: [PATCH] Add option to reply to a toot fixes #6 --- CHANGELOG.md | 4 ++++ tests/test_console.py | 10 +++++++++- toot/api.py | 17 +++++++++++++++-- toot/commands.py | 1 + toot/console.py | 6 +++++- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1df1a40..e8a49d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog --------- +**0.19.0 (TBA)** + +* Add support for replying to a toot (#6) + **0.18.0 (2018-06-12)** * Add support for public, tag and list timelines in `toot timeline` (#52) diff --git a/tests/test_console.py b/tests/test_console.py index 198349e..9a917ba 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -39,6 +39,7 @@ def test_post_defaults(mock_post, capsys): 'media_ids[]': None, 'sensitive': False, 'spoiler_text': None, + 'in_reply_to_id': None, }) out, err = capsys.readouterr() @@ -49,7 +50,13 @@ def test_post_defaults(mock_post, capsys): @mock.patch('toot.http.post') def test_post_with_options(mock_post, capsys): - args = ['Hello world', '--visibility', 'unlisted', '--sensitive', '--spoiler-text', 'Spoiler!'] + args = [ + 'Hello world', + '--visibility', 'unlisted', + '--sensitive', + '--spoiler-text', 'Spoiler!', + '--reply-to', '123' + ] mock_post.return_value = MockResponse({ 'url': 'https://habunek.com/@ihabunek/1234567890' @@ -63,6 +70,7 @@ def test_post_with_options(mock_post, capsys): 'visibility': 'unlisted', 'sensitive': True, 'spoiler_text': "Spoiler!", + 'in_reply_to_id': 123, }) out, err = capsys.readouterr() diff --git a/toot/api.py b/toot/api.py index a5bde26..c5fe79e 100644 --- a/toot/api.py +++ b/toot/api.py @@ -76,14 +76,27 @@ def request_access_token(app, authorization_code): return http.process_response(response).json() -def post_status(app, user, status, visibility='public', media_ids=None, - sensitive=False, spoiler_text=None): +def post_status( + app, + user, + status, + visibility='public', + media_ids=None, + sensitive=False, + spoiler_text=None, + in_reply_to_id=None +): + """ + Posts a new status. + https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#posting-a-new-status + """ return http.post(app, user, '/api/v1/statuses', { 'status': status, 'media_ids[]': media_ids, 'visibility': visibility, 'sensitive': sensitive, 'spoiler_text': spoiler_text, + 'in_reply_to_id': in_reply_to_id, }).json() diff --git a/toot/commands.py b/toot/commands.py index 67e4fa1..75d3988 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -62,6 +62,7 @@ def post(app, user, args): media_ids=media_ids, sensitive=args.sensitive, spoiler_text=args.spoiler_text, + in_reply_to_id=args.reply_to, ) print_out("Toot posted: {}".format(response.get('url'))) diff --git a/toot/console.py b/toot/console.py index d678ca6..0d86806 100644 --- a/toot/console.py +++ b/toot/console.py @@ -198,7 +198,11 @@ POST_COMMANDS = [ (["-p", "--spoiler-text"], { "type": str, "help": 'text to be shown as a warning before the actual content', - }) + }), + (["-r", "--reply-to"], { + "type": int, + "help": 'local ID of the status you want to reply to', + }), ], require_auth=True, ),