o
    ˷e                      @   sl   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 G d	d
 d
eZdS )z
The Campaigns API endpoint

Documentation: http://developer.mailchimp.com/documentation/mailchimp/reference/campaigns/
Schema: https://api.mailchimp.com/schema/3.0/Campaigns/Instance.json
    )unicode_literals)BaseApi)CampaignActions)CampaignContent)CampaignFeedback)CampaignSendChecklist)check_emailc                       sJ   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	  Z
S )	Campaignsz
    Campaigns are how you send emails to your MailChimp list. Use the
    Campaigns API calls to manage campaigns in your MailChimp account.
    c                    sN   t t| j|i | d| _d| _t| | _t| | _t	| | _
t| | _dS )z)
        Initialize the endpoint
        	campaignsN)superr	   __init__endpointcampaign_idr   actionsr   contentr   feedbackr   send_checklist)selfargskwargs	__class__ T/var/www/ideatree/venv/lib/python3.10/site-packages/mailchimp3/entities/campaigns.pyr      s   


zCampaigns.__init__c                 C   s  d|vrt dd|d vrt dd|di v r"t|d d  d|vr*t d|d d	vr4td
|d dkrd|vrBt dd|d vrLt d|d d dvrXtdd|d vrid|dvrit dd|d vrzd|dvrzt dd|d vrd|dvrt d|d dkrd|vrt dd|d vrt d|d d d vrtd!| jj|  |d"}|d#ur|d$ | _|S d#| _|S )%a  
        Create a new MailChimp campaign.

        The ValueError raised by an invalid type in data does not mention
        'absplit' as a potential value because the documentation indicates
        that the absplit type has been deprecated.

        :param data: The request body parameters
        :type data: :py:class:`dict`
        data = {
            "recipients": object*
            {
                "list_id": string*
            },
            "variate_settings": object* (Required if type is "variate")
            {
                "subject_lines": string* (can be empty if subject_line in settings)
                "from_names": string* (can be empty if from_name in settings)
                "reply_to_addresses": string* (can be empty if reply_to in settings)
                "winner_criteria": string* (Must be one of "opens", "clicks", "total_revenue", or "manual")
            },
            "rss_opts": object* (Required if type is "rss")
            {
                "feed_url": string*,
                "frequency": string* (Must be one of "daily", "weekly", or "monthly")
            },
            "type": string* (Must be one of "regular", "plaintext", "rss", "variate", or "absplit")
        }
        
recipientsz!The campaign must have recipientslist_idz+The campaign recipients must have a list_idreply_tosettingstypezThe campaign must have a type)regular	plaintextrssvariateabspiltzLThe campaign type must be one of "regular", "plaintext", "rss", or "variate"r"   variate_settingsz/The variate campaign must have variate_settingswinner_criteriaz9The campaign variate_settings must have a winner_criteria)opensclickstotal_revenuemanualzlThe campaign variate_settings winner_criteria must be one of "opens", "clicks", "total_revenue", or "manual"subject_linessubject_linez7The campaign variate_settings must have a subject_lines
from_names	from_namez4The campaign variate_settings must have a from_namesreply_to_addressesz<The campaign variate_settings must have a reply_to_addressesr!   rss_optsz#The rss campaign must have rss_optsfeed_urlz*The campaign rss_opts must have a feed_url	frequency)dailyweeklymonthlyzEThe rss_opts frequency must be one of "daily", "weekly", or "monthly"urldataNid)KeyErrorgetr   
ValueError
_mc_client_post_build_pathr   )r   r7   responser   r   r   create$   sH   
zCampaigns.createFc                 K   s<   d| _ |r| jdd|  i|S | jjdd|  i|S )a  
        Get all campaigns in an account.

        .. note::
            The before_create_time, since_create_time, before_send_time, and
            since_send_time queryparams expect times to be listed in the ISO
            8601 format in UTC (ex. 2015-10-21T15:41:36+00:00).

        :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'] = []
        queryparams['status'] = []
        queryparams['before_send_time'] = string
        queryparams['since_send_time'] = string
        queryparams['before_create_time'] = string
        queryparams['since_create_time'] = string
        queryparams['list_id'] = string
        queryparams['folder_id'] = string
        queryparams['sort_field'] = string
        queryparams['sort_dir'] = string
        Nr6   r   )r   _iterater>   r<   _get)r   get_allqueryparamsr   r   r   alli   s   zCampaigns.allc                 K   s"   || _ | jjdd| |i|S )a  
        Get information about a specific campaign.

        :param campaign_id: The unique id for the campaign.
        :type campaign_id: :py:class:`str`
        :param queryparams: The query string parameters
        queryparams['fields'] = []
        queryparams['exclude_fields'] = []
        queryparams['sort_field'] = string
        queryparams['create_time'] = string
        r6   Nr   )r   r<   rB   r>   )r   r   rD   r   r   r   r:      s   zCampaigns.getc                 C   sx   || _ d|vrtdd|d vrtdd|d vrtdd|d vr)tdt|d d  | jj| ||d	S )
a  
        Update some or all of the settings for a specific campaign.

        :param campaign_id: The unique id for the campaign.
        :type campaign_id: :py:class:`str`
        :param data: The request body parameters
        :type data: :py:class:`dict`
        data = {
            "settings": object*
            {
                "subject_line": string*,
                "from_name": string*,
                "reply_to": string*
            },
        }
        r   zThe campaign must have settingsr+   z.The campaign settings must have a subject_liner-   z+The campaign settings must have a from_namer   z*The campaign settings must have a reply_tor5   )r   r9   r   r<   _patchr>   )r   r   r7   r   r   r   update   s   zCampaigns.updatec                 C   s   || _ | jj| |dS )z
        Remove a campaign from your MailChimp account.

        :param campaign_id: The unique id for the campaign.
        :type campaign_id: :py:class:`str`
        )r6   )r   r<   _deleter>   )r   r   r   r   r   delete   s   zCampaigns.delete)F)__name__
__module____qualname____doc__r   r@   rE   r:   rG   rI   __classcell__r   r   r   r   r	      s    
E"r	   N)rM   
__future__r   mailchimp3.baseapir   #mailchimp3.entities.campaignactionsr   #mailchimp3.entities.campaigncontentr   $mailchimp3.entities.campaignfeedbackr   )mailchimp3.entities.campaignsendchecklistr   mailchimp3.helpersr   r	   r   r   r   r   <module>   s   