aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2019-04-28 21:53:01 +0200
committerLorenz Diener <[email protected]>2019-04-28 21:53:01 +0200
commit3eba3f8835f25800f37b9da18a09429b084effa0 (patch)
tree112470e2ce3e07775c8963d7373892cbb8576058
parent66524ad4df9dcff3cee3a6d6bfc198e50ce310e1 (diff)
downloadmastodon.py-3eba3f8835f25800f37b9da18a09429b084effa0.tar.gz
Add preferences endpoint
-rw-r--r--docs/index.rst27
-rw-r--r--mastodon/Mastodon.py15
-rw-r--r--tests/cassettes/test_preferences.yaml30
-rw-r--r--tests/test_account.py5
4 files changed, 75 insertions, 2 deletions
diff --git a/docs/index.rst b/docs/index.rst
index d6d0d04..a98eb23 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -335,7 +335,7 @@ Scheduled toot dicts
335 335
336.. code-block:: python 336.. code-block:: python
337 337
338 api2.status_post("text", scheduled_at=the_future) 338 mastodon.status_post("text", scheduled_at=the_future)
339 # Returns the following dictionary: 339 # Returns the following dictionary:
340 { 340 {
341 'id': # Scheduled toot ID (note: Not the id of the toot once it gets posted!) 341 'id': # Scheduled toot ID (note: Not the id of the toot once it gets posted!)
@@ -693,6 +693,26 @@ Push notification dicts
693 'title': # Title for the notification 693 'title': # Title for the notification
694 } 694 }
695 695
696Preference dicts
697~~~~~~~~~~~~~~~~
698.. _preference dict:
699
700.. code-block:: python
701
702 mastodon.preferences()
703 # Returns the following dictionary
704 {
705 'posting:default:visibility': # The default visibility setting for the users posts,
706 # as a string
707 'posting:default:sensitive': # Boolean indicating whether the users uploads should
708 # be marked sensitive by default
709 'posting:default:language': # The users default post language, if set (None if not)
710 'reading:expand:media': # How the user wishes to be shown sensitive media. Can be
711 # 'default' (hide if sensitive), 'hide_all' or 'show_all'
712 'reading:expand:spoilers': # Boolean indicating whether the user wishes to expand
713 # content warnings by default
714 }
715
696App registration and user authentication 716App registration and user authentication
697---------------------------------------- 717----------------------------------------
698Before you can use the mastodon API, you have to register your 718Before you can use the mastodon API, you have to register your
@@ -878,6 +898,11 @@ Reading data: Endorsements
878 898
879.. automethod:: Mastodon.endorsements 899.. automethod:: Mastodon.endorsements
880 900
901Reading data: Preferences
902--------------------------
903
904.. automethod:: Mastodon.preferences
905
881 906
882Writing data: Statuses 907Writing data: Statuses
883---------------------- 908----------------------
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 3fe3d21..6b3de9a 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -180,6 +180,7 @@ class Mastodon:
180 __DICT_VERSION_FILTER = "2.4.3" 180 __DICT_VERSION_FILTER = "2.4.3"
181 __DICT_VERSION_CONVERSATION = bigger_version(bigger_version("2.6.0", __DICT_VERSION_ACCOUNT), __DICT_VERSION_STATUS) 181 __DICT_VERSION_CONVERSATION = bigger_version(bigger_version("2.6.0", __DICT_VERSION_ACCOUNT), __DICT_VERSION_STATUS)
182 __DICT_VERSION_SCHEDULED_STATUS = bigger_version("2.7.0", __DICT_VERSION_STATUS) 182 __DICT_VERSION_SCHEDULED_STATUS = bigger_version("2.7.0", __DICT_VERSION_STATUS)
183 __DICT_VERSION_PREFERENCES = "2.8.0"
183 184
184 ### 185 ###
185 # Registering apps 186 # Registering apps
@@ -1350,6 +1351,20 @@ class Mastodon:
1350 return self.__api_request('GET', '/api/v1/push/subscription') 1351 return self.__api_request('GET', '/api/v1/push/subscription')
1351 1352
1352 ### 1353 ###
1354 # Reading data: Preferences
1355 ###
1356 @api_version("2.8.0", "2.8.0", __DICT_VERSION_PREFERENCES)
1357 def preferences(self):
1358 """
1359 Fetch the users preferences, which can be used to set some default options.
1360 As of 2.8.0, apps can only fetch, not update preferences.
1361
1362 Returns a `preference dict`_.
1363
1364 """
1365 return self.__api_request('GET', '/api/v1/preferences')
1366
1367 ###
1353 # Writing data: Statuses 1368 # Writing data: Statuses
1354 ### 1369 ###
1355 @api_version("1.0.0", "2.7.0", __DICT_VERSION_STATUS) 1370 @api_version("1.0.0", "2.7.0", __DICT_VERSION_STATUS)
diff --git a/tests/cassettes/test_preferences.yaml b/tests/cassettes/test_preferences.yaml
new file mode 100644
index 0000000..e6e660f
--- /dev/null
+++ b/tests/cassettes/test_preferences.yaml
@@ -0,0 +1,30 @@
1interactions:
2- request:
3 body: null
4 headers:
5 Accept: ['*/*']
6 Accept-Encoding: ['gzip, deflate']
7 Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
8 Connection: [keep-alive]
9 User-Agent: [python-requests/2.18.4]
10 method: GET
11 uri: http://localhost:3000/api/v1/preferences
12 response:
13 body: {string: '{"posting:default:visibility":"public","posting:default:sensitive":false,"posting:default:language":null,"reading:expand:media":"default","reading:expand:spoilers":false}'}
14 headers:
15 Cache-Control: ['max-age=0, private, must-revalidate']
16 Content-Type: [application/json; charset=utf-8]
17 ETag: [W/"16e1b4c608ece78202df9c19d6a56932"]
18 Referrer-Policy: [strict-origin-when-cross-origin]
19 Transfer-Encoding: [chunked]
20 Vary: ['Accept-Encoding, Origin']
21 X-Content-Type-Options: [nosniff]
22 X-Download-Options: [noopen]
23 X-Frame-Options: [SAMEORIGIN]
24 X-Permitted-Cross-Domain-Policies: [none]
25 X-Request-Id: [0b19cc10-64ae-4fd4-827e-0e8e1b46c673]
26 X-Runtime: ['0.032833']
27 X-XSS-Protection: [1; mode=block]
28 content-length: ['170']
29 status: {code: 200, message: OK}
30version: 1
diff --git a/tests/test_account.py b/tests/test_account.py
index cd7633d..9821c13 100644
--- a/tests/test_account.py
+++ b/tests/test_account.py
@@ -205,4 +205,7 @@ def test_account_pin_unpin(api, api2):
205 assert not relationship['endorsed'] 205 assert not relationship['endorsed']
206 assert not user["id"] in map(lambda x: x["id"], endorsed2) 206 assert not user["id"] in map(lambda x: x["id"], endorsed2)
207 207
208 208@pytest.mark.vcr()
209def test_preferences(api):
210 prefs = api.preferences()
211 assert prefs
Powered by cgit v1.2.3 (git 2.41.0)