aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/index.rst20
-rw-r--r--mastodon/Mastodon.py13
-rw-r--r--tests/cassettes/test_directory.yaml29
-rw-r--r--tests/setup.sql6
-rw-r--r--tests/test_instance.py9
5 files changed, 67 insertions, 10 deletions
diff --git a/docs/index.rst b/docs/index.rst
index b9fcde1..ef94b2a 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -263,12 +263,13 @@ User dicts
263 'header_static': # URL for their header image, never animated 263 'header_static': # URL for their header image, never animated
264 'source': # Additional information - only present for user dict returned 264 'source': # Additional information - only present for user dict returned
265 # from account_verify_credentials() 265 # from account_verify_credentials()
266 'moved_to_account': # If set, an account dict of the account this user has 266 'moved_to_account': # If set, a user dict of the account this user has
267 # set up as their moved-to address. 267 # set up as their moved-to address.
268 'bot': # Boolean indicating whether this account is automated. 268 'bot': # Boolean indicating whether this account is automated.
269 'fields': # List of up to four dicts with free-form 'name' and 'value' profile info. 269 'fields': # List of up to four dicts with free-form 'name' and 'value' profile info.
270 # For fields with "this is me" type verification, verified_at is set to the 270 # For fields with "this is me" type verification, verified_at is set to the
271 # last verification date (It is None otherwise) 271 # last verification date (It is None otherwise)
272 'emojis': # List of custom emoji used in name, bio or fields
272 } 273 }
273 274
274 mastodon.account_verify_credentials()["source"] 275 mastodon.account_verify_credentials()["source"]
@@ -626,7 +627,7 @@ Search result dicts
626 mastodon.search("<query>") 627 mastodon.search("<query>")
627 # Returns the following dictionary 628 # Returns the following dictionary
628 { 629 {
629 'accounts': # List of account dicts resulting from the query 630 'accounts': # List of user dicts resulting from the query
630 'hashtags': # List of hashtag dicts resulting from the query 631 'hashtags': # List of hashtag dicts resulting from the query
631 'statuses': # List of toot dicts resulting from the query 632 'statuses': # List of toot dicts resulting from the query
632 } 633 }
@@ -651,7 +652,7 @@ Instance dicts
651 'stats: # A dictionary containing three stats, user_count (number of local users), 652 'stats: # A dictionary containing three stats, user_count (number of local users),
652 # status_count (number of local statuses) and domain_count (number of known 653 # status_count (number of local statuses) and domain_count (number of known
653 # instance domains other than this one). 654 # instance domains other than this one).
654 'contact_account': # Account dict of the primary contact for the instance 655 'contact_account': # User dict of the primary contact for the instance
655 'languages': # Array of ISO 639-1 (two-letter) language codes the instance 656 'languages': # Array of ISO 639-1 (two-letter) language codes the instance
656 # has chosen to advertise. 657 # has chosen to advertise.
657 'registrations': # Boolean indication whether registrations on this instance are open 658 'registrations': # Boolean indication whether registrations on this instance are open
@@ -691,11 +692,11 @@ Report dicts
691 'comment': # Text comment submitted with the report 692 'comment': # Text comment submitted with the report
692 'created_at': # Time at which this report was created, as a datetime object 693 'created_at': # Time at which this report was created, as a datetime object
693 'updated_at': # Last time this report has been updated, as a datetime object 694 'updated_at': # Last time this report has been updated, as a datetime object
694 'account': # Account dict of the user that filed this report 695 'account': # User dict of the user that filed this report
695 'target_account': # Account that has been reported with this report 696 'target_account': # Account that has been reported with this report
696 'assigned_account': # If the report as been assigned to an account, 697 'assigned_account': # If the report as been assigned to an account,
697 # account dict of that account (None if not) 698 # User dict of that account (None if not)
698 'action_taken_by_account': # Account dict of the account that processed this report 699 'action_taken_by_account': # User dict of the account that processed this report
699 'statuses': # List of statuses attached to the report, as toot dicts 700 'statuses': # List of statuses attached to the report, as toot dicts
700 } 701 }
701 702
@@ -796,7 +797,7 @@ Admin account dicts
796 'locale': # For local users, the locale the user has set, 797 'locale': # For local users, the locale the user has set,
797 'invite_request': # If the user requested an invite, the invite request comment of that user. (TODO permanent?) 798 'invite_request': # If the user requested an invite, the invite request comment of that user. (TODO permanent?)
798 'invited_by_account_id': # Present if the user was invited by another user and set to the inviting users id. 799 'invited_by_account_id': # Present if the user was invited by another user and set to the inviting users id.
799 'account': # The users account, as a standard account dict 800 'account': # The users account, as a standard user dict
800 } 801 }
801 802
802App registration and user authentication 803App registration and user authentication
@@ -942,6 +943,11 @@ Reading data: Follow suggestions
942 943
943.. automethod:: Mastodon.suggestions 944.. automethod:: Mastodon.suggestions
944 945
946Reading data: Profile directory
947~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
948
949.. authomethod:: Mastodon.directory
950
945Reading data: Lists 951Reading data: Lists
946------------------- 952-------------------
947These functions allow you to view information about lists. 953These functions allow you to view information about lists.
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 9c6f1ce..d07bae7 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1239,6 +1239,19 @@ class Mastodon:
1239 return self.__api_request('GET', '/api/v1/suggestions') 1239 return self.__api_request('GET', '/api/v1/suggestions')
1240 1240
1241 ### 1241 ###
1242 # Reading data: Follow suggestions
1243 ###
1244 @api_version("3.0.0", "3.0.0", __DICT_VERSION_ACCOUNT)
1245 def directory(self):
1246 """
1247 Fetch the contents of the profile directory, if enabled on the server.
1248
1249 Returns a list of `user dicts`_.
1250
1251 """
1252 return self.__api_request('GET', '/api/v1/directory')
1253
1254 ###
1242 # Reading data: Endorsements 1255 # Reading data: Endorsements
1243 ### 1256 ###
1244 @api_version("2.5.0", "2.5.0", __DICT_VERSION_ACCOUNT) 1257 @api_version("2.5.0", "2.5.0", __DICT_VERSION_ACCOUNT)
diff --git a/tests/cassettes/test_directory.yaml b/tests/cassettes/test_directory.yaml
new file mode 100644
index 0000000..6c478e3
--- /dev/null
+++ b/tests/cassettes/test_directory.yaml
@@ -0,0 +1,29 @@
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/directory
12 response:
13 body: {string: '[{"id":"1234567890123457","username":"mastodonpy_test_2","acct":"mastodonpy_test_2","display_name":"","locked":true,"bot":false,"created_at":"2019-06-22T23:11:52.445Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost/@mastodonpy_test_2","avatar":"http://localhost/avatars/original/missing.png","avatar_static":"http://localhost/avatars/original/missing.png","header":"http://localhost/headers/original/missing.png","header_static":"http://localhost/headers/original/missing.png","followers_count":0,"following_count":0,"statuses_count":0,"last_status_at":null,"emojis":[],"fields":[]}]'}
14 headers:
15 Cache-Control: ['no-cache, no-store']
16 Content-Type: [application/json; charset=utf-8]
17 Referrer-Policy: [strict-origin-when-cross-origin]
18 Transfer-Encoding: [chunked]
19 Vary: ['Accept-Encoding, Origin']
20 X-Content-Type-Options: [nosniff]
21 X-Download-Options: [noopen]
22 X-Frame-Options: [SAMEORIGIN]
23 X-Permitted-Cross-Domain-Policies: [none]
24 X-Request-Id: [fedf048d-8ed4-4185-bcb4-11384f0db697]
25 X-Runtime: ['0.141196']
26 X-XSS-Protection: [1; mode=block]
27 content-length: ['597']
28 status: {code: 200, message: OK}
29version: 1
diff --git a/tests/setup.sql b/tests/setup.sql
index 74b1d80..0230655 100644
--- a/tests/setup.sql
+++ b/tests/setup.sql
@@ -46,13 +46,15 @@ INSERT INTO accounts (
46 username, 46 username,
47 locked, 47 locked,
48 created_at, 48 created_at,
49 updated_at 49 updated_at,
50 discoverable
50) VALUES ( 51) VALUES (
51 1234567890123457, 52 1234567890123457,
52 'mastodonpy_test_2', 53 'mastodonpy_test_2',
53 't', 54 't',
54 now(), 55 now(),
55 now() 56 now(),
57 t
56); 58);
57 59
58INSERT INTO users ( 60INSERT INTO users (
diff --git a/tests/test_instance.py b/tests/test_instance.py
index e7dee1f..2762ecb 100644
--- a/tests/test_instance.py
+++ b/tests/test_instance.py
@@ -43,8 +43,15 @@ def test_nodeinfo(api):
43 assert nodeinfo 43 assert nodeinfo
44 assert nodeinfo.version == '2.0' 44 assert nodeinfo.version == '2.0'
45 45
46
47@pytest.mark.vcr() 46@pytest.mark.vcr()
48def test_trends(api): 47def test_trends(api):
49 assert isinstance(api.trends(), list) 48 assert isinstance(api.trends(), list)
50 49
50@pytest.mark.vcr()
51def test_directory(api):
52 directory = api.directory()
53 assert directory
54 assert isinstance(directory, list)
55 assert len(directory) > 0
56
57
Powered by cgit v1.2.3 (git 2.41.0)