
    ZTh                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
mZ er
ddlZddlmZ  ej                  e      Z G d d	      Z G d
 d      Zy)zTransport layer for REST communication.

This module provides a simple wrapper around sift_py/rest.py for making REST API calls.
    )annotationsN)TYPE_CHECKING)urljoin)_DEFAULT_REST_RETRYSiftRestConfig_RestService)Retryc                  :    e Zd ZdZddef	 	 	 	 	 	 	 	 	 ddZddZy)	
RestConfigz#Configuration for REST API clients.TFc                J    || _         || _        || _        || _        || _        y)aD  Initialize the REST configuration.

        Args:
            base_url: The base URL of the API.
            api_key: The API key for authentication.
            use_ssl: Whether to use HTTPS.
            cert_via_openssl: Whether to use OpenSSL for SSL/TLS.
            retry: The retry configuration for requests.
        N)base_urlapi_keyuse_sslcert_via_opensslretry)selfr   r   r   r   r   s         i/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/sift_client/transport/rest_transport.py__init__zRestConfig.__init__   s(    " ! 0
    c                v    | j                   | j                  | j                  | j                  | j                  dS )zConvert to a SiftRestConfig for backwards compatibility. Will be removed in the future.

        Returns:
            A SiftRestConfig.
        )uriapikeyr   r   r   )r   r   r   r   r   r   s    r   _to_sift_rest_configzRestConfig._to_sift_rest_config1   s3     ==llZZ|| $ 5 5
 	
r   N)
r   strr   r   r   boolr   r   r   r	   )returnr   )__name__
__module____qualname____doc__r   r   r    r   r   r   r      sJ    - !&*  	
  .
r   r   c                      e Zd ZdZddZddZedd       ZddZ	 	 d	 	 	 	 	 	 	 	 	 ddZ	dddZ
	 d	 	 	 	 	 dd	Z	 d	 	 	 	 	 dd
ZdddZ	 d	 	 	 	 	 ddZy)
RestClientzA client wrapper for REST APIs.

    This class provides a wrapper around sift_py/rest.py for making REST API calls.
    It handles authentication, retries, and error mapping.
    c                ^    |j                   | _        || _        | j                         | _        y)zfInitialize the REST client.

        Args:
            config: The REST client configuration.
        N)r   	_base_url_config_create_client_client)r   configs     r   r   zRestClient.__init__G   s&      **,r   c                d    | j                   j                         } G d dt              } ||      S )zCreate a REST service with the configured settings. Using _RestService for backwards compatibility. Will be removed in the future.

        Returns:
            A configured REST service.
        c                        e Zd Zd fdZ xZS )6RestClient._create_client.<locals>.ConcreteRestServicec                $    t         |   |       y N)superr   )r   	rest_conf	__class__s     r   r   z?RestClient._create_client.<locals>.ConcreteRestService.__init__[   s     +r   )r1   r   )r   r   r    r   __classcell__)r2   s   @r   ConcreteRestServicer-   Z   s    , ,r   r4   )r'   r   r   )r   sift_rest_configr4   s      r   r(   zRestClient._create_clientQ   s1      <<<<>	,, 	, ##344r   c                    | j                   S )z`Get the base URL of the REST client.

        Returns:
            The base URL string.
        )r&   r   s    r   r   zRestClient.base_url`   s     ~~r   c                L    | j                   j                  j                          y)zClose the REST client session.N)r)   _sessioncloser   s    r   r9   zRestClient.closei   s    ##%r   Nc                    t        | j                  |      } | j                  j                  j                  ||f||d|S )N)headersdata)r   r   r)   r8   request)r   methodendpointr;   r<   kwargsfull_urls          r   _executezRestClient._executen   sA     4==(3,t||$$,,VXdwUYd]cddr   c                ,     | j                   d||d|S )a  Execute a GET request.

        Args:
            endpoint: The API endpoint to call.
            headers: Additional headers to include in the request.
            **kwargs: Additional arguments to pass to the request.

        Returns:
            The HTTP response.
        r?   r;   )GETrB   r   r?   r;   r@   s       r   getzRestClient.gety   s     t}}QXwQ&QQr   c                .     | j                   d|||d|S )aN  Execute a POST request.

        Args:
            endpoint: The API endpoint to call.
            headers: Additional headers to include in the request.
            data: The data to send in the request body.
            **kwargs: Additional arguments to pass to the request.

        Returns:
            The HTTP response.
        r?   r;   r<   )POSTrF   r   r?   r;   r<   r@   s        r   postzRestClient.post   s"     t}}]hd]V\]]r   c                .     | j                   d|||d|S )aM  Execute a PUT request.

        Args:
            endpoint: The API endpoint to call.
            headers: Additional headers to include in the request.
            data: The data to send in the request body.
            **kwargs: Additional arguments to pass to the request.

        Returns:
            The HTTP response.
        rJ   )PUTrF   rL   s        r   putzRestClient.put   s"     t}}\XwT\U[\\r   c                ,     | j                   d||d|S )a  Execute a DELETE request.

        Args:
            endpoint: The API endpoint to call.
            headers: Additional headers to include in the request.
            **kwargs: Additional arguments to pass to the request.

        Returns:
            The HTTP response.
        rD   )DELETErF   rG   s       r   deletezRestClient.delete   s     t}}T'TVTTr   c                .     | j                   d|||d|S )aO  Execute a PATCH request.

        Args:
            endpoint: The API endpoint to call.
            headers: Additional headers to include in the request.
            data: The data to send in the request body.
            **kwargs: Additional arguments to pass to the request.

        Returns:
            The HTTP response.
        rJ   )PATCHrF   rL   s        r   patchzRestClient.patch   s"     t}}^xt^W]^^r   )r*   r   )r   r   )r   r   )r   None)NN)
r>   r   r?   r   r;   dict | Noner<   rX   r   requests.Responser/   )r?   r   r;   rX   r   rY   )r   r   r    r!   r   r(   propertyr   r9   rB   rH   rM   rP   rS   rV   r"   r   r   r$   r$   @   s    -5  &  $ 	e	e 	e 		e
 	e 
	eR @D^^&1^	^" @D]]&1]	] U @D__&1_	_r   r$   )r!   
__future__r   loggingtypingr   urllib.parser   sift_py.restr   r   r   requestsurllib3.utilr	   	getLoggerr   loggerr   r$   r"   r   r   <module>rd      sT   
 #      J J" 
		8	$&
 &
RA_ A_r   