o
    ˷e                     @   s@   d 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 Segment Members API endpoint

Documentation: http://developer.mailchimp.com/documentation/mailchimp/reference/lists/segments/members/
Schema: https://api.mailchimp.com/schema/3.0/Lists/Members/Instance.json
    )unicode_literals)BaseApi)check_emailcheck_subscriber_hashc                       s:   e Zd ZdZ fddZdd ZdddZd	d
 Z  ZS )ListSegmentMembersz1
    Manage list members in a saved segment.
    c                    s2   t t| j|i | d| _d| _d| _d| _dS )z)
        Initialize the endpoint
        listsN)superr   __init__endpointlist_id
segment_idsubscriber_hash)selfargskwargs	__class__ ]/var/www/ideatree/venv/lib/python3.10/site-packages/mailchimp3/entities/listsegmentmembers.pyr	      s
   
zListSegmentMembers.__init__c                 C   s   || _ || _d|vrtdt|d  d|vrtd|d dvr&td| jj| |d|d|d	}|d
ur?|d | _|S d
| _|S )a  
        Add a member to a static segment.

        The documentation does not currently elaborate on the path or request
        body parameters. Looking at the example provided, it will be assumed
        that email_address and status are required request body parameters and
        they are documented and error-checked as such.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        :param segment_id: The unique id for the segment.
        :type segment_id: :py:class:`str`
        :param data: The request body parameters
        :type data: :py:class:`dict`
        data = {
            "email_address": string*,
            "status": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending')
        }
        email_addressz2The list segment member must have an email_addressstatusz*The list segment member must have a status)
subscribedunsubscribedcleanedpendingzaThe list segment member status must be one of "subscribed", "unsubscribed", "cleaned" or"pending"segmentsmembers)urldataNid)	r   r   KeyErrorr   
ValueError
_mc_client_post_build_pathr   )r   r   r   r   responser   r   r   create   s   
zListSegmentMembers.createFc              	   K   sX   || _ || _d| _|r| jdd| |d|di|S | jjdd| |d|di|S )a9  
        Get information about members in a saved segment.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        :param segment_id: The unique id for the segment.
        :type segment_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
        Nr   r   r   r   )r   r   r   _iterater$   r"   _get)r   r   r   get_allqueryparamsr   r   r   allC   s    "zListSegmentMembers.allc                 C   s6   t |}|| _|| _|| _| jj| |d|d|dS )u  
        Remove a member from the specified static segment.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        :param segment_id: The unique id for the segment.
        :type segment_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   r   r"   _deleter$   )r   r   r   r   r   r   r   delete\   s   zListSegmentMembers.delete)F)	__name__
__module____qualname____doc__r	   r&   r+   r-   __classcell__r   r   r   r   r      s    
&r   N)	r1   
__future__r   mailchimp3.baseapir   mailchimp3.helpersr   r   r   r   r   r   r   <module>   s
   