o
    ˷e0                     @   s   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 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 G dd deZdS )z
The Lists API endpoint

Documentation: http://developer.mailchimp.com/documentation/mailchimp/reference/lists/
Schema: https://api.mailchimp.com/schema/3.0/Lists/Instance.json
    )unicode_literals)BaseApi)ListAbuseReports)ListActivity)ListClients)ListGrowthHistory)ListInterestCategories)ListMembers)ListMergeFields)ListSegments)ListSignupForms)ListWebhooks)check_emailc                       sR   e Zd ZdZ fddZdd Zdd Zdd	d
Zdd Zdd Z	dd Z
  ZS )Listsz_
    A MailChimp list is a powerful and flexible tool that helps you manage your contacts.
    c                    s   t t| j|i | d| _d| _t| | _t| | _t	| | _
t| | _t| | _t| | _t| | _t| | _t| | _t| | _dS )z)
        Initialize the endpoint
        listsN)superr   __init__endpointlist_idr   abuse_reportsr   activityr   clientsr   growth_historyr   interest_categoriesr	   membersr
   merge_fieldsr   segmentsr   signup_formsr   webhooks)selfargskwargs	__class__ P/var/www/ideatree/venv/lib/python3.10/site-packages/mailchimp3/entities/lists.pyr      s   








zLists.__init__c                 C   sp  d|vrt dd|vrt dd|d vrt dd|d vr$t dd	|d vr.t d
d|d vr8t dd|d vrBt dd|d vrLt dd|vrTt dd|vr\t dd|d vrft dd|d vrpt dt|d d  d|d vrt dd|d vrt dd|vrt d|d dvrtd | jj|  |d!}|d"ur|d# | _|S d"| _|S )$a  
        Create a new list in your MailChimp account.

        :param data: The request body parameters
        :type data: :py:class:`dict`
        data = {
            "name": string*,
            "contact": object*
            {
                "company": string*,
                "address1": string*,
                "city": string*,
                "state": string*,
                "zip": string*,
                "country": string*
            },
            "permission_reminder": string*,
            "campaign_defaults": object*
            {
                "from_name": string*,
                "from_email": string*,
                "subject": string*,
                "language": string*
            },
            "email_type_option": boolean
        }
        nameThe list must have a namecontactThe list must have a contactcompany$The list contact must have a companyaddress1%The list contact must have a address1city!The list contact must have a citystate"The list contact must have a statezip The list contact must have a zipcountry$The list contact must have a countrypermission_reminder(The list must have a permission_remindercampaign_defaults&The list must have a campaign_defaults	from_name0The list campaign_defaults must have a from_name
from_email1The list campaign_defaults must have a from_emailsubject.The list campaign_defaults must have a subjectlanguage/The list campaign_defaults must have a languageemail_type_option'The list must have an email_type_optionTF0The list email_type_option must be True or FalseurldataNid)KeyErrorr   	TypeError
_mc_client_post_build_pathr   )r   rH   responser$   r$   r%   create/   sN   
zLists.createc                 C   s   || _ d|vrtdt|d dkstd|d D ]<}d|vr%tdt|d  d|vr7d|vr7td	g d
}d|v rI|d |vrItdd|v rW|d |vrWtdqd|vr`d|d< | jj| ||dS )a  
        Batch subscribe or unsubscribe list members.

        Only the members array is required in the request body parameters.
        Within the members array, each member requires an email_address
        and either a status or status_if_new. The update_existing parameter
        will also be considered required to help prevent accidental updates
        to existing members and will default to false if not present.

        :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 = {
            "members": array*
            [
                {
                    "email_address": string*,
                    "status": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending'),
                    "status_if_new": string* (Must be one of 'subscribed', 'unsubscribed', 'cleaned', or 'pending')
                }
            ],
            "update_existing": boolean*
        }
        r   z(The update must have at least one memberi  z2You may only batch sub/unsub 500 members at a timeemail_addressz+Each list member must have an email_addressstatusstatus_if_newz=Each list member must have either a status or a status_if_new)
subscribedunsubscribedcleanedpendingz[The list member status must be one of "subscribed", "unsubscribed", "cleaned", or "pending"zbThe list member status_if_new must be one of "subscribed", "unsubscribed", "cleaned", or "pending"update_existingFrF   )r   rJ   len
ValueErrorr   rL   rM   rN   )r   r   rH   membervalid_statusesr$   r$   r%   update_memberst   s(   zLists.update_membersFc                 K   s<   d| _ |r| jdd|  i|S | jjdd|  i|S )a  
        Get information about all lists in the account.

        :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['before_date_created'] = string
        queryparams['since_date_created'] = string
        queryparams['before_campaign_last_sent'] = string
        queryparams['since_campaign_last_sent'] = string
        queryparams['email'] = string
        queryparams['sort_field'] = string (Must be 'date_created')
        queryparams['sort_dir'] = string (Must be one of 'ASC' or 'DESC')
        NrG   r$   )r   _iteraterN   rL   _get)r   get_allqueryparamsr$   r$   r%   all   s   z	Lists.allc                 K   s"   || _ | jjdd| |i|S )u  
        Get information about a specific list in your MailChimp account.
        Results include list members who have signed up but haven’t confirmed
        their subscription yet and unsubscribed or cleaned.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        :param queryparams: The query string parameters
        queryparams['fields'] = []
        queryparams['exclude_fields'] = []
        rG   Nr$   )r   rL   r_   rN   )r   r   ra   r$   r$   r%   get   s   z	Lists.getc                 C   sX  || _ d|vrtdd|vrtdd|d vrtdd|d vr'tdd	|d vr1td
d|d vr;tdd|d vrEtdd|d vrOtdd|vrWtdd|vr_tdd|d vritdd|d vrstdt|d d  d|d vrtdd|d vrtdd|vrtd|d dvrtd | jj| ||d!S )"a_  
        Update the settings for 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*,
            "contact": object*
            {
                "company": string*,
                "address1": string*,
                "city": string*,
                "state": string*,
                "zip": string*,
                "country": string*
            },
            "permission_reminder": string*,
            "campaign_defaults": object*
            {
                "from_name": string*,
                "from_email": string*,
                "subject": string*,
                "language": string*
            },
            "email_type_option": boolean
        }
        r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   )r   rJ   r   rK   rL   _patchrN   )r   r   rH   r$   r$   r%   update   sF   zLists.updatec                 C   s   || _ | jj| |dS )u  
        Delete a list from your MailChimp account. If you delete a list,
        you’ll lose the list history—including subscriber activity,
        unsubscribes, complaints, and bounces. You’ll also lose subscribers’
        email addresses, unless you exported and backed up your list.

        :param list_id: The unique id for the list.
        :type list_id: :py:class:`str`
        )rG   )r   rL   _deleterN   )r   r   r$   r$   r%   delete  s   
zLists.delete)F)__name__
__module____qualname____doc__r   rP   r]   rb   rc   re   rg   __classcell__r$   r$   r"   r%   r      s    E
2Cr   N)rk   
__future__r   mailchimp3.baseapir   $mailchimp3.entities.listabusereportsr    mailchimp3.entities.listactivityr   mailchimp3.entities.listclientsr   %mailchimp3.entities.listgrowthhistoryr   *mailchimp3.entities.listinterestcategoriesr   mailchimp3.entities.listmembersr	   #mailchimp3.entities.listmergefieldsr
    mailchimp3.entities.listsegmentsr   #mailchimp3.entities.listsignupformsr    mailchimp3.entities.listwebhooksr   mailchimp3.helpersr   r   r$   r$   r$   r%   <module>   s   