U
    ҭc                     @   s*   d Z ddlmZ dZdd Zd	ddZdS )
z5Performs requests to the Google Maps Geolocation API.    )
exceptionszhttps://www.googleapis.comc                 C   st   |   }| jdkr|S z|d d d d }W n tk
rF   d}Y nX | jdkrbt| j|nt| j|dS )z
    Mimics the exception handling logic in ``client._get_body``, but
    for geolocation which uses a different response format.
    )   i  errorerrorsr   reasonNi  )jsonZstatus_codeKeyErrorr   Z_OverQueryLimitZApiError)responsebodyr    r   S/home/ubuntu/graampay/app_env/lib/python3.8/site-packages/googlemaps/geolocation.py_geolocation_extract   s    


r   Nc           	      C   s   i }|dk	r||d< |dk	r$||d< |dk	r4||d< |dk	rD||d< |dk	rT||d< |dk	rd||d< |dk	rt||d< | j d	i tt|d
S )aE  
    The Google Maps Geolocation API returns a location and accuracy
    radius based on information about cell towers and WiFi nodes given.

    See https://developers.google.com/maps/documentation/geolocation/intro
    for more info, including more detail for each parameter below.

    :param home_mobile_country_code: The mobile country code (MCC) for
        the device's home network.
    :type home_mobile_country_code: string

    :param home_mobile_network_code: The mobile network code (MCC) for
        the device's home network.
    :type home_mobile_network_code: string

    :param radio_type: The mobile radio type. Supported values are
        lte, gsm, cdma, and wcdma. While this field is optional, it
        should be included if a value is available, for more accurate
        results.
    :type radio_type: string

    :param carrier: The carrier name.
    :type carrier: string

    :param consider_ip: Specifies whether to fall back to IP geolocation
        if wifi and cell tower signals are not available. Note that the
        IP address in the request header may not be the IP of the device.
    :type consider_ip: bool

    :param cell_towers: A list of cell tower dicts. See
        https://developers.google.com/maps/documentation/geolocation/intro#cell_tower_object
        for more detail.
    :type cell_towers: list of dicts

    :param wifi_access_points: A list of WiFi access point dicts. See
        https://developers.google.com/maps/documentation/geolocation/intro#wifi_access_point_object
        for more detail.
    :type wifi_access_points: list of dicts
    NZhomeMobileCountryCodeZhomeMobileNetworkCodeZ	radioTypecarrierZ
considerIpZ
cellTowersZwifiAccessPointsz/geolocation/v1/geolocate)Zbase_urlZextract_bodyZ	post_json)Z_request_GEOLOCATION_BASE_URLr   )	ZclientZhome_mobile_country_codeZhome_mobile_network_codeZ
radio_typer   Zconsider_ipZcell_towersZwifi_access_pointsparamsr   r   r   	geolocate-   s(    +r   )NNNNNNN)__doc__
googlemapsr   r   r   r   r   r   r   r   <module>   s              