PyZipline/pyzipline/zipline.py
SeaswimmerTheFsh 6cc8a2dd0b
Some checks failed
Pylint / Pylint (3.12) (push) Failing after 35s
updating docs more
2023-12-20 14:28:15 -05:00

45 lines
1.8 KiB
Python

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.
All API requests should be made through this class.
Args:
hostname (str): The hostname of your Zipline instance, WITHOUT https or http.
token (str = None): String used for authentication when making requests.
ssl (bool = True): Normally set to True, but if your Zipline instance doesn't use SSL/TLS, set this to False.
enforced_signing (bool = True): Normally set to True, but if having SSL/TLS cert validation issues, can turn off with False.
logger (logging.Logger = None): If your app has a logger, pass it in here.
"""
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
user_id (int): Integer ID of the user to retrieve
:return: The :class:`pyzipline.models.User` object matching the ID
:rtype: :class:`pyzipline.models.User`
"""
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: `pyzipline.models.User`object matching the authenticated user
:rtype: `pyzipline.models.User`
"""
result = self._rest_adapter.get(endpoint=f"user")
return User(**result.data)