Added parameters for PLPython functions
This commit is contained in:
@@ -9,8 +9,7 @@ from cartodb_services.metrics import Traceable
|
||||
from cartodb_services.mapbox.exceptions import ServiceException
|
||||
from cartodb_services.tools.qps import qps_retry
|
||||
|
||||
ACCESS_TOKEN = 'pk.eyJ1IjoiYWNhcmxvbiIsImEiOiJjamJuZjQ1Zjc0Ymt4Mnh0YmFrMmhtYnY4In0.gt9cw0VeKc3rM2mV5pcEmg'
|
||||
|
||||
GEOCODER_NAME = 'geocoder_name'
|
||||
EPHEMERAL_GEOCODER = 'mapbox.places'
|
||||
PERMANENT_GEOCODER = 'mapbox.places-permanent'
|
||||
DEFAULT_GEOCODER = EPHEMERAL_GEOCODER
|
||||
@@ -28,9 +27,14 @@ class MapboxGeocoder(Traceable):
|
||||
Python wrapper for the Mapbox Geocoder service.
|
||||
'''
|
||||
|
||||
def __init__(self, token=ACCESS_TOKEN, name=DEFAULT_GEOCODER):
|
||||
def __init__(self, token, logger, service_params=None):
|
||||
service_params = service_params or {}
|
||||
self._token = token
|
||||
self._geocoder = Geocoder(access_token=self._token, name=name)
|
||||
self._logger = logger
|
||||
self._geocoder_name = service_params.get(GEOCODER_NAME,
|
||||
EPHEMERAL_GEOCODER)
|
||||
self._geocoder = Geocoder(access_token=self._token,
|
||||
name=self._geocoder_name)
|
||||
|
||||
def _parse_geocoder_response(self, response):
|
||||
json_response = json.loads(response)
|
||||
|
||||
@@ -37,8 +37,10 @@ class MapboxIsolines():
|
||||
Python wrapper for Mapbox services based isolines.
|
||||
'''
|
||||
|
||||
def __init__(self, matrix_client):
|
||||
def __init__(self, matrix_client, logger, service_params=None):
|
||||
service_params = service_params or {}
|
||||
self._matrix_client = matrix_client
|
||||
self._logger = logger
|
||||
|
||||
def _calculate_matrix_cost(self, origin, targets, isorange,
|
||||
profile=DEFAULT_PROFILE,
|
||||
|
||||
@@ -9,8 +9,6 @@ from cartodb_services.tools.coordinates import (validate_coordinates,
|
||||
from exceptions import ServiceException
|
||||
from cartodb_services.tools.qps import qps_retry
|
||||
|
||||
ACCESS_TOKEN = 'pk.eyJ1IjoiYWNhcmxvbiIsImEiOiJjamJuZjQ1Zjc0Ymt4Mnh0YmFrMmhtYnY4In0.gt9cw0VeKc3rM2mV5pcEmg'
|
||||
|
||||
BASEURI = ('https://api.mapbox.com/directions-matrix/v1/mapbox/{profile}/'
|
||||
'{coordinates}'
|
||||
'?access_token={token}'
|
||||
@@ -48,15 +46,14 @@ class MapboxMatrixClient(Traceable):
|
||||
Python wrapper for the Mapbox Time Matrix service.
|
||||
'''
|
||||
|
||||
def __init__(self, token=ACCESS_TOKEN):
|
||||
self.token = token
|
||||
def __init__(self, token, logger, service_params=None):
|
||||
service_params = service_params or {}
|
||||
self._token = token
|
||||
self._logger = logger
|
||||
|
||||
def _uri(self, coordinates, profile=DEFAULT_PROFILE):
|
||||
return BASEURI.format(profile=profile, coordinates=coordinates,
|
||||
token=self.token)
|
||||
|
||||
def _parse_matrix_response(self, response):
|
||||
return response
|
||||
token=self._token)
|
||||
|
||||
@qps_retry(qps=1)
|
||||
def matrix(self, coordinates, profile=DEFAULT_PROFILE):
|
||||
@@ -70,6 +67,6 @@ class MapboxMatrixClient(Traceable):
|
||||
response = requests.get(uri)
|
||||
|
||||
if response.status_code == requests.codes.ok:
|
||||
return self._parse_matrix_response(response.text)
|
||||
return response.text
|
||||
else:
|
||||
raise ServiceException(response.status_code, response.content)
|
||||
|
||||
@@ -11,8 +11,6 @@ from cartodb_services.tools.coordinates import (validate_coordinates,
|
||||
from cartodb_services.mapbox.exceptions import ServiceException
|
||||
from cartodb_services.tools.qps import qps_retry
|
||||
|
||||
ACCESS_TOKEN = 'pk.eyJ1IjoiYWNhcmxvbiIsImEiOiJjamJuZjQ1Zjc0Ymt4Mnh0YmFrMmhtYnY4In0.gt9cw0VeKc3rM2mV5pcEmg'
|
||||
|
||||
BASEURI = ('https://api.mapbox.com/directions/v5/mapbox/{profile}/'
|
||||
'{coordinates}'
|
||||
'?access_token={token}'
|
||||
@@ -45,8 +43,10 @@ class MapboxRouting(Traceable):
|
||||
Python wrapper for the Mapbox Routing service.
|
||||
'''
|
||||
|
||||
def __init__(self, token=ACCESS_TOKEN):
|
||||
def __init__(self, token, logger, service_params=None):
|
||||
service_params = service_params or {}
|
||||
self._token = token
|
||||
self._logger = logger
|
||||
|
||||
def _uri(self, coordinates, profile=DEFAULT_PROFILE,
|
||||
overview=DEFAULT_OVERVIEW):
|
||||
|
||||
Reference in New Issue
Block a user