diff --git a/pyzipline/zipline.py b/pyzipline/zipline.py index dad563a..97aa588 100644 --- a/pyzipline/zipline.py +++ b/pyzipline/zipline.py @@ -1,9 +1,11 @@ """This module contains the ZiplineApi class, which is the main class used to interact with the Zipline API.""" +from datetime import datetime, timedelta from typing import Union, List import logging from pyzipline.rest_adapter import RestAdapter -from pyzipline.exceptions import PyZiplineError, FeatureDisabledError, Forbidden -from pyzipline.models import User, Result, Stats, Version +from pyzipline.exceptions import PyZiplineError, FeatureDisabledError, Forbidden, NotFound +from pyzipline.models import User, File, Result, Invite, Stats, Version +from pyzipline.utils import convert_datetime_to_str # pylint: disable=not-a-mapping class ZiplineApi: @@ -298,6 +300,31 @@ class ZiplineApi: raise Forbidden(result.message) raise PyZiplineError(f"{result.status_code}: {result.message}\n{result.data}") + def get_users(self) -> list[User]: + """Get a list of users + + /// admonition | Requires Administrator + type: danger + /// + + Raises: + Forbidden: Raised if the authenticated user is not an administrator + PyZiplineError: Raised if the API changes, causing a breaking change in this method + + Returns: + list[User]: List of users + """ + result = self._rest_adapter.get(endpoint="users") + if result.status_code == 200: + users = [] + for user in result.data: + u = User(**user) + users.append(u) + return users + if result.status_code == 403: + raise Forbidden(result.message) + raise PyZiplineError(f"{result.status_code}: {result.message}\n{result.data}") + def get_stats(self, amount: int = 1, force_update: bool = False) -> Union[Stats, List[Stats]]: """Get statistics about the Zipline instance