2023-12-19 05:36:18 -05:00
|
|
|
import logging
|
|
|
|
from pyzipline.rest_adapter import RestAdapter
|
|
|
|
from pyzipline.errors import PyZiplineError
|
|
|
|
from pyzipline.models import *
|
|
|
|
|
|
|
|
class ZiplineApi:
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
hostname: str,
|
|
|
|
token: str = '',
|
|
|
|
ssl: bool = True,
|
|
|
|
enforced_signing: bool = True,
|
|
|
|
logger: logging.Logger = None
|
|
|
|
):
|
|
|
|
"""Constructor for ZiplineApi
|
|
|
|
|
|
|
|
:param hostname: The hostname of your Zipline instance, WITHOUT https or http.
|
2023-12-19 05:54:49 -05:00
|
|
|
:type hostname: str
|
2023-12-19 05:36:18 -05:00
|
|
|
:param token: (optional) String used for authentication when making requests.
|
2023-12-19 05:54:49 -05:00
|
|
|
:type token: str
|
2023-12-19 05:36:18 -05:00
|
|
|
:param ssl: (optional) Normally set to True, but if your Zipline instance doesn't use SSL/TLS, set this to False.
|
2023-12-19 05:54:49 -05:00
|
|
|
:type ssl: bool
|
2023-12-19 05:36:18 -05:00
|
|
|
:param enforced_signing: (optional) Normally set to True, but if having SSL/TLS cert validation issues, can turn off with False.
|
2023-12-19 05:54:49 -05:00
|
|
|
:type enforced_signing: bool
|
2023-12-19 05:36:18 -05:00
|
|
|
:param logger: (optional) If your app has a logger, pass it in here.
|
2023-12-19 05:54:49 -05:00
|
|
|
:type logger: logging.Logger
|
2023-12-19 05:36:18 -05:00
|
|
|
"""
|
|
|
|
self._rest_adapter = RestAdapter(hostname=hostname, token=token, ssl=ssl, enforced_signing=enforced_signing, logger=logger)
|
|
|
|
|
|
|
|
def get_user(self, user_id: int) -> User:
|
|
|
|
"""Get a user by ID
|
|
|
|
|
|
|
|
:param user_id: Integer ID of the user
|
2023-12-19 05:54:49 -05:00
|
|
|
:type user_id: int
|
2023-12-19 05:36:18 -05:00
|
|
|
:return: User object
|
2023-12-19 05:54:49 -05:00
|
|
|
:rtype: User
|
2023-12-19 05:36:18 -05:00
|
|
|
"""
|
|
|
|
result = self._rest_adapter.get(endpoint=f"user/{user_id}")
|
|
|
|
return User(**result.data)
|
|
|
|
|
|
|
|
def get_self(self) -> User:
|
|
|
|
"""Get the currently authenticated user
|
|
|
|
|
|
|
|
:return: User object
|
2023-12-19 05:54:49 -05:00
|
|
|
:rtype: User
|
2023-12-19 05:36:18 -05:00
|
|
|
"""
|
|
|
|
result = self._rest_adapter.get(endpoint=f"user")
|
|
|
|
return User(**result.data)
|