o
    éË·e|  ã                   @   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 )zI
The base API object that allows constructions of various endpoint paths
é    )Úunicode_literals)Úchain)Úmerge_resultsc                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )ÚBaseApiz0
    Simple class to buid path for entities
    c                    s   t t| ƒ ¡  || _d| _dS )zÌ
        Initialize the class with you user_id and secret_key

        :param mc_client: The mailchimp client connection
        :type mc_client: :mod:`mailchimp3.mailchimpclient.MailChimpClient`
        Ú N)Úsuperr   Ú__init__Ú
_mc_clientÚendpoint)ÚselfÚ	mc_client©Ú	__class__© úI/var/www/ideatree/venv/lib/python3.10/site-packages/mailchimp3/baseapi.pyr      s   
zBaseApi.__init__c                 G   s   d  t| jftt|ƒƒ¡S )zŒ
        Build path with endpoint and args

        :param args: Tokens in the endpoint URL
        :type args: :py:class:`unicode`
        ú/)Újoinr   r
   ÚmapÚstr)r   Úargsr   r   r   Ú_build_path   s   zBaseApi._build_pathc              	   K   sÄ   | j jsdS d|v rd|d  d¡vr|d  d7  < | dd¡ | dd¡}| j jd|d	|d
œ|¤Ž}|d }||kr`tdt|| ƒd ƒD ]}t|| j jd|t|| ƒ|d
œ|¤Žƒ}qG|S |S )a“  
        Iterate over all pages for the given url. Feed in the result of self._build_path as the url.

        :param url: The url of the endpoint
        :type url: :py:class:`str`
        :param queryparams: The query string parameters
        queryparams['fields'] = []
        queryparams['exclude_fields'] = []
        queryparams['count'] = integer
        queryparams['offset'] = integer
        NÚfieldsÚtotal_itemsú,z,total_itemsÚoffsetÚcountiô  r   )Úurlr   r   é   r   )r	   ÚenabledÚsplitÚpopÚ_getÚrangeÚintr   )r   r   Úqueryparamsr   ÚresultÚtotalr   r   r   r   Ú_iterate$   s(   
ý
üzBaseApi._iterate)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r'   Ú__classcell__r   r   r   r   r      s
    	r   N)	r+   Ú
__future__r   Ú	itertoolsr   Úmailchimp3.helpersr   Úobjectr   r   r   r   r   Ú<module>   s
   