diff --git a/tests/test_console.py b/tests/test_console.py
index 7cf1ee8..56ed86d 100644
--- a/tests/test_console.py
+++ b/tests/test_console.py
@@ -107,6 +107,17 @@ def test_post_invalid_media(capsys):
assert "can't open 'does_not_exist.jpg'" in err
+@mock.patch('toot.http.delete')
+def test_delete(mock_delete, capsys):
+ console.run_command(app, user, 'delete', ['12321'])
+
+ mock_delete.assert_called_once_with(app, user, '/api/v1/statuses/12321')
+
+ out, err = capsys.readouterr()
+ assert 'Status deleted' in out
+ assert not err
+
+
@mock.patch('toot.http.get')
def test_timeline(mock_get, monkeypatch, capsys):
mock_get.return_value = MockResponse([{
diff --git a/toot/api.py b/toot/api.py
index ce7270b..74dbf95 100644
--- a/toot/api.py
+++ b/toot/api.py
@@ -106,6 +106,14 @@ def post_status(
}, headers=headers).json()
+def delete_status(app, user, status_id):
+ """
+ Deletes a status with given ID.
+ https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#deleting-a-status
+ """
+ return http.delete(app, user, '/api/v1/statuses/{}'.format(status_id))
+
+
def timeline_home(app, user):
return http.get(app, user, '/api/v1/timelines/home').json()
diff --git a/toot/commands.py b/toot/commands.py
index 75d3988..5f7645f 100644
--- a/toot/commands.py
+++ b/toot/commands.py
@@ -68,6 +68,12 @@ def post(app, user, args):
print_out("Toot posted: {}".format(response.get('url')))
+def delete(app, user, args):
+ api.delete_status(app, user, args.status_id)
+
+ print_out("✓ Status deleted")
+
+
def auth(app, user, args):
config_data = config.load_config()
diff --git a/toot/console.py b/toot/console.py
index 0d86806..d99a97d 100644
--- a/toot/console.py
+++ b/toot/console.py
@@ -217,6 +217,17 @@ POST_COMMANDS = [
],
require_auth=True,
),
+ Command(
+ name="delete",
+ description="Delete an existing status",
+ arguments=[
+ (["status_id"], {
+ "help": "ID of the status to delete",
+ "type": int,
+ })
+ ],
+ require_auth=True,
+ ),
]
ACCOUNTS_COMMANDS = [
diff --git a/toot/http.py b/toot/http.py
index b63ee8f..b7f1aea 100644
--- a/toot/http.py
+++ b/toot/http.py
@@ -69,6 +69,16 @@ def post(app, user, url, data=None, files=None, allow_redirects=True, headers={}
return process_response(response)
+def delete(app, user, url, data=None):
+ url = app.base_url + url
+ headers = {"Authorization": "Bearer " + user.access_token}
+
+ request = Request('DELETE', url, headers=headers, data=data)
+ response = send_request(request)
+
+ return process_response(response)
+
+
def anon_post(url, data=None, files=None, allow_redirects=True):
request = Request('POST', url, {}, files, data)
response = send_request(request, allow_redirects)