o
    ˷eS                     @   s<   d Z ddlmZ ddlmZ ddlmZ G dd deZdS )z
The List Segments API endpoint

Documentation: http://developer.mailchimp.com/documentation/mailchimp/reference/lists/segments/
Schema: https://api.mailchimp.com/schema/3.0/Lists/Segments/Instance.json
    )unicode_literals)BaseApi)ListSegmentMembersc                       sR   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
  ZS )ListSegmentsz
    Manage segments for a specific MailChimp list. A segment is a section of
    your list that includes only those subscribers who share specific common
    field information.
    c                    s6   t t| j|i | d| _d| _d| _t| | _dS )z)
        Initialize the endpoint
        listsN)superr   __init__endpointlist_id
segment_idr   members)selfargskwargs	__class__ W/var/www/ideatree/venv/lib/python3.10/site-packages/mailchimp3/entities/listsegments.pyr      s
   zListSegments.__init__c                 C   sN   || _ d|vrtd| jj| |d|d}|dur"|d | _|S d| _|S )a#  
        Create a new segment in a specific 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 = {
            "name": string*
        }
        name!The list segment must have a namesegmentsurldataNid)r
   KeyError
_mc_client_post_build_pathr   )r   r
   r   responser   r   r   create   s   
zListSegments.createFc                 K   sJ   || _ d| _|r| jdd| |di|S | jjdd| |di|S )a  
        Get information about all available segments for a specific 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['type'] = string
        queryparams['before_created_at'] = string
        queryparams['since_created_at'] = string
        queryparams['before_updated_at'] = string
        queryparams['since_updated_at'] = string
        Nr   r   r   )r
   r   _iterater   r   _get)r   r
   get_allqueryparamsr   r   r   all6   s
   zListSegments.allc                 K   s,   || _ || _| jjdd| |d|i|S )a  
        Get information about a specific 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 queryparams: The query string parameters
        queryparams['fields'] = []
        queryparams['exclude_fields'] = []
        r   r   Nr   )r
   r   r   r"   r   )r   r
   r   r$   r   r   r   getQ   s    zListSegments.getc                 C   s6   || _ || _d|vrtd| jj| |d||dS )a  
        Update a specific segment in a list.

        :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 = {
            "name": string*
        }
        r   r   r   r   )r
   r   r   r   _patchr   r   r
   r   r   r   r   r   updateb   s
   zListSegments.updatec                 C   s&   || _ || _| jj| |d||dS )a  
        Batch add/remove list members to 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 data: The request body parameters
        :type data: :py:class:`dict`
        data = {
            "members_to_add": array,
            "members_to_remove": array
        }
        r   r   )r
   r   r   r   r   r(   r   r   r   update_membersw   s   zListSegments.update_membersc                 C   s$   || _ || _| jj| |d|dS )z
        Delete a specific segment in a list.

        :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`
        r   )r   )r
   r   r   _deleter   )r   r
   r   r   r   r   delete   s   	zListSegments.delete)F)__name__
__module____qualname____doc__r   r    r%   r&   r)   r*   r,   __classcell__r   r   r   r   r      s    
r   N)r0   
__future__r   mailchimp3.baseapir   &mailchimp3.entities.listsegmentmembersr   r   r   r   r   r   <module>   s
   