This commit is contained in:
parent
63258d6dea
commit
a674eabf89
1 changed files with 29 additions and 2 deletions
|
@ -1,9 +1,11 @@
|
||||||
"""This module contains the ZiplineApi class, which is the main class used to interact with the Zipline API."""
|
"""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
|
from typing import Union, List
|
||||||
import logging
|
import logging
|
||||||
from pyzipline.rest_adapter import RestAdapter
|
from pyzipline.rest_adapter import RestAdapter
|
||||||
from pyzipline.exceptions import PyZiplineError, FeatureDisabledError, Forbidden
|
from pyzipline.exceptions import PyZiplineError, FeatureDisabledError, Forbidden, NotFound
|
||||||
from pyzipline.models import User, Result, Stats, Version
|
from pyzipline.models import User, File, Result, Invite, Stats, Version
|
||||||
|
from pyzipline.utils import convert_datetime_to_str
|
||||||
|
|
||||||
# pylint: disable=not-a-mapping
|
# pylint: disable=not-a-mapping
|
||||||
class ZiplineApi:
|
class ZiplineApi:
|
||||||
|
@ -298,6 +300,31 @@ class ZiplineApi:
|
||||||
raise Forbidden(result.message)
|
raise Forbidden(result.message)
|
||||||
raise PyZiplineError(f"{result.status_code}: {result.message}\n{result.data}")
|
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]]:
|
def get_stats(self, amount: int = 1, force_update: bool = False) -> Union[Stats, List[Stats]]:
|
||||||
"""Get statistics about the Zipline instance
|
"""Get statistics about the Zipline instance
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue