─░├žeri─če ge├ž

Referans i├žin hub_sdk/modules/users.py

Not

Bu dosya https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/modules/users .py adresinde mevcuttur. Bir sorun tespit ederseniz, l├╝tfen bir ├çekme ─░ste─či ­čŤá´ŞĆ ile katk─▒da bulunarak d├╝zeltmeye yard─▒mc─▒ olun. Te┼čekk├╝rler ­čÖĆ!



hub_sdk.modules.users.Users

├ťsler: CRUDClient

CRUD i┼člemleri arac─▒l─▒─č─▒yla Kullan─▒c─▒larla etkile┼čim i├žin bir istemciyi temsil eden bir s─▒n─▒f. Bu s─▒n─▒f CRUDClient'─▒ geni┼čletir s─▒n─▒f─▒n─▒ olu┼čturur ve Kullan─▒c─▒lar ile ├žal─▒┼čmak i├žin ├Âzel y├Ântemler sa─člar.

Nitelikler:

─░sim Tip A├ž─▒klama
id (str, None)

Varsa, kullan─▒c─▒n─▒n benzersiz tan─▒mlay─▒c─▒s─▒.

data dict

Kullan─▒c─▒ verilerini saklamak i├žin bir s├Âzl├╝k.

Not

'id' ├Âzniteli─či ba┼člatma s─▒ras─▒nda ayarlan─▒r ve bir kullan─▒c─▒y─▒ benzersiz bir ┼čekilde tan─▒mlamak i├žin kullan─▒labilir. 'data' ├Âzniteli─či, API'den al─▒nan kullan─▒c─▒ verilerini saklamak i├žin kullan─▒l─▒r.

Kaynak kodu hub_sdk/modules/users.py
class Users(CRUDClient):
    """
    A class representing a client for interacting with Users through CRUD operations. This class extends the CRUDClient
    class and provides specific methods for working with Users.

    Attributes:
        id (str, None): The unique identifier of the user, if available.
        data (dict): A dictionary to store user data.

    Note:
        The 'id' attribute is set during initialization and can be used to uniquely identify a user.
        The 'data' attribute is used to store user data fetched from the API.
    """

    def __init__(self, user_id: Optional[str] = None, headers: Optional[Dict[str, Any]] = None) -> None:
        """
        Initialize a Users object for interacting with user data via CRUD operations.

        Args:
            user_id (str, optional): The unique identifier of the user.
            headers (dict, optional): A dictionary of HTTP headers to be included in API requests.
        """
        super().__init__("users", "user", headers)
        self.id = user_id
        self.data = {}
        if user_id:
            self.get_data()

    def get_data(self) -> None:
        """
        Retrieves data for the current user instance.

        If a valid user ID has been set, it sends a request to fetch the user data and stores it in the instance.
        If no user ID has been set, it logs an error message.

        Returns:
            (None): The method does not return a value.
        """
        if not self.id:
            self.logger.error("No user id has been set. Update the user id or create a user.")
            return

        try:
            response = super().read(self.id)

            if response is None:
                self.logger.error(f"Received no response from the server for user ID: {self.id}")
                return

            # Check if the response has a .json() method (it should if it's a response object)
            if not hasattr(response, "json"):
                self.logger.error(f"Invalid response object received for user ID: {self.id}")
                return

            resp_data = response.json()
            if resp_data is None:
                self.logger.error(f"No data received in the response for user ID: {self.id}")
                return

            data = resp_data.get("data", {})
            self.data = self._reconstruct_data(data)
            self.logger.debug(f"User data retrieved for ID: {self.id}")

        except Exception as e:
            self.logger.error(f"An error occurred while retrieving data for user ID: {self.id}, {str(e)}")

    def create_user(self, user_data: dict) -> None:
        """
        Creates a new user with the provided data and sets the user ID for the current instance.

        Args:
            user_data (dict): A dictionary containing the data for creating the user.

        Returns:
            (None): The method does not return a value.
        """
        resp = super().create(user_data).json()
        self.id = resp.get("data", {}).get("id")
        self.get_data()

    def delete(self, hard: bool = False) -> Optional[Response]:
        """
        Delete the user resource represented by this instance.

        Args:
            hard (bool, optional): If True, perform a hard delete.

        Note:
            The 'hard' parameter determines whether to perform a soft delete (default) or a hard delete.
            In a soft delete, the model might be marked as deleted but retained in the system.
            In a hard delete, the model is permanently removed from the system.

        Returns:
            (Optional[Response]): Response object from the delete request, or None if delete fails
        """
        return super().delete(self.id, hard)

    def update(self, data: dict) -> Optional[Response]:
        """
        Update the user resource represented by this instance.

        Args:
            data (dict): The updated data for the user resource.

        Returns:
            (Optional[Response]): Response object from the update request, or None if update fails
        """
        return super().update(self.id, data)

__init__(user_id=None, headers=None)

CRUD i┼člemleri arac─▒l─▒─č─▒yla kullan─▒c─▒ verileriyle etkile┼čim i├žin bir Users nesnesini ba┼člat─▒n.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
user_id str

Kullan─▒c─▒n─▒n benzersiz tan─▒mlay─▒c─▒s─▒.

None
headers dict

API isteklerine dahil edilecek HTTP ├╝stbilgileri s├Âzl├╝─č├╝.

None
Kaynak kodu hub_sdk/modules/users.py
def __init__(self, user_id: Optional[str] = None, headers: Optional[Dict[str, Any]] = None) -> None:
    """
    Initialize a Users object for interacting with user data via CRUD operations.

    Args:
        user_id (str, optional): The unique identifier of the user.
        headers (dict, optional): A dictionary of HTTP headers to be included in API requests.
    """
    super().__init__("users", "user", headers)
    self.id = user_id
    self.data = {}
    if user_id:
        self.get_data()

create_user(user_data)

Sa─članan verilerle yeni bir kullan─▒c─▒ olu┼čturur ve ge├žerli ├Ârnek i├žin kullan─▒c─▒ kimli─čini ayarlar.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
user_data dict

Kullan─▒c─▒y─▒ olu┼čturmak i├žin gerekli verileri i├žeren bir s├Âzl├╝k.

gerekli

─░ade:

Tip A├ž─▒klama
None

Y├Ântem bir de─čer d├Ând├╝rmez.

Kaynak kodu hub_sdk/modules/users.py
def create_user(self, user_data: dict) -> None:
    """
    Creates a new user with the provided data and sets the user ID for the current instance.

    Args:
        user_data (dict): A dictionary containing the data for creating the user.

    Returns:
        (None): The method does not return a value.
    """
    resp = super().create(user_data).json()
    self.id = resp.get("data", {}).get("id")
    self.get_data()

delete(hard=False)

Bu ├Ârnek taraf─▒ndan temsil edilen kullan─▒c─▒ kayna─č─▒n─▒ siler.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
hard bool

True ise, sert bir silme i┼člemi ger├žekle┼čtirin.

False
Not

'hard' parametresi yumu┼čak silme mi (varsay─▒lan) yoksa sert silme mi yap─▒laca─č─▒n─▒ belirler. Yumu┼čak silme i┼čleminde, model silinmi┼č olarak i┼čaretlenebilir ancak sistemde tutulabilir. Sert silme i┼čleminde model sistemden kal─▒c─▒ olarak kald─▒r─▒l─▒r.

─░ade:

Tip A├ž─▒klama
Optional[Response]

Silme iste─činden gelen yan─▒t nesnesi veya silme ba┼čar─▒s─▒z olursa Yok

Kaynak kodu hub_sdk/modules/users.py
def delete(self, hard: bool = False) -> Optional[Response]:
    """
    Delete the user resource represented by this instance.

    Args:
        hard (bool, optional): If True, perform a hard delete.

    Note:
        The 'hard' parameter determines whether to perform a soft delete (default) or a hard delete.
        In a soft delete, the model might be marked as deleted but retained in the system.
        In a hard delete, the model is permanently removed from the system.

    Returns:
        (Optional[Response]): Response object from the delete request, or None if delete fails
    """
    return super().delete(self.id, hard)

get_data()

Ge├žerli kullan─▒c─▒ ├Ârne─či i├žin verileri al─▒r.

Ge├žerli bir kullan─▒c─▒ kimli─či ayarlanm─▒┼čsa, kullan─▒c─▒ verilerini almak i├žin bir istek g├Ânderir ve bunlar─▒ ├Ârnekte depolar. Herhangi bir kullan─▒c─▒ kimli─či ayarlanmam─▒┼čsa, bir hata mesaj─▒ g├╝nl├╝─če kaydeder.

─░ade:

Tip A├ž─▒klama
None

Y├Ântem bir de─čer d├Ând├╝rmez.

Kaynak kodu hub_sdk/modules/users.py
def get_data(self) -> None:
    """
    Retrieves data for the current user instance.

    If a valid user ID has been set, it sends a request to fetch the user data and stores it in the instance.
    If no user ID has been set, it logs an error message.

    Returns:
        (None): The method does not return a value.
    """
    if not self.id:
        self.logger.error("No user id has been set. Update the user id or create a user.")
        return

    try:
        response = super().read(self.id)

        if response is None:
            self.logger.error(f"Received no response from the server for user ID: {self.id}")
            return

        # Check if the response has a .json() method (it should if it's a response object)
        if not hasattr(response, "json"):
            self.logger.error(f"Invalid response object received for user ID: {self.id}")
            return

        resp_data = response.json()
        if resp_data is None:
            self.logger.error(f"No data received in the response for user ID: {self.id}")
            return

        data = resp_data.get("data", {})
        self.data = self._reconstruct_data(data)
        self.logger.debug(f"User data retrieved for ID: {self.id}")

    except Exception as e:
        self.logger.error(f"An error occurred while retrieving data for user ID: {self.id}, {str(e)}")

update(data)

Bu ├Ârnek taraf─▒ndan temsil edilen kullan─▒c─▒ kayna─č─▒n─▒ g├╝ncelleyin.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
data dict

Kullan─▒c─▒ kayna─č─▒ i├žin g├╝ncellenmi┼č veriler.

gerekli

─░ade:

Tip A├ž─▒klama
Optional[Response]

G├╝ncelleme iste─činden gelen yan─▒t nesnesi veya g├╝ncelleme ba┼čar─▒s─▒z olursa Yok

Kaynak kodu hub_sdk/modules/users.py
def update(self, data: dict) -> Optional[Response]:
    """
    Update the user resource represented by this instance.

    Args:
        data (dict): The updated data for the user resource.

    Returns:
        (Optional[Response]): Response object from the update request, or None if update fails
    """
    return super().update(self.id, data)