o
    ˷e.                      @   sp   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZ G d	d
 d
eZdS )z
The List Members API endpoint

Documentation: http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/
Schema: https://api.mailchimp.com/schema/3.0/Lists/Members/Instance.json
    )unicode_literals)BaseApi)ListMemberActivity)ListMemberEvents)ListMemberGoals)ListMemberNotes)check_emailcheck_subscriber_hashc                       sZ   e Zd ZdZ fddZdd ZdddZd	d
 Zdd Zdd Z	dd Z
dd Z  ZS )ListMembersz}
    Manage members of a specific MailChimp list, including currently
    subscribed, unsubscribed, and bounced members.
    c                    sT   t t| j|i | d| _d| _d| _t| | _t| | _	t
| | _t| | _dS )z)
        Initialize the endpoint
        listsN)superr
   __init__endpointlist_idsubscriber_hashr   activityr   eventsr   goalsr   notes)selfargskwargs	__class__ V/var/www/ideatree/venv/lib/python3.10/site-packages/mailchimp3/entities/listmembers.pyr      s   


zListMembers.__init__c                 C   s~   || _ d|vrtd|d dvrtdd|vrtdt|d  | jj| |d|d}|d	ur:|d
 | _|S d	| _|S )a  
        Add a new member to the list.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        :param data: The request body parameters
        :type data: :py:class:`dict`
        data = {
            "status": string*, (Must be one of 'subscribed', 'unsubscribed', 'cleaned',
                'pending', or 'transactional')
            "email_address": string*
        }
        statusz"The list member must have a status
subscribedunsubscribedcleanedpendingtransactionalzlThe list member status must be one of "subscribed", "unsubscribed", "cleaned", "pending", or "transactional"email_address*The list member must have an email_addressmembersurldataNid)r   KeyError
ValueErrorr   
_mc_client_post_build_pathr   )r   r   r(   responser   r   r   create%   s   
zListMembers.createFc                 K   sJ   || _ d| _|r| jdd| |di|S | jjdd| |di|S )a  
        Get information about members in a specific MailChimp list.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        :param get_all: Should the query get all results
        :type get_all: :py:class:`bool`
        :param queryparams: The query string parameters
        queryparams['fields'] = []
        queryparams['exclude_fields'] = []
        queryparams['count'] = integer
        queryparams['offset'] = integer
        queryparams['email_type'] = string
        queryparams['status'] = string
        queryparams['before_timestamp_opt'] = string
        queryparams['since_timestamp_opt'] = string
        queryparams['before_last_changed'] = string
        queryparams['since_last_changed'] = string
        queryparams['unique_email_id'] = string
        queryparams['vip_only'] = boolean
        queryparams['interest_category_id'] = string
        queryparams['interest_ids'] = string
        queryparams['interest_match'] = string
        Nr'   r%   r   )r   r   _iterater.   r,   _get)r   r   get_allqueryparamsr   r   r   allD   s
   zListMembers.allc                 K   s4   t |}|| _|| _| jjdd| |d|i|S )u  
        Get information about a specific list member, including a currently
        subscribed, unsubscribed, or bounced member.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        :param subscriber_hash: The MD5 hash of the lowercase version of the
            list member’s email address.
        :type subscriber_hash: :py:class:`str`
        :param queryparams: The query string parameters
        queryparams['fields'] = []
        queryparams['exclude_fields'] = []
        r'   r%   Nr   )r	   r   r   r,   r2   r.   )r   r   r   r4   r   r   r   gete   s    zListMembers.getc                 C   s.   t |}|| _|| _| jj| |d||dS )u  
        Update information for a specific list member.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        :param subscriber_hash: The MD5 hash of the lowercase version of the
            list member’s email address.
        :type subscriber_hash: :py:class:`str`
        :param data: The request body parameters
        :type data: :py:class:`dict`
        r%   r&   )r	   r   r   r,   _patchr.   r   r   r   r(   r   r   r   updatey   s   zListMembers.updatec                 C   sn   t |}|| _|| _d|vrtdt|d  d|vr td|d dvr*td| jj| |d||dS )	uU  
        Add or update a list member.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        :param subscriber_hash: The MD5 hash of the lowercase version of the
            list member’s email address.
        :type subscriber_hash: :py:class:`str`
        :param data: The request body parameters
        :type data: :py:class:`dict`
        data = {
            "email_address": string*,
            "status_if_new": string* (Must be one of 'subscribed',
                'unsubscribed', 'cleaned', 'pending', or 'transactional')
        }
        r#   r$   status_if_newz)The list member must have a status_if_newr   zsThe list member status_if_new must be one of "subscribed", "unsubscribed", "cleaned", "pending", or "transactional"r%   r&   )	r	   r   r   r*   r   r+   r,   _putr.   r8   r   r   r   create_or_update   s   zListMembers.create_or_updatec                 C   s,   t |}|| _|| _| jj| |d|dS )u/  
        Delete a member from a list.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        :param subscriber_hash: The MD5 hash of the lowercase version of the
          list member’s email address.
        :type subscriber_hash: :py:class:`str`
        r%   r'   )r	   r   r   r,   _deleter.   r   r   r   r   r   r   delete   s   
zListMembers.deletec                 C   s0   t |}|| _|| _| jj| |d|dddS )u;  
        Delete permanently a member from a list.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        :param subscriber_hash: The MD5 hash of the lowercase version of the
          list member’s email address.
        :type subscriber_hash: :py:class:`str`
        r%   actionszdelete-permanentr=   )r	   r   r   r,   r-   r.   r?   r   r   r   delete_permanent   s   
zListMembers.delete_permanent)F)__name__
__module____qualname____doc__r   r0   r5   r6   r9   r<   r@   rB   __classcell__r   r   r   r   r
      s    
!r
   N)rF   
__future__r   mailchimp3.baseapir   &mailchimp3.entities.listmemberactivityr   $mailchimp3.entities.listmembereventsr   #mailchimp3.entities.listmembergoalsr   #mailchimp3.entities.listmembernotesr   mailchimp3.helpersr   r	   r
   r   r   r   r   <module>   s   