diff --git a/server/lib/python/cartodb_services/cartodb_services/google/client_factory.py b/server/lib/python/cartodb_services/cartodb_services/google/client_factory.py index caf3fd8..feb7f4a 100644 --- a/server/lib/python/cartodb_services/cartodb_services/google/client_factory.py +++ b/server/lib/python/cartodb_services/cartodb_services/google/client_factory.py @@ -9,14 +9,15 @@ class GoogleMapsClientFactory(): clients = {} @classmethod - def get(cls, client_id, client_secret): - cache_key = "{}:{}".format(client_id, client_secret) + def get(cls, client_id, client_secret, channel=None): + cache_key = "{}:{}:{}".format(client_id, client_secret, channel) client = cls.clients.get(cache_key) if not client: cls.assert_valid_crendentials(client_secret) client = googlemaps.Client( client_id=client_id, - client_secret=client_secret) + client_secret=client_secret, + channel=channel) cls.clients[cache_key] = client return client diff --git a/server/lib/python/cartodb_services/cartodb_services/google/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/google/geocoder.py index bf14b84..2fb0e01 100644 --- a/server/lib/python/cartodb_services/cartodb_services/google/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/google/geocoder.py @@ -2,8 +2,10 @@ # -*- coding: utf-8 -*- import googlemaps +from urlparse import parse_qs from exceptions import MalformedResult +from cartodb_services.google.exceptions import InvalidGoogleCredentials from client_factory import GoogleMapsClientFactory @@ -11,9 +13,11 @@ class GoogleMapsGeocoder: """A Google Maps Geocoder wrapper for python""" def __init__(self, client_id, client_secret, logger): - self.client_id = self._clean_client_id(client_id) + if client_id is None: + raise InvalidGoogleCredentials + self.client_id, self.channel = self.parse_client_id(client_id) self.client_secret = client_secret - self.geocoder = GoogleMapsClientFactory.get(self.client_id, self.client_secret) + self.geocoder = GoogleMapsClientFactory.get(self.client_id, self.client_secret, self.channel) self._logger = logger def geocode(self, searchtext, city=None, state=None, @@ -46,6 +50,8 @@ class GoogleMapsGeocoder: optional_params['country'] = country return optional_params - def _clean_client_id(self, client_id): - # Consistency with how the client_id is saved in metadata - return client_id.replace('client=', '') + def parse_client_id(self, client_id): + arguments = parse_qs(client_id) + client = arguments['client'][0] if arguments.has_key('client') else client_id + channel = arguments['channel'][0] if arguments.has_key('channel') else None + return client, channel diff --git a/server/lib/python/cartodb_services/setup.py b/server/lib/python/cartodb_services/setup.py index 3b3446a..9133421 100644 --- a/server/lib/python/cartodb_services/setup.py +++ b/server/lib/python/cartodb_services/setup.py @@ -10,7 +10,7 @@ from setuptools import setup, find_packages setup( name='cartodb_services', - version='0.15.5', + version='0.15.6', description='CartoDB Services API Python Library',