From 1a34044df2b7fbea79fab65d3c97b15415a5d88b Mon Sep 17 00:00:00 2001 From: Landon Reed Date: Thu, 8 Jun 2017 10:34:12 -0400 Subject: [PATCH 1/4] feat(url-param): add optional url param for overriding Mapzen Search with custom Pelias instance #39 --- index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 614165f..b10d0c1 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,7 @@ const searchUrl = `${mapzenUrl}/search` * {@link https://mapzen.com/documentation/search/autocomplete/#layers|layer types} * @param {string} [$0.sources='gn,oa,osm,wof'] * @param {string} $0.text query text + * @param {string} $0.url optional URL to override Mapzen autocomplete endpoint * @return {Promise} A Promise that'll get resolved with the autocomplete result */ export function autocomplete ({ @@ -35,7 +36,8 @@ export function autocomplete ({ format, layers, sources = 'gn,oa,osm,wof', - text + text, + url = autocompleteUrl }) { // build query const query = { @@ -75,7 +77,7 @@ export function autocomplete ({ return run({ format, query, - url: autocompleteUrl + url }) } @@ -92,6 +94,7 @@ export function autocomplete ({ * @param {number} [$0.size=10] * @param {string} [$0.sources='gn,oa,osm,wof'] * @param {string} $0.text The address text to query for + * @param {string} $0.url optional URL to override Mapzen search endpoint * @return {Promise} A Promise that'll get resolved with search result */ export function search ({ @@ -101,7 +104,8 @@ export function search ({ format, size = 10, sources = 'gn,oa,osm,wof', - text + text, + url = searchUrl }) { if (!text) return Promise.resolve([]) @@ -146,12 +150,14 @@ export function search ({ * @param {string} $0.apiKey The Mapzen API key * @param {boolean} $0.format * @param {{lat: number, lon: number}} $0.point Point to reverse geocode + * @param {string} $0.url optional URL to override Mapzen reverse endpoint * @return {Promise} A Promise that'll get resolved with reverse geocode result */ export function reverse ({ apiKey, format, - point + point, + url = reverseUrl }) { const {lon, lat} = lonlat(point) return run({ @@ -161,7 +167,7 @@ export function reverse ({ 'point.lat': lat, 'point.lon': lon }, - url: reverseUrl + url }) } From 8596da4e6d7fd48c0c5fef85973b2c1a456851fd Mon Sep 17 00:00:00 2001 From: Landon Reed Date: Thu, 8 Jun 2017 11:11:37 -0400 Subject: [PATCH 2/4] docs(url-param): make url param optional; generate docs --- README.md | 3 +++ index.js | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 51caa48..dc303b8 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ service. [layer types](https://mapzen.com/documentation/search/autocomplete/#layers) - `$0.sources` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** (optional, default `'gn,oa,osm,wof'`) - `$0.text` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** query text + - `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen autocomplete endpoint Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with the autocomplete result @@ -122,6 +123,7 @@ service. - `$0.size` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** (optional, default `10`) - `$0.sources` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** (optional, default `'gn,oa,osm,wof'`) - `$0.text` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The address text to query for + - `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen search endpoint Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with search result @@ -137,5 +139,6 @@ service. - `$0.apiKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The Mapzen API key - `$0.format` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** - `$0.point` **{lat: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), lon: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)}** Point to reverse geocode + - `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen reverse endpoint Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with reverse geocode result diff --git a/index.js b/index.js index b10d0c1..d8bf453 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ const searchUrl = `${mapzenUrl}/search` * {@link https://mapzen.com/documentation/search/autocomplete/#layers|layer types} * @param {string} [$0.sources='gn,oa,osm,wof'] * @param {string} $0.text query text - * @param {string} $0.url optional URL to override Mapzen autocomplete endpoint + * @param {string} [$0.url] optional URL to override Mapzen autocomplete endpoint * @return {Promise} A Promise that'll get resolved with the autocomplete result */ export function autocomplete ({ @@ -94,7 +94,7 @@ export function autocomplete ({ * @param {number} [$0.size=10] * @param {string} [$0.sources='gn,oa,osm,wof'] * @param {string} $0.text The address text to query for - * @param {string} $0.url optional URL to override Mapzen search endpoint + * @param {string} [$0.url] optional URL to override Mapzen search endpoint * @return {Promise} A Promise that'll get resolved with search result */ export function search ({ @@ -150,7 +150,7 @@ export function search ({ * @param {string} $0.apiKey The Mapzen API key * @param {boolean} $0.format * @param {{lat: number, lon: number}} $0.point Point to reverse geocode - * @param {string} $0.url optional URL to override Mapzen reverse endpoint + * @param {string} [$0.url] optional URL to override Mapzen reverse endpoint * @return {Promise} A Promise that'll get resolved with reverse geocode result */ export function reverse ({ From 741afcee21cc72e68979c1d17131835536148dd9 Mon Sep 17 00:00:00 2001 From: Landon Reed Date: Thu, 8 Jun 2017 11:31:28 -0400 Subject: [PATCH 3/4] docs(url-param): add default value for url param --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d8bf453..f2b472a 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ const searchUrl = `${mapzenUrl}/search` * {@link https://mapzen.com/documentation/search/autocomplete/#layers|layer types} * @param {string} [$0.sources='gn,oa,osm,wof'] * @param {string} $0.text query text - * @param {string} [$0.url] optional URL to override Mapzen autocomplete endpoint + * @param {string} [$0.url='https://search.mapzen.com/v1/autocomplete'] optional URL to override Mapzen autocomplete endpoint * @return {Promise} A Promise that'll get resolved with the autocomplete result */ export function autocomplete ({ @@ -94,7 +94,7 @@ export function autocomplete ({ * @param {number} [$0.size=10] * @param {string} [$0.sources='gn,oa,osm,wof'] * @param {string} $0.text The address text to query for - * @param {string} [$0.url] optional URL to override Mapzen search endpoint + * @param {string} [$0.url='https://search.mapzen.com/v1/search'] optional URL to override Mapzen search endpoint * @return {Promise} A Promise that'll get resolved with search result */ export function search ({ @@ -150,7 +150,7 @@ export function search ({ * @param {string} $0.apiKey The Mapzen API key * @param {boolean} $0.format * @param {{lat: number, lon: number}} $0.point Point to reverse geocode - * @param {string} [$0.url] optional URL to override Mapzen reverse endpoint + * @param {string} [$0.url='https://search.mapzen.com/v1/reverse'] optional URL to override Mapzen reverse endpoint * @return {Promise} A Promise that'll get resolved with reverse geocode result */ export function reverse ({ From 8ceebff515ecf1bd1c6fa78dd9e061b4455e0277 Mon Sep 17 00:00:00 2001 From: Landon Reed Date: Thu, 8 Jun 2017 11:38:52 -0400 Subject: [PATCH 4/4] docs(url-param): update readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dc303b8..6786180 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ service. [layer types](https://mapzen.com/documentation/search/autocomplete/#layers) - `$0.sources` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** (optional, default `'gn,oa,osm,wof'`) - `$0.text` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** query text - - `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen autocomplete endpoint + - `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen autocomplete endpoint (optional, default `'https://search.mapzen.com/v1/autocomplete'`) Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with the autocomplete result @@ -123,7 +123,7 @@ service. - `$0.size` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** (optional, default `10`) - `$0.sources` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** (optional, default `'gn,oa,osm,wof'`) - `$0.text` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The address text to query for - - `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen search endpoint + - `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen search endpoint (optional, default `'https://search.mapzen.com/v1/search'`) Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with search result @@ -139,6 +139,6 @@ service. - `$0.apiKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The Mapzen API key - `$0.format` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** - `$0.point` **{lat: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), lon: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)}** Point to reverse geocode - - `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen reverse endpoint + - `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen reverse endpoint (optional, default `'https://search.mapzen.com/v1/reverse'`) Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with reverse geocode result