-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from mapbox/multi-endpoint
Multi-endpoint refactor
- Loading branch information
Showing
14 changed files
with
105 additions
and
78 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
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,11 +1,8 @@ | ||
var compile = require('es6-template-strings/compile'); | ||
|
||
var API = 'https://api.tiles.mapbox.com/'; | ||
var APIV4 = API + 'v4/'; | ||
|
||
module.exports.API = API; | ||
module.exports.API_GEOCODER_FORWARD = compile(APIV4 + 'geocode/${dataset}/${encodeURIComponent(query)}.json'); | ||
module.exports.API_GEOCODER_REVERSE = compile(APIV4 + 'geocode/${dataset}/${location.longitude},${location.latitude}.json'); | ||
module.exports.API_DIRECTIONS = compile(APIV4 + 'directions/${profile}/${encodedWaypoints}.json'); | ||
module.exports.API_MATCHING = compile(API + 'matching/v4/${profile}.json'); | ||
module.exports.API_SURFACE = compile(APIV4 + 'surface/${mapid}.json'); | ||
module.exports.DEFAULT_ENDPOINT = 'https://api.mapbox.com'; | ||
module.exports.API_GEOCODER_FORWARD = compile('${endpoint}/v4/geocode/${dataset}/${encodeURIComponent(query)}.json?${query}'); | ||
module.exports.API_GEOCODER_REVERSE = compile('${endpoint}/v4/geocode/${dataset}/${location.longitude},${location.latitude}.json?${query}'); | ||
module.exports.API_DIRECTIONS = compile('${endpoint}/v4/directions/${profile}/${encodedWaypoints}.json?${query}'); | ||
module.exports.API_SURFACE = compile('${endpoint}/v4/surface/${mapid}.json?${query}'); | ||
module.exports.API_MATCHING = compile('${endpoint}/matching/v4/${profile}.json?${query}'); |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
var invariant = require('invariant'); | ||
var constants = require('./constants'); | ||
|
||
function makeService(name) { | ||
|
||
function service(accessToken, options) { | ||
this.name = name; | ||
|
||
invariant(typeof accessToken === 'string', | ||
'accessToken required to instantiate MapboxDirections'); | ||
|
||
this.accessToken = accessToken; | ||
this.endpoint = constants.DEFAULT_ENDPOINT; | ||
|
||
if (options !== undefined) { | ||
invariant(typeof options === 'object', 'options must be an object'); | ||
if (options.endpoint) { | ||
invariant(typeof options.endpoint === 'string', 'endpoint must be a string'); | ||
this.endpoint = options.endpoint; | ||
} | ||
} | ||
} | ||
|
||
return service; | ||
} | ||
|
||
module.exports = makeService; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
var xtend = require('xtend'), | ||
qs = require('querystring'), | ||
resolveToString = require('es6-template-strings/resolve-to-string'); | ||
|
||
function makeURL(self, template, params, query) { | ||
return resolveToString(template, | ||
xtend(params, { | ||
endpoint: self.endpoint, | ||
query: qs.stringify(xtend(query, { access_token: self.accessToken })) | ||
})); | ||
} | ||
|
||
module.exports = makeURL; |
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
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
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 was deleted.
Oops, something went wrong.
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