U
    42‹i‰  ã                   @   s    d dl Z ddd„Zddd„ZdS )	é    NFc                 C   s4   t ƒ }| D ]}d|i}| |¡ q
|r0t |¡S |S )zp decouple, allow for modifications to return type
        returns a list of ip addresses in object or json form Úip)ÚlistÚappendÚjsonÚdumps)Z
return_setÚas_jsonZret_listÚitemÚd© r
   úL/tmp/pip-unpacked-wheel-clku7wca/sendgrid/helpers/endpoints/ip/unassigned.pyÚ
format_ret   s    
r   c                 C   s\   t ƒ }t| tƒst||dS | D ]*}t|d ƒ}|dkr |d }| |¡ q t||d}|S )a|   https://sendgrid.com/docs/API_Reference/api_v3.html#ip-addresses
        The /ips rest endpoint returns information about the IP addresses
        and the usernames assigned to an IP

        unassigned returns a listing of the IP addresses that are allocated
        but have 0 users assigned


        data (response.body from sg.client.ips.get())
        as_json False -> get list of dicts
                True  -> get json object

        example:
        sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))

        params = {
            'subuser': 'test_string',
            'ip': 'test_string',
            'limit': 1,
            'exclude_whitelabels':
            'true', 'offset': 1
        }
        response = sg.client.ips.get(query_params=params)
        if response.status_code == 201:
           data = response.body
           unused = unassigned(data)
    )r   Zsubusersr   r   )ÚsetÚ
isinstancer   r   ÚlenÚadd)Údatar   Zno_subusersÚcurrentZnum_subusersZ
current_ipZret_valr
   r
   r   Ú
unassigned   s    
r   )F)F)r   r   r   r
   r
   r
   r   Ú<module>   s   
