diff options
Diffstat (limited to 'mastodon/reports.py')
-rw-r--r-- | mastodon/reports.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/mastodon/reports.py b/mastodon/reports.py new file mode 100644 index 0000000..3d6380e --- /dev/null +++ b/mastodon/reports.py | |||
@@ -0,0 +1,62 @@ | |||
1 | |||
2 | # reports.py - report endpoints | ||
3 | |||
4 | from .versions import _DICT_VERSION_REPORT | ||
5 | from .errors import MastodonVersionError | ||
6 | from .utility import api_version | ||
7 | |||
8 | from .internals import Mastodon as Internals | ||
9 | |||
10 | class Mastodon(Internals): | ||
11 | ### | ||
12 | # Reading data: Reports | ||
13 | ### | ||
14 | @api_version("1.1.0", "1.1.0", _DICT_VERSION_REPORT) | ||
15 | def reports(self): | ||
16 | """ | ||
17 | Fetch a list of reports made by the logged-in user. | ||
18 | |||
19 | Returns a list of :ref:`report dicts <report dicts>`. | ||
20 | |||
21 | Warning: This method has now finally been removed, and will not | ||
22 | work on Mastodon versions 2.5.0 and above. | ||
23 | """ | ||
24 | if self.verify_minimum_version("2.5.0", cached=True): | ||
25 | raise MastodonVersionError("API removed in Mastodon 2.5.0") | ||
26 | return self.__api_request('GET', '/api/v1/reports') | ||
27 | |||
28 | ### | ||
29 | # Writing data: Reports | ||
30 | ### | ||
31 | @api_version("1.1.0", "3.5.0", _DICT_VERSION_REPORT) | ||
32 | def report(self, account_id, status_ids=None, comment=None, forward=False, category=None, rule_ids=None): | ||
33 | """ | ||
34 | Report statuses to the instances administrators. | ||
35 | |||
36 | Accepts a list of toot IDs associated with the report, and a comment. | ||
37 | |||
38 | Starting with Mastodon 3.5.0, you can also pass a `category` (one out of | ||
39 | "spam", "violation" or "other") and `rule_ids` (a list of rule IDs corresponding | ||
40 | to the rules returned by the :ref:`instance() <instance()>` API). | ||
41 | |||
42 | Set `forward` to True to forward a report of a remote user to that users | ||
43 | instance as well as sending it to the instance local administrators. | ||
44 | |||
45 | Returns a :ref:`report dict <report dict>`. | ||
46 | """ | ||
47 | if category is not None and not category in ["spam", "violation", "other"]: | ||
48 | raise MastodonIllegalArgumentError("Invalid report category (must be spam, violation or other)") | ||
49 | |||
50 | account_id = self.__unpack_id(account_id) | ||
51 | |||
52 | if status_ids is not None: | ||
53 | if not isinstance(status_ids, list): | ||
54 | status_ids = [status_ids] | ||
55 | status_ids = list(map(lambda x: self.__unpack_id(x), status_ids)) | ||
56 | |||
57 | params_initial = locals() | ||
58 | if not forward: | ||
59 | del params_initial['forward'] | ||
60 | |||
61 | params = self.__generate_params(params_initial) | ||
62 | return self.__api_request('POST', '/api/v1/reports/', params) \ No newline at end of file | ||