diff options
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 76 |
1 files changed, 60 insertions, 16 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index a4fe768..d0b3606 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -373,10 +373,9 @@ class Mastodon: | |||
373 | 373 | ||
374 | If no other `User-Agent` is specified, "mastodonpy" will be used. | 374 | If no other `User-Agent` is specified, "mastodonpy" will be used. |
375 | """ | 375 | """ |
376 | if api_base_url is None: | 376 | self.api_base_url = api_base_url |
377 | raise MastodonIllegalArgumentError("API base URL is required.") | 377 | if self.api_base_url is not None: |
378 | self.api_base_url = Mastodon.__protocolize(api_base_url) | 378 | self.api_base_url = self.__protocolize(self.api_base_url) |
379 | |||
380 | self.client_id = client_id | 379 | self.client_id = client_id |
381 | self.client_secret = client_secret | 380 | self.client_secret = client_secret |
382 | self.access_token = access_token | 381 | self.access_token = access_token |
@@ -417,9 +416,9 @@ class Mastodon: | |||
417 | try_base_url = secret_file.readline().rstrip() | 416 | try_base_url = secret_file.readline().rstrip() |
418 | if try_base_url is not None and len(try_base_url) != 0: | 417 | if try_base_url is not None and len(try_base_url) != 0: |
419 | try_base_url = Mastodon.__protocolize(try_base_url) | 418 | try_base_url = Mastodon.__protocolize(try_base_url) |
419 | print(self.api_base_url, try_base_url) | ||
420 | if not (self.api_base_url is None or try_base_url == self.api_base_url): | 420 | if not (self.api_base_url is None or try_base_url == self.api_base_url): |
421 | raise MastodonIllegalArgumentError( | 421 | raise MastodonIllegalArgumentError('Mismatch in base URLs between files and/or specified') |
422 | 'Mismatch in base URLs between files and/or specified') | ||
423 | self.api_base_url = try_base_url | 422 | self.api_base_url = try_base_url |
424 | 423 | ||
425 | # With new registrations we support the 4th line to store a client_name and use it as user-agent | 424 | # With new registrations we support the 4th line to store a client_name and use it as user-agent |
@@ -428,8 +427,7 @@ class Mastodon: | |||
428 | self.user_agent = client_name.rstrip() | 427 | self.user_agent = client_name.rstrip() |
429 | else: | 428 | else: |
430 | if self.client_secret is None: | 429 | if self.client_secret is None: |
431 | raise MastodonIllegalArgumentError( | 430 | raise MastodonIllegalArgumentError('Specified client id directly, but did not supply secret') |
432 | 'Specified client id directly, but did not supply secret') | ||
433 | 431 | ||
434 | if self.access_token is not None and os.path.isfile(self.access_token): | 432 | if self.access_token is not None and os.path.isfile(self.access_token): |
435 | with open(self.access_token, 'r') as token_file: | 433 | with open(self.access_token, 'r') as token_file: |
@@ -439,10 +437,14 @@ class Mastodon: | |||
439 | if try_base_url is not None and len(try_base_url) != 0: | 437 | if try_base_url is not None and len(try_base_url) != 0: |
440 | try_base_url = Mastodon.__protocolize(try_base_url) | 438 | try_base_url = Mastodon.__protocolize(try_base_url) |
441 | if not (self.api_base_url is None or try_base_url == self.api_base_url): | 439 | if not (self.api_base_url is None or try_base_url == self.api_base_url): |
442 | raise MastodonIllegalArgumentError( | 440 | raise MastodonIllegalArgumentError('Mismatch in base URLs between files and/or specified') |
443 | 'Mismatch in base URLs between files and/or specified') | ||
444 | self.api_base_url = try_base_url | 441 | self.api_base_url = try_base_url |
445 | 442 | ||
443 | # Verify we have a base URL, protocolize | ||
444 | if self.api_base_url is None: | ||
445 | raise MastodonIllegalArgumentError("API base URL is required.") | ||
446 | self.api_base_url = Mastodon.__protocolize(self.api_base_url) | ||
447 | |||
446 | if not version_check_mode in ["created", "changed", "none"]: | 448 | if not version_check_mode in ["created", "changed", "none"]: |
447 | raise MastodonIllegalArgumentError("Invalid version check method.") | 449 | raise MastodonIllegalArgumentError("Invalid version check method.") |
448 | self.version_check_mode = version_check_mode | 450 | self.version_check_mode = version_check_mode |
@@ -994,7 +996,7 @@ class Mastodon: | |||
994 | Does not require authentication for publicly visible statuses. | 996 | Does not require authentication for publicly visible statuses. |
995 | 997 | ||
996 | This function is deprecated as of 3.0.0 and the endpoint does not | 998 | This function is deprecated as of 3.0.0 and the endpoint does not |
997 | exist anymore - you should just use the "card" field of the status dicts | 999 | exist anymore - you should just use the "card" field of the toot dicts |
998 | instead. Mastodon.py will try to mimic the old behaviour, but this | 1000 | instead. Mastodon.py will try to mimic the old behaviour, but this |
999 | is somewhat inefficient and not guaranteed to be the case forever. | 1001 | is somewhat inefficient and not guaranteed to be the case forever. |
1000 | 1002 | ||
@@ -1573,7 +1575,7 @@ class Mastodon: | |||
1573 | Specify `limit` to limit how many results are returned (the maximum number | 1575 | Specify `limit` to limit how many results are returned (the maximum number |
1574 | of results is 10, the endpoint is not paginated). | 1576 | of results is 10, the endpoint is not paginated). |
1575 | 1577 | ||
1576 | Returns a list of `status dicts`_, sorted by the instances's trending algorithm, | 1578 | Returns a list of `toot dicts`_, sorted by the instances's trending algorithm, |
1577 | descending. | 1579 | descending. |
1578 | """ | 1580 | """ |
1579 | params = self.__generate_params(locals()) | 1581 | params = self.__generate_params(locals()) |
@@ -1690,6 +1692,8 @@ class Mastodon: | |||
1690 | Warning: This method has now finally been removed, and will not | 1692 | Warning: This method has now finally been removed, and will not |
1691 | work on Mastodon versions 2.5.0 and above. | 1693 | work on Mastodon versions 2.5.0 and above. |
1692 | """ | 1694 | """ |
1695 | if self.verify_minimum_version("2.5.0", cached=True): | ||
1696 | raise MastodonVersionError("API removed in Mastodon 2.5.0") | ||
1693 | return self.__api_request('GET', '/api/v1/reports') | 1697 | return self.__api_request('GET', '/api/v1/reports') |
1694 | 1698 | ||
1695 | ### | 1699 | ### |
@@ -2530,7 +2534,7 @@ class Mastodon: | |||
2530 | """ | 2534 | """ |
2531 | Set a note (visible to the logged in user only) for the given account. | 2535 | Set a note (visible to the logged in user only) for the given account. |
2532 | 2536 | ||
2533 | Returns a `status dict`_ with the `note` updated. | 2537 | Returns a `toot dict`_ with the `note` updated. |
2534 | """ | 2538 | """ |
2535 | id = self.__unpack_id(id) | 2539 | id = self.__unpack_id(id) |
2536 | params = self.__generate_params(locals(), ["id"]) | 2540 | params = self.__generate_params(locals(), ["id"]) |
@@ -2696,18 +2700,25 @@ class Mastodon: | |||
2696 | ### | 2700 | ### |
2697 | # Writing data: Reports | 2701 | # Writing data: Reports |
2698 | ### | 2702 | ### |
2699 | @api_version("1.1.0", "2.5.0", __DICT_VERSION_REPORT) | 2703 | @api_version("1.1.0", "3.5.0", __DICT_VERSION_REPORT) |
2700 | def report(self, account_id, status_ids=None, comment=None, forward=False): | 2704 | def report(self, account_id, status_ids=None, comment=None, forward=False, category=None, rule_ids=None): |
2701 | """ | 2705 | """ |
2702 | Report statuses to the instances administrators. | 2706 | Report statuses to the instances administrators. |
2703 | 2707 | ||
2704 | Accepts a list of toot IDs associated with the report, and a comment. | 2708 | Accepts a list of toot IDs associated with the report, and a comment. |
2705 | 2709 | ||
2706 | Set forward to True to forward a report of a remote user to that users | 2710 | Starting with Mastodon 3.5.0, you can also pass a `category` (one out of |
2711 | "spam", "violation" or "other") and `rule_ids` (a list of rule IDs corresponding | ||
2712 | to the rules returned by the `instance()`_ API). | ||
2713 | |||
2714 | Set `forward` to True to forward a report of a remote user to that users | ||
2707 | instance as well as sending it to the instance local administrators. | 2715 | instance as well as sending it to the instance local administrators. |
2708 | 2716 | ||
2709 | Returns a `report dict`_. | 2717 | Returns a `report dict`_. |
2710 | """ | 2718 | """ |
2719 | if category is not None and not category in ["spam", "violation", "other"]: | ||
2720 | raise MastodonIllegalArgumentError("Invalid report category (must be spam, violation or other)") | ||
2721 | |||
2711 | account_id = self.__unpack_id(account_id) | 2722 | account_id = self.__unpack_id(account_id) |
2712 | 2723 | ||
2713 | if status_ids is not None: | 2724 | if status_ids is not None: |
@@ -3297,6 +3308,39 @@ class Mastodon: | |||
3297 | id = self.__unpack_id(id) | 3308 | id = self.__unpack_id(id) |
3298 | return self.__api_request('POST', '/api/v1/admin/reports/{0}/resolve'.format(id)) | 3309 | return self.__api_request('POST', '/api/v1/admin/reports/{0}/resolve'.format(id)) |
3299 | 3310 | ||
3311 | @api_version("3.5.0", "3.5.0", __DICT_VERSION_HASHTAG) | ||
3312 | def admin_trending_tags(self, limit=None): | ||
3313 | """ | ||
3314 | Admin version of `trending_tags()`_. Includes unapproved tags. | ||
3315 | |||
3316 | Returns a list of `hashtag dicts`_, sorted by the instance's trending algorithm, | ||
3317 | descending. | ||
3318 | """ | ||
3319 | params = self.__generate_params(locals()) | ||
3320 | return self.__api_request('GET', '/api/v1/admin/trends/tags', params) | ||
3321 | |||
3322 | @api_version("3.5.0", "3.5.0", __DICT_VERSION_STATUS) | ||
3323 | def admin_trending_statuses(self): | ||
3324 | """ | ||
3325 | Admin version of `trending_statuses()`_. Includes unapproved tags. | ||
3326 | |||
3327 | Returns a list of `toot dicts`_, sorted by the instance's trending algorithm, | ||
3328 | descending. | ||
3329 | """ | ||
3330 | params = self.__generate_params(locals()) | ||
3331 | return self.__api_request('GET', '/api/v1/admin/trends/statuses', params) | ||
3332 | |||
3333 | @api_version("3.5.0", "3.5.0", __DICT_VERSION_CARD) | ||
3334 | def admin_trending_links(self): | ||
3335 | """ | ||
3336 | Admin version of `trending_links()`_. Includes unapproved tags. | ||
3337 | |||
3338 | Returns a list of `card dicts`_, sorted by the instance's trending algorithm, | ||
3339 | descending. | ||
3340 | """ | ||
3341 | params = self.__generate_params(locals()) | ||
3342 | return self.__api_request('GET', '/api/v1/admin/trends/links', params) | ||
3343 | |||
3300 | ### | 3344 | ### |
3301 | # Push subscription crypto utilities | 3345 | # Push subscription crypto utilities |
3302 | ### | 3346 | ### |