feat: added get_users method
Some checks failed
Pylint / Pylint (3.12) (push) Failing after 39s

This commit is contained in:
Seaswimmer 2023-12-22 13:51:42 -05:00
parent 63258d6dea
commit a674eabf89
Signed by: cswimr
GPG key ID: 1EBC234EEDA901AE

View file

@ -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