Allow using non-Premium keys for Google Maps client

This commit is contained in:
Juan Ignacio Sánchez Lara 2018-06-04 18:07:16 +02:00
parent 2687f0c73a
commit 5251534283

View File

@ -5,6 +5,7 @@ import googlemaps
import base64 import base64
from exceptions import InvalidGoogleCredentials from exceptions import InvalidGoogleCredentials
class GoogleMapsClientFactory(): class GoogleMapsClientFactory():
clients = {} clients = {}
@ -13,11 +14,14 @@ class GoogleMapsClientFactory():
cache_key = "{}:{}:{}".format(client_id, client_secret, channel) cache_key = "{}:{}:{}".format(client_id, client_secret, channel)
client = cls.clients.get(cache_key) client = cls.clients.get(cache_key)
if not client: if not client:
cls.assert_valid_crendentials(client_secret) if client_id:
client = googlemaps.Client( cls.assert_valid_crendentials(client_secret)
client_id=client_id, client = googlemaps.Client(
client_secret=client_secret, client_id=client_id,
channel=channel) client_secret=client_secret,
channel=channel)
else:
client = googlemaps.Client(key=client_secret)
cls.clients[cache_key] = client cls.clients[cache_key] = client
return client return client