2022-11-30 23:39:08 +00:00
|
|
|
# list.py - list endpoints
|
|
|
|
|
2023-06-19 21:35:03 +00:00
|
|
|
from mastodon.versions import _DICT_VERSION_LIST, _DICT_VERSION_ACCOUNT
|
|
|
|
from mastodon.utility import api_version
|
2022-11-30 23:39:08 +00:00
|
|
|
|
2023-06-19 21:35:03 +00:00
|
|
|
from mastodon.internals import Mastodon as Internals
|
|
|
|
from mastodon.types import NonPaginatableList, UserList, IdType, PaginatableList, Account
|
2022-11-30 23:39:08 +00:00
|
|
|
|
2023-06-19 21:35:03 +00:00
|
|
|
from typing import List, Union, Optional
|
2023-01-02 13:39:16 +00:00
|
|
|
|
2022-11-30 23:39:08 +00:00
|
|
|
class Mastodon(Internals):
|
|
|
|
###
|
|
|
|
# Reading data: Lists
|
|
|
|
###
|
|
|
|
@api_version("2.1.0", "2.1.0", _DICT_VERSION_LIST)
|
2023-06-19 21:35:03 +00:00
|
|
|
def lists(self) -> NonPaginatableList[UserList]:
|
2022-11-30 23:39:08 +00:00
|
|
|
"""
|
|
|
|
Fetch a list of all the Lists by the logged-in user.
|
|
|
|
"""
|
|
|
|
return self.__api_request('GET', '/api/v1/lists')
|
|
|
|
|
|
|
|
@api_version("2.1.0", "2.1.0", _DICT_VERSION_LIST)
|
2023-06-19 21:35:03 +00:00
|
|
|
def list(self, id: Union[UserList, IdType]) -> UserList:
|
2022-11-30 23:39:08 +00:00
|
|
|
"""
|
|
|
|
Fetch info about a specific list.
|
|
|
|
"""
|
|
|
|
id = self.__unpack_id(id)
|
2022-12-02 21:04:23 +00:00
|
|
|
return self.__api_request('GET', f'/api/v1/lists/{id}')
|
2022-11-30 23:39:08 +00:00
|
|
|
|
|
|
|
@api_version("2.1.0", "2.6.0", _DICT_VERSION_ACCOUNT)
|
2023-06-19 21:35:03 +00:00
|
|
|
def list_accounts(self, id: Union[UserList, IdType], max_id: Optional[Union[UserList, IdType]] = None,
|
|
|
|
min_id: Optional[Union[UserList, IdType]] = None, since_id: Optional[Union[UserList, IdType]] = None,
|
|
|
|
limit: Optional[int] = None) -> PaginatableList[Account]:
|
2022-11-30 23:39:08 +00:00
|
|
|
"""
|
|
|
|
Get the accounts that are on the given list.
|
|
|
|
"""
|
|
|
|
id = self.__unpack_id(id)
|
|
|
|
|
|
|
|
if max_id is not None:
|
2023-06-19 21:35:03 +00:00
|
|
|
max_id = self.__unpack_id(max_id)
|
2022-11-30 23:39:08 +00:00
|
|
|
|
|
|
|
if min_id is not None:
|
2023-06-19 21:35:03 +00:00
|
|
|
min_id = self.__unpack_id(min_id)
|
2022-11-30 23:39:08 +00:00
|
|
|
|
|
|
|
if since_id is not None:
|
2023-06-19 21:35:03 +00:00
|
|
|
since_id = self.__unpack_id(since_id)
|
2022-11-30 23:39:08 +00:00
|
|
|
|
|
|
|
params = self.__generate_params(locals(), ['id'])
|
2023-02-07 21:50:23 +00:00
|
|
|
return self.__api_request('GET', f'/api/v1/lists/{id}/accounts', params)
|
2022-11-30 23:39:08 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
# Writing data: Lists
|
|
|
|
###
|
|
|
|
@api_version("2.1.0", "2.1.0", _DICT_VERSION_LIST)
|
2023-06-19 21:35:03 +00:00
|
|
|
def list_create(self, title: str) -> UserList:
|
2022-11-30 23:39:08 +00:00
|
|
|
"""
|
|
|
|
Create a new list with the given `title`.
|
|
|
|
"""
|
|
|
|
params = self.__generate_params(locals())
|
|
|
|
return self.__api_request('POST', '/api/v1/lists', params)
|
|
|
|
|
|
|
|
@api_version("2.1.0", "2.1.0", _DICT_VERSION_LIST)
|
2023-06-19 21:35:03 +00:00
|
|
|
def list_update(self, id: Union[UserList, IdType], title: str) -> UserList:
|
2022-11-30 23:39:08 +00:00
|
|
|
"""
|
|
|
|
Update info about a list, where "info" is really the lists `title`.
|
|
|
|
|
2023-06-19 21:35:03 +00:00
|
|
|
The returned object reflects the updated list.
|
2022-11-30 23:39:08 +00:00
|
|
|
"""
|
|
|
|
id = self.__unpack_id(id)
|
|
|
|
params = self.__generate_params(locals(), ['id'])
|
2022-12-02 21:04:23 +00:00
|
|
|
return self.__api_request('PUT', f'/api/v1/lists/{id}', params)
|
2022-11-30 23:39:08 +00:00
|
|
|
|
|
|
|
@api_version("2.1.0", "2.1.0", "2.1.0")
|
2023-06-19 21:35:03 +00:00
|
|
|
def list_delete(self, id: Union[UserList, IdType]):
|
2022-11-30 23:39:08 +00:00
|
|
|
"""
|
|
|
|
Delete a list.
|
|
|
|
"""
|
|
|
|
id = self.__unpack_id(id)
|
2022-12-02 21:04:23 +00:00
|
|
|
self.__api_request('DELETE', f'/api/v1/lists/{id}')
|
2022-11-30 23:39:08 +00:00
|
|
|
|
|
|
|
@api_version("2.1.0", "2.1.0", "2.1.0")
|
2023-06-19 21:35:03 +00:00
|
|
|
def list_accounts_add(self, id: Union[UserList, IdType], account_ids: List[Union[Account, IdType]]):
|
2022-11-30 23:39:08 +00:00
|
|
|
"""
|
|
|
|
Add the account(s) given in `account_ids` to the list.
|
|
|
|
"""
|
|
|
|
id = self.__unpack_id(id)
|
2023-06-19 21:35:03 +00:00
|
|
|
account_ids = self.__unpack_id(account_ids, listify = True)
|
2022-11-30 23:39:08 +00:00
|
|
|
|
|
|
|
params = self.__generate_params(locals(), ['id'])
|
2022-12-02 21:04:23 +00:00
|
|
|
self.__api_request('POST', f'/api/v1/lists/{id}/accounts', params)
|
2022-11-30 23:39:08 +00:00
|
|
|
|
|
|
|
@api_version("2.1.0", "2.1.0", "2.1.0")
|
2023-06-19 21:35:03 +00:00
|
|
|
def list_accounts_delete(self, id: Union[UserList, IdType], account_ids: List[Union[Account, IdType]]):
|
2022-11-30 23:39:08 +00:00
|
|
|
"""
|
|
|
|
Remove the account(s) given in `account_ids` from the list.
|
|
|
|
"""
|
|
|
|
id = self.__unpack_id(id)
|
2023-06-19 21:35:03 +00:00
|
|
|
account_ids = self.__unpack_id(account_ids, listify = True)
|
2022-11-30 23:39:08 +00:00
|
|
|
params = self.__generate_params(locals(), ['id'])
|
2023-01-02 13:39:16 +00:00
|
|
|
self.__api_request('DELETE', f'/api/v1/lists/{id}/accounts', params)
|