o
    Ž¨ÊhW  ã                   @   s(   d dl Z ddlmZ G dd„ deƒZdS )é    Né   )ÚResourcec                   @   sF   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zddd„Z	dd„ Z
dS )ÚRecipientListszü
    RecipientLists class used to create, update, delete, list and get recipient
    lists. For detailed request and response formats, see the `Recipient Lists
    API documentation
    <https://www.sparkpost.com/api#/reference/recipient-lists>`_.
    zrecipient-listsc                 K   sV   i }d|v r|  d¡|d< |  d¡|d< |  d¡|d< |  d¡|d< |  d¡|d< |S )NÚidÚnameÚdescriptionÚ
attributesÚ
recipients)Úget)ÚselfÚkwargsÚmodel© r   úK/var/www/html/env/lib/python3.10/site-packages/sparkpost/recipient_lists.pyÚ_translate_keys   s   zRecipientLists._translate_keysc                 K   s,   | j di |¤Ž}| jd| jt |¡d�}|S )a0  
        Create a recipient list based on the supplied parameters

        :param str id: ID used to reference the recipient list
        :param str name: Editable display name
        :param str description: Detailed description of the recipient list
        :param dict attributes: Arbitrary metadata related to the list
        :param list recipients: Array of recipient dicts

        :returns: a ``dict`` with the ID, name, and number of accepted
            and rejected recipients
        :raises: :exc:`SparkPostAPIException` if API call fails
        ÚPOST©ÚdataNr   )r   ÚrequestÚuriÚjsonÚdumps)r   r   ÚpayloadÚresultsr   r   r   Úcreate   s   zRecipientLists.createc                 K   s8   d| j |f }| jdi |¤Ž}| jd|t |¡d�}|S )a?  
        Update a recipient list by ID based on the supplied parameters

        :param str list_id: ID of the recipient list you want to update
        :param str name: Editable display name
        :param str description: Detailed description of the recipient list
        :param dict attributes: Arbitrary metadata related to the list
        :param list recipients: Array of recipient dicts

        :returns: a ``dict`` with the ID, name, and number of accepted
            and rejected recipients
        :raises: :exc:`SparkPostAPIException` if API call fails
        ú%s/%sÚPUTr   Nr   )r   r   r   r   r   )r   Úlist_idr   r   r   r   r   r   r   Úupdate.   s   zRecipientLists.updatec                 C   s   d| j |f }|  d|¡}|S )a  
        Delete a recipient list by ID

        :param str list_id: ID of the recipient list you want to delete

        :returns: empty ``dict``
        :raises: :exc:`SparkPostAPIException` if recipient list is not found
            or if recipient list is in use
        r   ÚDELETE)r   r   )r   r   r   r   r   r   r   ÚdeleteA   s   
zRecipientLists.deleteNc                 C   s>   d| j |f }i }|durt|ƒ ¡ |d< | jd||d�}|S )a]  
        Get a recipient list by ID

        :param str list_id: ID of the recipient list you want to retrieve
        :param bool show_recipients: If True, returns attributes for
            all recipients

        :returns: the requested recipient list if found
        :raises: :exc:`SparkPostAPIException` if recipient list is not found
        r   NÚshow_recipientsÚGET)Úparams)r   ÚstrÚlowerr   )r   r   r!   r   r#   r   r   r   r   r
   O   s   zRecipientLists.getc                 C   s   |   d| j¡}|S )zŸ
        Get a list of your recipient lists

        :returns: list of recipient lists
        :raises: :exc:`SparkPostAPIException` if API call fails
        r"   )r   r   )r   r   r   r   r   Úlista   s   zRecipientLists.list)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úkeyr   r   r   r    r
   r&   r   r   r   r   r      s    
r   )r   Úbaser   r   r   r   r   r   Ú<module>   s    