Merge pull request #385 from AlexKalopsia/master

Add API call for getting multiple accounts at once
pull/391/head
Lorenz Diener 2024-12-01 15:02:09 +02:00 zatwierdzone przez GitHub
commit 13725053a3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
4 zmienionych plików z 28 dodań i 7 usunięć

Wyświetl plik

@ -15,6 +15,7 @@ Reading
.. automethod:: Mastodon.account
.. automethod:: Mastodon.account_search
.. automethod:: Mastodon.account_lookup
.. automethod:: Mastodon.accounts
.. automethod:: Mastodon.featured_tags
.. automethod:: Mastodon.featured_tag_suggestions

Wyświetl plik

@ -51,6 +51,7 @@ Every function on a huge CTRL-F-able page
.. automethod:: Mastodon.account
.. automethod:: Mastodon.account_search
.. automethod:: Mastodon.account_lookup
.. automethod:: Mastodon.accounts
.. automethod:: Mastodon.featured_tags
.. automethod:: Mastodon.featured_tag_suggestions
.. automethod:: Mastodon.account_featured_tags

Wyświetl plik

@ -130,6 +130,16 @@ class Mastodon(Internals):
id = self.__unpack_id(id)
return self.__api_request('GET', f'/api/v1/accounts/{id}')
@api_version("4.3.0", "4.3.0", _DICT_VERSION_ACCOUNT)
def accounts(self, ids: List[Union[Account, IdType]]) -> List[Account]:
"""
Fetch information from multiple accounts by a list of user `id`.
Does not require authentication for publicly visible accounts.
"""
ids = [self.__unpack_id(id) for id in ids]
return self.__api_request('GET', '/api/v1/accounts', {"id[]": ids})
@api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
def account_verify_credentials(self) -> Account:
"""

Wyświetl plik

@ -8,6 +8,15 @@ def test_account(api):
account = api.account(api.account_verify_credentials())
assert account
@pytest.mark.vcr()
def test_accounts(api):
account_ids = [
api.account_lookup("mastodonpy_test").id,
api.account_lookup("mastodonpy_test_2").id
]
accounts = api.accounts(account_ids)
assert len(accounts) == 2
@pytest.mark.vcr()
def test_verify_credentials(api):
account_a = api.account_verify_credentials()