Skip to content

Commit

Permalink
add server rules API
Browse files Browse the repository at this point in the history
  • Loading branch information
halcy authored and halcy committed Nov 18, 2022
1 parent bfdde77 commit 6a63020
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Refer to mastodon changelog and API docs for details when implementing, add or m

3.4.0
-----
* [ ] Add server rules
* [x] Add server rules
* [ ] Add POST /api/v1/emails/confirmations to REST API
* [ ] Add GET /api/v1/accounts/lookup to REST API
* [ ] Add policy param to POST /api/v1/push/subscriptions in REST API
Expand Down
12 changes: 10 additions & 2 deletions mastodon/Mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,7 @@ def instance_health(self):
"""
Basic health check. Returns True if healthy, False if not.
"""
status = self.__api_request(
'GET', '/health', parse=False).decode("utf-8")
status = self.__api_request('GET', '/health', parse=False).decode("utf-8")
return status in ["OK", "success"]

@api_version("3.0.0", "3.0.0", "3.0.0")
Expand Down Expand Up @@ -807,6 +806,15 @@ def instance_nodeinfo(self, schema="http://nodeinfo.diaspora.software/ns/schema/
parse = urlparse(schema_url)
return self.__api_request('GET', parse.path + parse.params + parse.query + parse.fragment)

@api_version("3.4.0", "3.4.0", __DICT_VERSION_INSTANCE)
def instance_rules(self):
"""
Retrieve instance rules.
Returns a list of `id` + `text` dicts, same as the `rules` field in the `instance dicts`_.
"""
return self.__api_request('GET', '/api/v1/instance/rules')

###
# Reading data: Timelines
##
Expand Down
60 changes: 60 additions & 0 deletions tests/cassettes/test_instance_rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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/rules
response:
body:
string: '[]'
headers:
Cache-Control:
- no-store
Content-Security-Policy:
- 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src
''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000;
style-src ''self'' http://localhost:3000 ''nonce-VfLfKge8CLCQB9dJyA6/cA=='';
media-src ''self'' https: data: http://localhost:3000; frame-src ''self''
https:; manifest-src ''self'' http://localhost:3000; connect-src ''self''
data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000
ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline''
''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000;
worker-src ''self'' blob: http://localhost:3000'
Content-Type:
- application/json; charset=utf-8
ETag:
- W/"4f53cda18c2baa0c0354bb5f9a3ecbe5"
Referrer-Policy:
- strict-origin-when-cross-origin
Transfer-Encoding:
- chunked
Vary:
- Accept, Origin
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- SAMEORIGIN
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- 48fd3107-1ed2-4db1-8ae6-a62ac4897b98
X-Runtime:
- '0.036615'
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
4 changes: 3 additions & 1 deletion tests/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ def test_directory(api):
assert isinstance(directory, list)
assert len(directory) > 0


@pytest.mark.vcr()
def test_instance_rules(api):
assert isinstance(api.instance_rules(), list)

0 comments on commit 6a63020

Please sign in to comment.