o
    ˷e                     @   s0   d Z ddlmZ ddlmZ G dd deZdS )z
The Batch Operations API Endpoint

Documentation: http://developer.mailchimp.com/documentation/mailchimp/reference/batches/
Schema: https://api.mailchimp.com/schema/3.0/Batches/Instance.json
    )unicode_literals)BaseApic                       sB   e Zd ZdZ fddZdd ZdddZd	d
 Zdd Z  Z	S )BatchOperationszR
    Use batch operations to complete multiple operations with a single call.
    c                    s,   t t| j|i | d| _d| _d| _dS )z)
        Initialize the endpoint
        batchesN)superr   __init__endpointbatch_idoperation_status)selfargskwargs	__class__ Z/var/www/ideatree/venv/lib/python3.10/site-packages/mailchimp3/entities/batchoperations.pyr      s   
zBatchOperations.__init__c                 C   sp   d|vrt d|d D ]!}d|vrt d|d dvr%td|d d|vr-t dq| jj|  |d	S )
a  
        Begin processing a batch operations request.

        :param data: The request body parameters
        :type data: :py:class:`dict`
        data = {
            "operations": array*
            [
                {
                    "method": string* (Must be one of "GET", "POST", "PUT", "PATCH", or "DELETE")
                    "path": string*,
                }
            ]
        }
        
operationszThe batch must have operationsmethodz&The batch operation must have a method)GETPOSTPUTPATCHDELETEz]The batch operation method must be one of "GET", "POST", "PUT", "PATCH", or "DELETE", not {0}pathz$The batch operation must have a path)urldata)KeyError
ValueErrorformat
_mc_client_post_build_path)r   r   opr   r   r   create   s   
zBatchOperations.createFc                 K   sB   d| _ d| _|r| jdd|  i|S | jjdd|  i|S )a}  
        Get a summary of batch requests that have been made.

        :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
   _iterater!   r   _get)r   get_allqueryparamsr   r   r   all8   s
   zBatchOperations.allc                 K   s(   || _ d| _| jjdd| |i|S )a#  
        Get the status of a batch request.

        :param batch_id: The unique id for the batch operation.
        :type batch_id: :py:class:`str`
        :param queryparams: The query string parameters
        queryparams['fields'] = []
        queryparams['exclude_fields'] = []
        Nr   r   )r	   r
   r   r%   r!   )r   r	   r'   r   r   r   getL   s   
zBatchOperations.getc                 C   s    || _ d| _| jj| |dS )ag  
        Stops a batch request from running. Since only one batch request is
        run at a time, this can be used to cancel a long running request. The
        results of any completed operations will not be available after this
        call.

        :param batch_id: The unique id for the batch operation.
        :type batch_id: :py:class:`str`
        N)r   )r	   r
   r   _deleter!   )r   r	   r   r   r   delete[   s   
zBatchOperations.delete)F)
__name__
__module____qualname____doc__r   r#   r(   r)   r+   __classcell__r   r   r   r   r      s    

r   N)r/   
__future__r   mailchimp3.baseapir   r   r   r   r   r   <module>   s   