Add, test and document profile directory API (fixes #188)

This commit is contained in:
Lorenz Diener 2019-10-12 22:05:35 +02:00
pare 63bf5afc61
commit 1f36deb119
S'han modificat 5 arxius amb 67 adicions i 10 eliminacions

Veure arxiu

@ -263,12 +263,13 @@ User dicts
'header_static': # URL for their header image, never animated 'header_static': # URL for their header image, never animated
'source': # Additional information - only present for user dict returned 'source': # Additional information - only present for user dict returned
# from account_verify_credentials() # from account_verify_credentials()
'moved_to_account': # If set, an account dict of the account this user has 'moved_to_account': # If set, a user dict of the account this user has
# set up as their moved-to address. # set up as their moved-to address.
'bot': # Boolean indicating whether this account is automated. 'bot': # Boolean indicating whether this account is automated.
'fields': # List of up to four dicts with free-form 'name' and 'value' profile info. 'fields': # List of up to four dicts with free-form 'name' and 'value' profile info.
# For fields with "this is me" type verification, verified_at is set to the # For fields with "this is me" type verification, verified_at is set to the
# last verification date (It is None otherwise) # last verification date (It is None otherwise)
'emojis': # List of custom emoji used in name, bio or fields
} }
mastodon.account_verify_credentials()["source"] mastodon.account_verify_credentials()["source"]
@ -626,7 +627,7 @@ Search result dicts
mastodon.search("<query>") mastodon.search("<query>")
# Returns the following dictionary # Returns the following dictionary
{ {
'accounts': # List of account dicts resulting from the query 'accounts': # List of user dicts resulting from the query
'hashtags': # List of hashtag dicts resulting from the query 'hashtags': # List of hashtag dicts resulting from the query
'statuses': # List of toot dicts resulting from the query 'statuses': # List of toot dicts resulting from the query
} }
@ -651,7 +652,7 @@ Instance dicts
'stats: # A dictionary containing three stats, user_count (number of local users), 'stats: # A dictionary containing three stats, user_count (number of local users),
# status_count (number of local statuses) and domain_count (number of known # status_count (number of local statuses) and domain_count (number of known
# instance domains other than this one). # instance domains other than this one).
'contact_account': # Account dict of the primary contact for the instance 'contact_account': # User dict of the primary contact for the instance
'languages': # Array of ISO 639-1 (two-letter) language codes the instance 'languages': # Array of ISO 639-1 (two-letter) language codes the instance
# has chosen to advertise. # has chosen to advertise.
'registrations': # Boolean indication whether registrations on this instance are open 'registrations': # Boolean indication whether registrations on this instance are open
@ -691,11 +692,11 @@ Report dicts
'comment': # Text comment submitted with the report 'comment': # Text comment submitted with the report
'created_at': # Time at which this report was created, as a datetime object 'created_at': # Time at which this report was created, as a datetime object
'updated_at': # Last time this report has been updated, as a datetime object 'updated_at': # Last time this report has been updated, as a datetime object
'account': # Account dict of the user that filed this report 'account': # User dict of the user that filed this report
'target_account': # Account that has been reported with this report 'target_account': # Account that has been reported with this report
'assigned_account': # If the report as been assigned to an account, 'assigned_account': # If the report as been assigned to an account,
# account dict of that account (None if not) # User dict of that account (None if not)
'action_taken_by_account': # Account dict of the account that processed this report 'action_taken_by_account': # User dict of the account that processed this report
'statuses': # List of statuses attached to the report, as toot dicts 'statuses': # List of statuses attached to the report, as toot dicts
} }
@ -796,7 +797,7 @@ Admin account dicts
'locale': # For local users, the locale the user has set, 'locale': # For local users, the locale the user has set,
'invite_request': # If the user requested an invite, the invite request comment of that user. (TODO permanent?) 'invite_request': # If the user requested an invite, the invite request comment of that user. (TODO permanent?)
'invited_by_account_id': # Present if the user was invited by another user and set to the inviting users id. 'invited_by_account_id': # Present if the user was invited by another user and set to the inviting users id.
'account': # The users account, as a standard account dict 'account': # The users account, as a standard user dict
} }
App registration and user authentication App registration and user authentication
@ -942,6 +943,11 @@ Reading data: Follow suggestions
.. automethod:: Mastodon.suggestions .. automethod:: Mastodon.suggestions
Reading data: Profile directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. authomethod:: Mastodon.directory
Reading data: Lists Reading data: Lists
------------------- -------------------
These functions allow you to view information about lists. These functions allow you to view information about lists.

Veure arxiu

@ -1238,6 +1238,19 @@ class Mastodon:
""" """
return self.__api_request('GET', '/api/v1/suggestions') return self.__api_request('GET', '/api/v1/suggestions')
###
# Reading data: Follow suggestions
###
@api_version("3.0.0", "3.0.0", __DICT_VERSION_ACCOUNT)
def directory(self):
"""
Fetch the contents of the profile directory, if enabled on the server.
Returns a list of `user dicts`_.
"""
return self.__api_request('GET', '/api/v1/directory')
### ###
# Reading data: Endorsements # Reading data: Endorsements
### ###

Veure arxiu

@ -0,0 +1,29 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
User-Agent: [python-requests/2.18.4]
method: GET
uri: http://localhost:3000/api/v1/directory
response:
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":[]}]'}
headers:
Cache-Control: ['no-cache, no-store']
Content-Type: [application/json; charset=utf-8]
Referrer-Policy: [strict-origin-when-cross-origin]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Download-Options: [noopen]
X-Frame-Options: [SAMEORIGIN]
X-Permitted-Cross-Domain-Policies: [none]
X-Request-Id: [fedf048d-8ed4-4185-bcb4-11384f0db697]
X-Runtime: ['0.141196']
X-XSS-Protection: [1; mode=block]
content-length: ['597']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -46,13 +46,15 @@ INSERT INTO accounts (
username, username,
locked, locked,
created_at, created_at,
updated_at updated_at,
discoverable
) VALUES ( ) VALUES (
1234567890123457, 1234567890123457,
'mastodonpy_test_2', 'mastodonpy_test_2',
't', 't',
now(), now(),
now() now(),
t
); );
INSERT INTO users ( INSERT INTO users (

Veure arxiu

@ -43,8 +43,15 @@ def test_nodeinfo(api):
assert nodeinfo assert nodeinfo
assert nodeinfo.version == '2.0' assert nodeinfo.version == '2.0'
@pytest.mark.vcr() @pytest.mark.vcr()
def test_trends(api): def test_trends(api):
assert isinstance(api.trends(), list) assert isinstance(api.trends(), list)
@pytest.mark.vcr()
def test_directory(api):
directory = api.directory()
assert directory
assert isinstance(directory, list)
assert len(directory) > 0