o
    tBh                     @   sD   d dl mZ d dlmZ d dlmZ d dlmZ G dd deZdS )    )	APIHelper)ApiResponse)BaseApi)OAuth2c                       s:   e Zd ZdZd fdd	Zdd Zdd Zd	d
 Z  ZS )SnippetsApiz3A Controller to access Endpoints in the square API.Nc                    s   t t| || d S N)superr   __init__)selfconfig	call_back	__class__ n/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/square/api/snippets_api.pyr	      s   zSnippetsApi.__init__c                 C   s   d}t |d|ddi}| j }||7 }t |}ddi}| jjj||d}t| j| | 	|}t 
|j}t|tu rF|d}	nd	}	t|||	d
}
|
S )a)  Does a DELETE request to /v2/sites/{site_id}/snippet.

        Removes your snippet from a Square Online site.
        You can call [ListSites]($e/Sites/ListSites) to get the IDs of the
        sites that belong to a seller.
        __Note:__ Square Online APIs are publicly available as part of an
        early access program. For more information, see [Early access program
        for Square Online
        APIs](https://developer.squareup.com/docs/online-api#early-access-progr
        am-for-square-online-apis).

        Args:
            site_id (string): The ID of the site that contains the snippet.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        /v2/sites/{site_id}/snippetsite_idTvalueencodeacceptapplication/jsonheaderserrorsNbodyr   )r   #append_url_with_template_parametersr   get_base_uri	clean_urlhttp_clientdeleter   applyexecute_requestjson_deserializetexttypedictgetr   r
   r   	_url_path_query_builder
_query_url_headers_request	_responsedecoded_errors_resultr   r   r   delete_snippet   s$   



zSnippetsApi.delete_snippetc                 C   s   d}t |d|ddi}| j }||7 }t |}ddi}| jjj||d}t| j| | 	|}t 
|j}t|tu rF|d}	nd	}	t|||	d
}
|
S )a  Does a GET request to /v2/sites/{site_id}/snippet.

        Retrieves your snippet from a Square Online site. A site can contain
        snippets from multiple snippet applications, but you can retrieve only
        the snippet that was added by your application.
        You can call [ListSites]($e/Sites/ListSites) to get the IDs of the
        sites that belong to a seller.
        __Note:__ Square Online APIs are publicly available as part of an
        early access program. For more information, see [Early access program
        for Square Online
        APIs](https://developer.squareup.com/docs/online-api#early-access-progr
        am-for-square-online-apis).

        Args:
            site_id (string): The ID of the site that contains the snippet.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        r   r   Tr   r   r   r   r   Nr   )r   r   r   r   r   r    r(   r   r"   r#   r$   r%   r&   r'   r   r)   r   r   r   retrieve_snippetG   s$   



zSnippetsApi.retrieve_snippetc                 C   s   d}t |d|ddi}| j }||7 }t |}ddd}| jjj||t |d}t	| j| | 
|}t |j}	t|	tu rK|	d}
nd	}
t||	|
d
}|S )a  Does a POST request to /v2/sites/{site_id}/snippet.

        Adds a snippet to a Square Online site or updates the existing snippet
        on the site. 
        The snippet code is appended to the end of the `head` element on every
        page of the site, except checkout pages. A snippet application can add
        one snippet to a given site. 
        You can call [ListSites]($e/Sites/ListSites) to get the IDs of the
        sites that belong to a seller.
        __Note:__ Square Online APIs are publicly available as part of an
        early access program. For more information, see [Early access program
        for Square Online
        APIs](https://developer.squareup.com/docs/online-api#early-access-progr
        am-for-square-online-apis).

        Args:
            site_id (string): The ID of the site where you want to add or
                update the snippet.
            body (UpsertSnippetRequest): An object containing the fields to
                POST for the request.  See the corresponding object definition
                for field details.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        r   r   Tr   r   )r   zContent-Type)r   
parametersr   Nr   )r   r   r   r   r   r    postjson_serializer   r"   r#   r$   r%   r&   r'   r(   r   )r
   r   r   r*   r+   r,   r-   r.   r/   r0   r1   r2   r   r   r   upsert_snippet   s&   &



zSnippetsApi.upsert_snippetr   )	__name__
__module____qualname____doc__r	   r3   r4   r8   __classcell__r   r   r   r   r   	   s    79r   N)	square.api_helperr   square.http.api_responser   square.api.base_apir   square.http.auth.o_auth_2r   r   r   r   r   r   <module>   s
   