Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API call for getting multiple accounts at once #385

Merged
merged 3 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/06_accounts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions docs/15_everything.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Every function on a huge CTRL-F-able page
=========================================
.. py:module:: mastodon
.. py:class: Mastodon

Every function on a huge CTRL-F-able page
=========================================
.. py:module:: mastodon
.. py:class: Mastodon
.. automethod:: Mastodon.retrieve_mastodon_version
.. automethod:: Mastodon.verify_minimum_version
.. automethod:: Mastodon.create_app
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -184,5 +185,5 @@ Every function on a huge CTRL-F-able page
.. automethod:: Mastodon.admin_delete_domain_block
.. automethod:: Mastodon.admin_measures
.. automethod:: Mastodon.admin_dimensions
.. automethod:: Mastodon.admin_retention

.. automethod:: Mastodon.admin_retention
10 changes: 10 additions & 0 deletions mastodon/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ def account(self, id: Union[Account, IdType]) -> Account:
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:
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down