From e5c00a9229645cd7bd6587d02bc94db2f35124b8 Mon Sep 17 00:00:00 2001 From: halcy Date: Sat, 15 Feb 2025 17:11:56 +0200 Subject: [PATCH] add instance_extended_description --- CHANGELOG.rst | 2 + docs/08_instances.rst | 3 +- mastodon/instance.py | 9 ++- srcgen/return_types.json | 10 +-- .../test_instance_extended_description.yaml | 63 +++++++++++++++++++ tests/test_instance.py | 4 ++ 6 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 tests/cassettes/test_instance_extended_description.yaml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ea4dfa0..f317fa7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -35,6 +35,8 @@ v2.0.0 (IN PROGRESS) * Add automatic conversion of datetime objects to flake IDs for min/max/since_id fields where appropriate * Add `notifications_unread_count` * Add media attachment editing +* Add email domain blocking support (`admin_email_domain_blocks`, `admin_email_domain_block`, `admin_email_domain_block_create`, `admin_email_domain_block_delete`) +* Add `instance_extended_description` v1.8.1 ------ diff --git a/docs/08_instances.rst b/docs/08_instances.rst index 24dcc2e..21b0671 100644 --- a/docs/08_instances.rst +++ b/docs/08_instances.rst @@ -17,7 +17,8 @@ current instance as well as data from the instance-wide profile directory. .. automethod:: Mastodon.instance_health .. automethod:: Mastodon.instance_nodeinfo .. automethod:: Mastodon.instance_rules - +.. automethod:: Mastodon.instance_extended_description + Profile directory ~~~~~~~~~~~~~~~~~ .. automethod:: Mastodon.directory diff --git a/mastodon/instance.py b/mastodon/instance.py index f9befe2..1b7f3ff 100644 --- a/mastodon/instance.py +++ b/mastodon/instance.py @@ -4,7 +4,7 @@ from mastodon.utility import api_version from mastodon.compat import urlparse from mastodon.internals import Mastodon as Internals -from mastodon.return_types import Instance, InstanceV2, NonPaginatableList, Activity, Nodeinfo, AttribAccessDict, Rule, Announcement, CustomEmoji, Account, IdType +from mastodon.return_types import Instance, InstanceV2, NonPaginatableList, Activity, Nodeinfo, AttribAccessDict, Rule, Announcement, CustomEmoji, Account, IdType, ExtendedDescription from typing import Union, Optional @@ -199,3 +199,10 @@ class Mastodon(Internals): """ id = self.__unpack_id(id) self.__api_request('DELETE', f'/api/v1/announcements/{id}/reactions/{reaction}') + + @api_version("4.0.0", "4.0.0") + def instance_extended_description(self) -> ExtendedDescription: + """ + Retrieve the instance's extended description. + """ + return self.__api_request('GET', '/api/v1/instance/extended_description', parse=False).decode("utf-8") diff --git a/srcgen/return_types.json b/srcgen/return_types.json index e734ad3..c80dc8f 100644 --- a/srcgen/return_types.json +++ b/srcgen/return_types.json @@ -8437,7 +8437,7 @@ { "name": "Extended instance description", "python_name": "ExtendedDescription", - "func_call": "TODO_TO_BE_IMPLEMENTED", + "func_call": "mastodon.instance_extended_description()", "func_call_real": null, "func_call_additional": null, "func_alternate_acc": null, @@ -8670,7 +8670,7 @@ { "name": "Status source", "python_name": "StatusSource", - "func_call": "TODO_TO_BE_IMPLEMENTED", + "func_call": "mastodon.status_source()", "func_call_real": null, "func_call_additional": null, "func_alternate_acc": null, @@ -9547,7 +9547,7 @@ { "name": "Account Warning", "python_name": "AccountWarning", - "func_call": "# There isn't really a good way to get this manually - you get it if a moderation takes action.", + "func_call": "# There isn't really a good way to get this manually - you get it if a moderator takes action.", "func_call_real": null, "func_call_additional": null, "func_alternate_acc": null, @@ -9661,11 +9661,11 @@ { "name": "Appeal", "python_name": "Appeal", - "func_call": "TODO_TO_BE_IMPLEMENTED", + "func_call": "# There isn't really a good way to get this manually - you get it if a moderator takes action.", "func_call_real": null, "func_call_additional": null, "func_alternate_acc": null, - "manual_update": false, + "manual_update": true, "masto_doc_link": "https://docs.joinmastodon.org/entities/Appeal/", "description": "Appeal against a moderation action.", "fields": { diff --git a/tests/cassettes/test_instance_extended_description.yaml b/tests/cassettes/test_instance_extended_description.yaml new file mode 100644 index 0000000..00df3fd --- /dev/null +++ b/tests/cassettes/test_instance_extended_description.yaml @@ -0,0 +1,63 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - Bearer __MASTODON_PY_TEST_ACCESS_TOKEN + Connection: + - keep-alive + User-Agent: + - tests/v311 + method: GET + uri: http://localhost:3000/api/v1/instance/extended_description + response: + body: + string: '{"updated_at":null,"content":""}' + headers: + Cache-Control: + - max-age=300, public, stale-while-revalidate=30, stale-if-error=86400 + Content-Length: + - '32' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none'; form-action 'none' + Content-Type: + - application/json; charset=utf-8 + Date: + - Sat, 15 Feb 2025 15:11:19 GMT + ETag: + - W/"a7feb2b8d6c676e926cca06600860589" + Referrer-Policy: + - strict-origin-when-cross-origin + Server-Timing: + - cache_read.active_support;dur=0.07, sql.active_record;dur=2.98, cache_generate.active_support;dur=7.75, + cache_write.active_support;dur=0.17, instantiation.active_record;dur=0.23, + start_processing.action_controller;dur=0.01, render.active_model_serializers;dur=0.38, + process_action.action_controller;dur=23.00 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-RateLimit-Limit: + - '300' + X-RateLimit-Remaining: + - '299' + X-RateLimit-Reset: + - '2025-02-15T15:15:00.307003Z' + X-Request-Id: + - 5f2a511b-6332-44d1-b1c6-bc29882cb543 + X-Runtime: + - '0.067181' + X-XSS-Protection: + - '0' + vary: + - Accept, Origin + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_instance.py b/tests/test_instance.py index 309e742..95f35f4 100644 --- a/tests/test_instance.py +++ b/tests/test_instance.py @@ -23,6 +23,10 @@ def test_instance(api): expected_keys = set(('description', )) # TODO add some more maybe assert set(instance.keys()) >= expected_keys +@pytest.mark.vcr() +def test_instance_extended_description(api): + extended_desc = api.instance_extended_description() + assert extended_desc @pytest.mark.vcr() def test_instance_activity(api):