This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
25 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,22 @@ | ||
from uritemplate import URITemplate | ||
"""Distance API V1 **DEPRECATED**""" | ||
|
||
from mapbox.encoding import encode_coordinates_json | ||
from mapbox.errors import InvalidProfileError | ||
from mapbox.services.base import Service | ||
import warnings | ||
|
||
from mapbox.services.matrix import DirectionsMatrix | ||
|
||
class Distance(Service): | ||
"""Access to the Distance API V1""" | ||
|
||
api_name = 'distances' | ||
api_version = 'v1' | ||
class Distance(object): | ||
"""Access to the Distance API V1 ***DEPRECATED**""" | ||
|
||
valid_profiles = ['driving', 'cycling', 'walking'] | ||
|
||
@property | ||
def baseuri(self): | ||
return 'https://{0}/{1}/{2}/mapbox'.format( | ||
self.host, self.api_name, self.api_version) | ||
|
||
def _validate_profile(self, profile): | ||
if profile not in self.valid_profiles: | ||
raise InvalidProfileError( | ||
"{0} is not a valid profile".format(profile)) | ||
return profile | ||
def __init__(self, access_token=None, host=None, cache=None): | ||
warnings.warn( | ||
"The distance module will be removed in the next version. " | ||
"Use the matrix module instead.", DeprecationWarning) | ||
self.access_token = access_token | ||
self.host = host | ||
self.cache = cache | ||
|
||
def distances(self, features, profile='driving'): | ||
profile = self._validate_profile(profile) | ||
coords = encode_coordinates_json(features) | ||
uri = URITemplate(self.baseuri + '/{profile}').expand(profile=profile) | ||
res = self.session.post(uri, data=coords, | ||
headers={'Content-Type': 'application/json'}) | ||
self.handle_http_error(res) | ||
return res | ||
service = DirectionsMatrix( | ||
access_token=self.access_token, host=self.host, cache=self.cache) | ||
return service.matrix(features, profile=profile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters