U
    
ڲg                     @   sP   d Z ddlZddlmZ ddlmZ dZdZdd Zdd	d
ZG dd dZ	dS )zkFirebase Instance ID module.

This module enables deleting instance IDs associated with Firebase projects.
    N)_http_client)_utilsz'https://console.firebase.google.com/v1/Z_iidc                 C   s   t | ttS )N)r   Zget_app_service_IID_ATTRIBUTE_InstanceIdService)app r   >/tmp/pip-unpacked-wheel-p0r7i5ii/firebase_admin/instance_id.py_get_iid_service   s    r	   c                 C   s   t ||  dS )a  Deletes the specified instance ID and the associated data from Firebase.

    Note that Google Analytics for Firebase uses its own form of Instance ID to
    keep track of analytics data. Therefore deleting a regular Instance ID does
    not delete Analytics data. See `Delete an Instance ID`_ for more information.

    Args:
      instance_id: A non-empty instance ID string.
      app: An App instance (optional).

    Raises:
      InstanceIdError: If an error occurs while invoking the backend instance ID service.
      ValueError: If the specified instance ID or app is invalid.

    .. _Delete an Instance ID: https://firebase.google.com/support/privacy          /manage-iids#delete_an_instance_id
    N)r	   delete_instance_id)instance_idr   r   r   r   r
   "   s    r
   c                	   @   s>   e Zd ZdZdddddddd	d
Zdd Zdd Zdd ZdS )r   zEProvides methods for interacting with the remote instance ID service.zMalformed instance ID argument.zRequest not authorized.zUProject does not match instance ID or the client does not have sufficient privileges.zFailed to find the instance ID.zAlready deleted.z,Request throttled out by the backend server.zInternal server error.z3Backend servers are over capacity. Try again later.)i  i  i  i  i  i  i  i  c                 C   s2   |j }|std|| _tj|j td| _d S )NzProject ID is required to access Instance ID service. Either set the projectId option, or use service account credentials. Alternatively, set the GOOGLE_CLOUD_PROJECT environment variable.)
credentialbase_url)	
project_id
ValueError_project_idr   ZJsonHttpClientr   get_credential_IID_SERVICE_URL_client)selfr   r   r   r   r   __init__F   s     z_InstanceIdService.__init__c              
   C   sz   t |tr|stdd| j|}z| jd| W n> tjj	k
rt } z| 
||}t||W 5 d }~X Y nX d S )Nz'Instance ID must be a non-empty string.zproject/{0}/instanceId/{1}delete)
isinstancestrr   formatr   r   requestrequests
exceptionsRequestException_extract_messager   Zhandle_requests_error)r   r   patherrormsgr   r   r   r
   Q   s    z%_InstanceIdService.delete_instance_idc                 C   s>   |j d krd S |j j}| j|}|r2d||S d||S )NzInstance ID "{0}": {1})responsestatus_codeerror_codesgetr   )r   r   r    statusr!   r   r   r   r   [   s    
z#_InstanceIdService._extract_messageN)__name__
__module____qualname____doc__r$   r   r
   r   r   r   r   r   r   7   s   
r   )N)
r*   r   Zfirebase_adminr   r   r   r   r	   r
   r   r   r   r   r   <module>   s   
