From 11edbe6f23be986ef5293f19d274d44f9190ec14 Mon Sep 17 00:00:00 2001 From: iBinh Date: Tue, 13 Jul 2021 15:30:12 +0700 Subject: [PATCH] update geocoding api --- .github/workflows/npm-publish.yml | 2 +- README.md | 36 ++--- config/service-doc.yml | 17 +-- docs/services.md | 236 +++++++++++++++++++----------- package-lock.json | 2 +- package.json | 9 +- services/autocomplete.js | 8 +- services/directions.js | 10 +- services/distancematrix.js | 8 +- services/geocoding.js | 67 ++++++++- services/static.js | 2 +- umd/goong-sdk.js | 4 +- umd/goong-sdk.min.js | 2 +- 13 files changed, 251 insertions(+), 152 deletions(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 70d35e1..fb45b28 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -13,7 +13,7 @@ jobs: with: node-version: 12 registry-url: https://registry.npmjs.org/ - - run: yarn install + - run: npm install - run: npm publish --access public env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/README.md b/README.md index f3417b4..9a5018a 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,22 @@ # @goongmaps/goong-sdk + [![npm](https://img.shields.io/npm/v/@goongmaps/goong-sdk.svg)](https://www.npmjs.com/package/@goongmaps/goong-sdk) -A JS SDK for working with [Goong REST APIs](https://docs.goong.io/rest/). +A Javascript SDK for working with [Goong REST APIs](https://docs.goong.io/rest/). + +- [Directions API](https://docs.goong.io/rest/directions/) +- [Distance Matrix API](https://docs.goong.io/rest/distance_matrix/) +- [Geocoding API](https://docs.goong.io/rest/geocode/) +- [Place API](https://docs.goong.io/rest/place/) +- [Static Map API](https://docs.goong.io/rest/staticmap/) - - [Directions API](https://docs.goong.io/rest/direction/) - - [Distance Matrix API](https://docs.goong.io/rest/distance_matrix/) - - [Geocoding API](https://docs.goong.io/rest/geocode/) - - [Place API](https://docs.goong.io/rest/place/) - - [Static Map API](https://docs.goong.io/rest/staticmap/) - Works in Node, the browser, and React Native. ## Table of contents - [Installation](#installation) + - [Npm](#npm) + - [Yarn](#yarn) - [Usage](#usage) - [Creating clients](#creating-clients) - [Creating and sending requests](#creating-and-sending-requests) @@ -21,14 +24,19 @@ Works in Node, the browser, and React Native. - [Pre-bundled files on unpkg.com](#pre-bundled-files-on-unpkgcom) ## Installation + ### Npm + ``` npm install @goongmaps/goong-sdk ``` + ### Yarn + ``` yarn add @gongmaps/goong-sdk ``` + **If you are supporting older browsers, you will need a Promise polyfill.** [es6-promise](https://github.com/stefanpenner/es6-promise) is a good one, if you're uncertain. @@ -45,7 +53,7 @@ There are 3 basic steps to getting an API response: ### Creating clients -To **create a service client**, import the service's factory function from `'@goongmaps/goong-sdk/services/{service}'` and provide it with your access token. +To **create a service client**, import the service's factory function from `'@goongmaps/goong-sdk/services/{service}'` and provide it with your [access token](https://docs.goong.io/rest/api-key/). The service client exposes methods that create requests. @@ -109,15 +117,3 @@ Here's how you might use it. .then(..); ``` - -[`got`]: https://github.com/sindresorhus/got - -[`http`]: https://nodejs.org/api/http.html - -[`xmlhttprequest`]: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest - -[`gapirequest`]: #gapirequest - -[`gapiresponse`]: #gapiresponse - -[`gapierror`]: #gapierror diff --git a/config/service-doc.yml b/config/service-doc.yml index 8339d67..bf2b323 100644 --- a/config/service-doc.yml +++ b/config/service-doc.yml @@ -3,19 +3,4 @@ toc: - Geocoding - Autocomplete - Directions - - DistanceMatrix - # - name: Data structures - # description: | - # Data structures used in service method configuration. - # children: - # - DirectionsWaypoint - # - MapMatchingPoint - # - MatrixPoint - # - OptimizationWaypoint - # - SimpleMarkerOverlay - # - CustomMarkerOverlay - # - PathOverlay - # - GeoJsonOverlay - # - UploadableFile - # - Coordinates - # - BoundingBox \ No newline at end of file + - DistanceMatrix \ No newline at end of file diff --git a/docs/services.md b/docs/services.md index 0cac6b6..bb993c3 100644 --- a/docs/services.md +++ b/docs/services.md @@ -10,28 +10,34 @@ - [reverseGeocode][6] - [Parameters][7] - [Examples][8] -- [Autocomplete][9] - - [search][10] - - [Parameters][11] - - [Examples][12] - - [placeDetail][13] - - [Parameters][14] - - [Examples][15] -- [Directions][16] - - [getDirections][17] - - [Parameters][18] - - [Examples][19] -- [DistanceMatrix][20] - - [getMatrix][21] - - [Parameters][22] - - [Examples][23] + - [forwardGeocode][9] + - [Parameters][10] + - [Examples][11] + - [placeDetail][12] + - [Parameters][13] + - [Examples][14] +- [Autocomplete][15] + - [search][16] + - [Parameters][17] + - [Examples][18] + - [placeDetail][19] + - [Parameters][20] + - [Examples][21] +- [Directions][22] + - [getDirections][23] + - [Parameters][24] + - [Examples][25] +- [DistanceMatrix][26] + - [getMatrix][27] + - [Parameters][28] + - [Examples][29] ## Static Static Images API service. Learn more about this service and its responses in -[Goong REST API documentation][24]. +[Goong Static Map API documentation][30]. ### getStaticImage @@ -39,14 +45,14 @@ Get a static map image. #### Parameters -- `config` **[Object][25]** - - `config.origin` **[number][26]** Origin coordinate `latitude,longitude` - - `config.destination` **[string][27]** Destination coordinate `latitude,longitude` - - `config.width` **[number][26]** Width of the image in pixels, default 600px. (optional, default `600`) - - `config.height` **[number][26]** Height of the image in pixels, default 400px. (optional, default `400`) +- `config` **[Object][31]** + - `config.origin` **[number][32]** Origin coordinate `latitude,longitude` + - `config.destination` **[string][33]** Destination coordinate `latitude,longitude` + - `config.width` **[number][32]** Width of the image in pixels, default 600px. (optional, default `600`) + - `config.height` **[number][32]** Height of the image in pixels, default 400px. (optional, default `400`) - `config.vehicle` **(`"car"` \| `"bike"` \| `"taxi"`)** Vehicle type (optional, default `'car'`) - `config.type` **(`"fastest"` \| `"shortest"`)** Routing type (optional, default `'fastest'`) - - `config.color` **[string][27]** Color of route line, default #253494 (optional, default `'#253494'`) + - `config.color` **[string][33]** Color of route line, default #253494 (optional, default `'#253494'`) #### Examples @@ -74,26 +80,74 @@ Returns **GAPIRequest** Geocoding API service. Learn more about this service and its responses in -[Goong REST API documentation][28]. +[Goong Geocoding API documentation][34]. ### reverseGeocode -Get Place by coordinate +Reverse Geocoding #### Parameters -- `config` **[Object][25]** - - `config.latlng` **[string][27]** Coordinates at which features will be reversed. +- `config` **[Object][31]** + - `config.latlng` **[string][33]** Coordinates at which features will be reversed. #### Examples ```javascript geocodingClient.reverseGeocode({ - latlng: '20.981971,105.864323' + latlng: '21.0137443130001,105.798346108' }) .send() .then(response => { - // GeoJSON document with geocoding matches + // JSON document with geocoding matches + const match = response.body; + }); +``` + +Returns **GAPIRequest** + +### forwardGeocode + +Forward Geocoding + +#### Parameters + +- `config` **[Object][31]** + - `config.address` **[string][33]** Address string you are looking for + +#### Examples + +```javascript +geocodingClient.forwardGeocode({ + address: '91 Trung Kinh, Trung Hoa, Cau Giay, Ha Noi' +}) + .send() + .then(response => { + // JSON document with geocoding matches + const match = response.body; + }); +``` + +Returns **GAPIRequest** + +### placeDetail + +Get Place detail + +#### Parameters + +- `config` **[Object][31]** + - `config.place_id` **[string][33]** Place ID string + +#### Examples + +```javascript +geocodingClient.placeDetail({ + place_id: 'uq58Yr/RA0wuHVtqzDczw7bbR4Gs7gs2b5DRZtogUr2bvWTaN5Vb2qd/atCZ1FoPg7cdIqFo9E_2TxQzrc20hw==.ZXhwYW5kMA==' +}) + .send() + .then(response => { + // JSON document with geocoding matches const match = response.body; }); ``` @@ -105,23 +159,23 @@ Returns **GAPIRequest** Autocomplete API service. Learn more about this service and its responses in -[Goong REST API documentation][29]. +[Goong Places API documentation][35]. ### search Autocomplete search -See the [public documentation][30]. +See the [public documentation][36]. #### Parameters -- `config` **[Object][25]** - - `config.input` **[string][27]** A place name. - - `config.location` **[string][27]** A location to use as a hint when looking up the specified address - `latitude,longitude` - - `config.radius` **[number][26]** Distance round from your location by kilometers - - `config.limit` **[number][26]** Limit the number of results returned. - Options are [IETF language tags][31] comprised of a mandatory - [ISO 639-1 language code][32] and optionally one or more IETF subtags for country or script. (optional, default `10`) +- `config` **[Object][31]** + - `config.input` **[string][33]** A place name. + - `config.location` **[string][33]** A location to use as a hint when looking up the specified address - `latitude,longitude` + - `config.radius` **[number][32]** Distance round from your location by kilometers + - `config.limit` **[number][32]** Limit the number of results returned. + Options are [IETF language tags][37] comprised of a mandatory + [ISO 639-1 language code][38] and optionally one or more IETF subtags for country or script. (optional, default `10`) #### Examples @@ -155,14 +209,14 @@ Returns **GAPIRequest** Autocomplete get place detail -See the [public documentation][33]. +See the [public documentation][39]. #### Parameters -- `config` **[Object][25]** - - `config.placeID` **[string][27]** Place id from `Autocomplete` or `Geocoding`. - Options are [IETF language tags][31] comprised of a mandatory - [ISO 639-1 language code][32] and optionally one or more IETF subtags for country or script. +- `config` **[Object][31]** + - `config.placeID` **[string][33]** Place id from `Autocomplete` or `Geocoding`. + Options are [IETF language tags][37] comprised of a mandatory + [ISO 639-1 language code][38] and optionally one or more IETF subtags for country or script. #### Examples @@ -183,7 +237,7 @@ Returns **GAPIRequest** Directions API service. Learn more about this service and its responses in -[Goong REST API documentation][34]. +[Goong Directions API documentation][40]. ### getDirections @@ -191,12 +245,11 @@ Get directions. #### Parameters -- `config` **[Object][25]** - - `config.origin` **[number][26]** Origin coordinate `latitude,longitude` - - `config.destination` **[string][27]** Destination coordinate `latitude,longitude` - - `config.alternatives` **[boolean][35]** Whether to try to return alternative routes. (optional, default `true`) - - `config.vehicle` **(`"car"` \| `"bike"` \| `"taxi"`)** Vehicle type (optional, default `'car'`) - - `config.type` **(`"fastest"` \| `"shortest"`)** Routing type (optional, default `'fastest'`) +- `config` **[Object][31]** + - `config.origin` **[number][32]** Origin coordinate `latitude,longitude` + - `config.destination` **[string][33]** Destination coordinate `latitude,longitude` + - `config.alternatives` **[boolean][41]** Whether to try to return alternative routes. (optional, default `true`) + - `config.vehicle` **(`"car"` \| `"bike"` \| `"taxi"` \| `"hd"`)** Vehicle type (optional, default `'car'`) #### Examples @@ -205,8 +258,7 @@ directionsClient.getDirections({ origin: '20.981971,105.864323', destination: '21.031011,105.783206', alternatives: true, - vehicle: 'car', - type: 'shortest' + vehicle: 'car' }) .send() .then(response => { @@ -221,7 +273,7 @@ Returns **GAPIRequest** Map Matching API service. Learn more about this service and its responses in -[Goong REST API documentation][36]. +[Goong Distance Matrix API documentation][42]. ### getMatrix @@ -229,11 +281,10 @@ Get a duration and/or distance matrix showing travel times and distances between #### Parameters -- `config` **[Object][25]** - - `config.origins` **[number][26]** Origin coordinate: `latitude,longitude|latitude,longitude` - - `config.destinations` **[string][27]** List of destination coordinate: `latitude,longitude|latitude,longitude|latitude,longitude` - - `config.vehicle` **(`"car"` \| `"bike"` \| `"taxi"`)** Vehicle type (optional, default `'car'`) - - `config.type` **(`"fastest"` \| `"shortest"`)** Routing type (optional, default `'fastest'`) +- `config` **[Object][31]** + - `config.origins` **[number][32]** Origin coordinate: `latitude,longitude|latitude,longitude` + - `config.destinations` **[string][33]** List of destination coordinate: `latitude,longitude|latitude,longitude|latitude,longitude` + - `config.vehicle` **(`"car"` \| `"bike"` \| `"taxi"` \| `"hd"`)** Vehicle type (optional, default `'car'`) #### Examples @@ -241,8 +292,7 @@ Get a duration and/or distance matrix showing travel times and distances between matrixClient.getMatrix({ origins: '20.981971,105.864323', destinations: '21.031011,105.783206|21.022328,105.790480|21.016665,105.788774', - vehicle: 'car', - type: 'fastest', + vehicle: 'car' }) .send() .then(response => { @@ -268,58 +318,70 @@ Returns **GAPIRequest** [8]: #examples-1 -[9]: #autocomplete +[9]: #forwardgeocode + +[10]: #parameters-2 + +[11]: #examples-2 + +[12]: #placedetail + +[13]: #parameters-3 + +[14]: #examples-3 + +[15]: #autocomplete -[10]: #search +[16]: #search -[11]: #parameters-2 +[17]: #parameters-4 -[12]: #examples-2 +[18]: #examples-4 -[13]: #placedetail +[19]: #placedetail-1 -[14]: #parameters-3 +[20]: #parameters-5 -[15]: #examples-3 +[21]: #examples-5 -[16]: #directions +[22]: #directions -[17]: #getdirections +[23]: #getdirections -[18]: #parameters-4 +[24]: #parameters-6 -[19]: #examples-4 +[25]: #examples-6 -[20]: #distancematrix +[26]: #distancematrix -[21]: #getmatrix +[27]: #getmatrix -[22]: #parameters-5 +[28]: #parameters-7 -[23]: #examples-5 +[29]: #examples-7 -[24]: https://docs.goong.io/rest/guide#static-map +[30]: https://docs.goong.io/rest/staticmap/ -[25]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[31]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[26]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number +[32]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number -[27]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[33]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[28]: https://docs.goong.io/rest/guide#geocode +[34]: https://docs.goong.io/rest/geocode -[29]: https://docs.goong.io/rest/guide#place +[35]: https://docs.goong.io/rest/place/ -[30]: https://docs.goong.io/rest/guide#get-points-by-keyword +[36]: https://docs.goong.io/rest/place/#places-search-by-keyword-with-autocomplete -[31]: https://en.wikipedia.org/wiki/IETF_language_tag +[37]: https://en.wikipedia.org/wiki/IETF_language_tag -[32]: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes +[38]: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes -[33]: https://docs.goong.io/rest/guide#get-point-detail-by-id +[39]: https://docs.goong.io/rest/place/#get-place-detail-by-id -[34]: https://docs.goong.io/rest/guide#direction +[40]: https://docs.goong.io/rest/directions -[35]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[41]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean -[36]: https://docs.goong.io/rest/guide#distance-matrix +[42]: https://docs.goong.io/rest/distance_matrix/ diff --git a/package-lock.json b/package-lock.json index 280d903..e09be46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@goongmaps/goong-sdk", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 877b682..b9e9e30 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@goongmaps/goong-sdk", - "version": "1.0.4", - "description": "JS SDK for Goong REST API", + "version": "1.0.5", + "description": "A Javascript SDK working with Goong REST APIs", "main": "index.js", "files": [ "umd", @@ -27,11 +27,12 @@ "keywords": [ "goong", "goong-js", - "goong-api", + "goong-rest-api", "directions", "distance-matrix", "autocomplete", - "geocoding" + "geocoding", + "static-map" ], "author": "Goong", "license": "ISC", diff --git a/services/autocomplete.js b/services/autocomplete.js index 4dd7c70..4a54a6a 100644 --- a/services/autocomplete.js +++ b/services/autocomplete.js @@ -7,14 +7,14 @@ var createServiceFactory = require('./service-helpers/create-service-factory'); * Autocomplete API service. * * Learn more about this service and its responses in - * [Goong REST API documentation](https://docs.goong.io/rest/guide#place). + * [Goong Places API documentation](https://docs.goong.io/rest/place/). */ var Autocomplete = {}; /** * Autocomplete search * - * See the [public documentation](https://docs.goong.io/rest/guide#get-points-by-keyword). + * See the [public documentation](https://docs.goong.io/rest/place/#places-search-by-keyword-with-autocomplete). * * @param {Object} config * @param {string} config.input - A place name. @@ -65,7 +65,7 @@ Autocomplete.search = function(config) { /** * Autocomplete get place detail * - * See the [public documentation](https://docs.goong.io/rest/guide#get-point-detail-by-id). + * See the [public documentation](https://docs.goong.io/rest/place/#get-place-detail-by-id). * * @param {Object} config * @param {string} config.placeID - Place id from `Autocomplete` or `Geocoding`. @@ -89,7 +89,7 @@ Autocomplete.placeDetail = function(config) { return this.client.createRequest({ method: 'GET', - path: '/place/detail', + path: '/Place/Detail', query: config }); }; diff --git a/services/directions.js b/services/directions.js index a9ea94d..8abeccc 100644 --- a/services/directions.js +++ b/services/directions.js @@ -8,7 +8,7 @@ var createServiceFactory = require('./service-helpers/create-service-factory'); * Directions API service. * * Learn more about this service and its responses in - * [Goong REST API documentation](https://docs.goong.io/rest/guide#direction). + * [Goong Directions API documentation](https://docs.goong.io/rest/directions). */ var Directions = {}; @@ -17,10 +17,9 @@ var Directions = {}; * * @param {Object} config * @param {number} config.origin - Origin coordinate `latitude,longitude` - * @param {string} config.destination - Destination coordinate `latitude,longitude` + * @param {string} config.destination - The destination coordinate string. Split by `;` for more than 2 destinations. * @param {boolean} [config.alternatives=true] - Whether to try to return alternative routes. - * @param {'car'|'bike'|'taxi'} [config.vehicle='car'] - Vehicle type - * @param {'fastest'|'shortest'} [config.type='fastest'] - Routing type + * @param {'car'|'bike'|'taxi'|'hd'} [config.vehicle='car'] - Vehicle type * @return {GAPIRequest} * @@ -29,8 +28,7 @@ var Directions = {}; * origin: '20.981971,105.864323', * destination: '21.031011,105.783206', * alternatives: true, - * vehicle: 'car', - * type: 'shortest' + * vehicle: 'car' * }) * .send() * .then(response => { diff --git a/services/distancematrix.js b/services/distancematrix.js index 468a8a9..0d2737a 100644 --- a/services/distancematrix.js +++ b/services/distancematrix.js @@ -7,7 +7,7 @@ var createServiceFactory = require('./service-helpers/create-service-factory'); * Map Matching API service. * * Learn more about this service and its responses in - * [Goong REST API documentation](https://docs.goong.io/rest/guide#distance-matrix). + * [Goong Distance Matrix API documentation](https://docs.goong.io/rest/distance_matrix/). */ var DistanceMatrix = {}; @@ -17,16 +17,14 @@ var DistanceMatrix = {}; * @param {Object} config * @param {number} config.origins - Origin coordinate: `latitude,longitude|latitude,longitude` * @param {string} config.destinations - List of destination coordinate: `latitude,longitude|latitude,longitude|latitude,longitude` - * @param {'car'|'bike'|'taxi'} [config.vehicle='car'] - Vehicle type - * @param {'fastest'|'shortest'} [config.type='fastest'] - Routing type + * @param {'car'|'bike'|'taxi'|'hd'} [config.vehicle='car'] - Vehicle type * @return {GAPIRequest} * * @example * matrixClient.getMatrix({ * origins: '20.981971,105.864323', * destinations: '21.031011,105.783206|21.022328,105.790480|21.016665,105.788774', - * vehicle: 'car', - * type: 'fastest', + * vehicle: 'car' * }) * .send() * .then(response => { diff --git a/services/geocoding.js b/services/geocoding.js index a4dcedc..deb713e 100644 --- a/services/geocoding.js +++ b/services/geocoding.js @@ -7,12 +7,12 @@ var createServiceFactory = require('./service-helpers/create-service-factory'); * Geocoding API service. * * Learn more about this service and its responses in - * [Goong REST API documentation](https://docs.goong.io/rest/guide#geocode). + * [Goong Geocoding API documentation](https://docs.goong.io/rest/geocode). */ var Geocoding = {}; /** - * Get Place by coordinate + * Reverse Geocoding * * @param {Object} config * @param {string} config.latlng - Coordinates at which features will be reversed. @@ -20,11 +20,11 @@ var Geocoding = {}; * * @example * geocodingClient.reverseGeocode({ - * latlng: '20.981971,105.864323' + * latlng: '21.0137443130001,105.798346108' * }) * .send() * .then(response => { - * // GeoJSON document with geocoding matches + * // JSON document with geocoding matches * const match = response.body; * }); */ @@ -40,4 +40,63 @@ Geocoding.reverseGeocode = function(config) { }); }; +/** + * Forward Geocoding + * + * @param {Object} config + * @param {string} config.address - Address string you are looking for + * @return {GAPIRequest} + * + * @example + * geocodingClient.forwardGeocode({ + * address: '91 Trung Kinh, Trung Hoa, Cau Giay, Ha Noi' + * }) + * .send() + * .then(response => { + * // JSON document with geocoding matches + * const match = response.body; + * }); + */ + Geocoding.forwardGeocode = function(config) { + v.assertShape({ + address: v.required(v.string) + })(config); + + return this.client.createRequest({ + method: 'GET', + path: '/Geocode', + query: config + }); +}; + + +/** + * Get Place detail + * + * @param {Object} config + * @param {string} config.place_id - Place ID string + * @return {GAPIRequest} + * + * @example + * geocodingClient.placeDetail({ + * place_id: 'uq58Yr/RA0wuHVtqzDczw7bbR4Gs7gs2b5DRZtogUr2bvWTaN5Vb2qd/atCZ1FoPg7cdIqFo9E_2TxQzrc20hw==.ZXhwYW5kMA==' + * }) + * .send() + * .then(response => { + * // JSON document with geocoding matches + * const match = response.body; + * }); + */ + Geocoding.placeDetail = function(config) { + v.assertShape({ + address: v.required(v.string) + })(config); + + return this.client.createRequest({ + method: 'GET', + path: '/Geocode', + query: config + }); +}; + module.exports = createServiceFactory(Geocoding); diff --git a/services/static.js b/services/static.js index ee95092..efa514e 100644 --- a/services/static.js +++ b/services/static.js @@ -6,7 +6,7 @@ var createServiceFactory = require('./service-helpers/create-service-factory'); * Static Images API service. * * Learn more about this service and its responses in - * [Goong REST API documentation](https://docs.goong.io/rest/guide#static-map). + * [Goong Static Map API documentation](https://docs.goong.io/rest/staticmap/). */ var Static = {}; diff --git a/umd/goong-sdk.js b/umd/goong-sdk.js index b52f2e8..3dc1f42 100644 --- a/umd/goong-sdk.js +++ b/umd/goong-sdk.js @@ -1666,7 +1666,7 @@ return this.client.createRequest({ method: 'GET', - path: '/Place/AutoComplete', + path: '/place/autocomplete', query: config }); }; @@ -1698,7 +1698,7 @@ return this.client.createRequest({ method: 'GET', - path: '/Place/Detail', + path: '/place/detail', query: config }); }; diff --git a/umd/goong-sdk.min.js b/umd/goong-sdk.min.js index 2a8e671..2494a20 100644 --- a/umd/goong-sdk.min.js +++ b/umd/goong-sdk.min.js @@ -1 +1 @@ -(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):global.goongSdk=factory()})(this,function(){"use strict";function parseParam(param){var parts=param.match(/\s*(.+)\s*=\s*"?([^"]+)"?/);if(!parts)return null;return{key:parts[1],value:parts[2]}}function parseLink(link){var parts=link.match(/]*)>(.*)/);if(!parts)return null;var linkUrl=parts[1];var linkParams=parts[2].split(";");var rel=null;var parsedLinkParams=linkParams.reduce(function(result,param){var parsed=parseParam(param);if(!parsed)return result;if(parsed.key==="rel"){if(!rel){rel=parsed.value}return result}result[parsed.key]=parsed.value;return result},{});if(!rel)return null;return{url:linkUrl,rel:rel,params:parsedLinkParams}}function parseLinkHeader(linkHeader){if(!linkHeader)return{};return linkHeader.split(/,\s*=400){var gAPIError=new gapiError({request:request,body:xhr.response,statusCode:xhr.status});reject(gAPIError);return}resolve(xhr)};var body=request.body;if(typeof body==="string"){xhr.send(body)}else if(body){xhr.send(JSON.stringify(body))}else if(file){xhr.send(file)}else{xhr.send()}requestsUnderway[request.id]=xhr}).then(function(xhr){return createResponse(request,xhr)})}function createRequestXhr(request,accessToken){var url=request.url(accessToken);var xhr=new window.XMLHttpRequest;xhr.open(request.method,url);Object.keys(request.headers).forEach(function(key){xhr.setRequestHeader(key,request.headers[key])});xhr.timeout=request.timeout;return xhr}function browserSend(request){return Promise.resolve().then(function(){var xhr=createRequestXhr(request,request.client.accessToken);return sendRequestXhr(request,xhr)})}var browserLayer={browserAbort:browserAbort,sendRequestXhr:sendRequestXhr,browserSend:browserSend,createRequestXhr:createRequestXhr};var immutable=extend;var hasOwnProperty=Object.prototype.hasOwnProperty;function extend(){var target={};for(var i=0;imax.length?arr:max})}};v.equal=function equal(compareWith){return function equalValidator(value){if(value!==compareWith){return JSON.stringify(compareWith)}}};v.oneOf=function oneOf(){var options=Array.isArray(arguments[0])?arguments[0]:Array.prototype.slice.call(arguments);var validators=options.map(function(value){return v.equal(value)});return v.oneOfType.apply(this,validators)};v.range=function range(compareWith){var min=compareWith[0];var max=compareWith[1];return function rangeValidator(value){var validationResult=validate(v.number,value);if(validationResult||valuemax){return"number between "+min+" & "+max+" (inclusive)"}}};v.any=function any(){return};v.boolean=function boolean(value){if(typeof value!=="boolean"){return"boolean"}};v.number=function number(value){if(typeof value!=="number"){return"number"}};v.plainArray=function plainArray(value){if(!Array.isArray(value)){return"array"}};v.plainObject=function plainObject(value){if(!isPlainObj(value)){return"object"}};v.string=function string(value){if(typeof value!=="string"){return"string"}};v.func=function func(value){if(typeof value!=="function"){return"function"}};function validate(validator,value){if(value==null&&!validator.hasOwnProperty("__required")){return}var result=validator(value);if(result){return Array.isArray(result)?result:[result]}}function processMessage(message,options){var len=message.length;var result=message[len-1];var path=message.slice(0,len-1);if(path.length===0){path=[DEFAULT_ERROR_PATH]}options=immutable(options,{path:path});return typeof result==="function"?result(options):formatErrorMessage(options,prettifyResult(result))}function orList(list){if(list.length<2){return list[0]}if(list.length===2){return list.join(" or ")}return list.slice(0,-1).join(", ")+", or "+list.slice(-1)}function prettifyResult(result){return"must be "+addArticle(result)+"."}function addArticle(nounPhrase){if(/^an? /.test(nounPhrase)){return nounPhrase}if(/^[aeiou]/i.test(nounPhrase)){return"an "+nounPhrase}if(/^[a-z]/i.test(nounPhrase)){return"a "+nounPhrase}return nounPhrase}function formatErrorMessage(options,prettyResult){var arrayCulprit=isArrayCulprit(options.path);var output=options.path.join(".")+" "+prettyResult;var prepend=arrayCulprit?"Item at position ":"";return prepend+output}function isArrayCulprit(path){return typeof path[path.length-1]=="number"||typeof path[0]=="number"}function objectEntries(obj){return Object.keys(obj||{}).map(function(key){return{key:key,value:obj[key]}})}v.validate=validate;v.processMessage=processMessage;var lib=v;function file(value){if(typeof window!=="undefined"){if(value instanceof commonjsGlobal.Blob||value instanceof commonjsGlobal.ArrayBuffer){return}return"Blob or ArrayBuffer"}if(typeof value==="string"||value.pipe!==undefined){return}return"Filename or Readable stream"}function assertShape(validatorObj,apiName){return lib.assert(lib.strictShape(validatorObj),apiName)}function date(value){var msg="date";if(typeof value==="boolean"){return msg}try{var date=new Date(value);if(date.getTime&&isNaN(date.getTime())){return msg}}catch(e){return msg}}function coordinates(value){return lib.tuple(lib.number,lib.number)(value)}var validator=immutable(lib,{file:file,date:date,coordinates:coordinates,assertShape:assertShape});function createServiceFactory(ServicePrototype){return function(clientOrConfig){var client;if(gapiClient.prototype.isPrototypeOf.call(clientOrConfig)){client=clientOrConfig}else{client=browserClient(clientOrConfig)}var service=Object.create(ServicePrototype);service.client=client;return service}}var createServiceFactory_1=createServiceFactory;var Autocomplete={};Autocomplete.search=function(config){validator.assertShape({input:validator.required(validator.string),location:validator.string,radius:validator.number,limit:validator.number})(config);return this.client.createRequest({method:"GET",path:"/Place/AutoComplete",query:config})};Autocomplete.placeDetail=function(config){validator.assertShape({placeid:validator.required(validator.string)})(config);return this.client.createRequest({method:"GET",path:"/Place/Detail",query:config})};var autocomplete=createServiceFactory_1(Autocomplete);function objectMap(obj,cb){return Object.keys(obj).reduce(function(result,key){result[key]=cb(key,obj[key]);return result},{})}var objectMap_1=objectMap;function stringifyBoolean(obj){return objectMap_1(obj,function(_,value){return typeof value==="boolean"?JSON.stringify(value):value})}var stringifyBooleans=stringifyBoolean;var Directions={};Directions.getDirections=function(config){validator.assertShape({origin:validator.required(validator.string),destination:validator.required(validator.string),vehicle:validator.oneOf("car","bike","taxi"),type:validator.oneOf("fastest","shortest"),alternatives:validator.boolean})(config);var query=stringifyBooleans(config);return this.client.createRequest({method:"GET",path:"/Direction",query:query})};var directions=createServiceFactory_1(Directions);var Geocoding={};Geocoding.reverseGeocode=function(config){validator.assertShape({latlng:validator.required(validator.string)})(config);return this.client.createRequest({method:"GET",path:"/Geocode",query:config})};var geocoding=createServiceFactory_1(Geocoding);var DistanceMatrix={};DistanceMatrix.getMatrix=function(config){validator.assertShape({origins:validator.required(validator.string),destinations:validator.required(validator.string),vehicle:validator.oneOf("car","bike","taxi"),type:validator.oneOf("fastest","shortest")})(config);return this.client.createRequest({method:"GET",path:"/DistanceMatrix",query:config})};var distancematrix=createServiceFactory_1(DistanceMatrix);var Static={};Static.getStaticImage=function(config){validator.assertShape({origin:validator.required(validator.string),destination:validator.required(validator.string),width:validator.number,height:validator.number,vehicle:validator.oneOf("car","bike","taxi"),type:validator.oneOf("fastest","shortest"),color:validator.string})(config);return this.client.createRequest({method:"GET",path:"/staticmap/route",query:config,encoding:"binary"})};var _static=createServiceFactory_1(Static);function goongSdk(options){var client=browserClient(options);client.autocomplete=autocomplete(client);client.directions=directions(client);client.geocoding=geocoding(client);client.distancematrix=distancematrix(client);client.static=_static(client);return client}var bundle=goongSdk;return bundle}); +(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):global.goongSdk=factory()})(this,function(){"use strict";function parseParam(param){var parts=param.match(/\s*(.+)\s*=\s*"?([^"]+)"?/);if(!parts)return null;return{key:parts[1],value:parts[2]}}function parseLink(link){var parts=link.match(/]*)>(.*)/);if(!parts)return null;var linkUrl=parts[1];var linkParams=parts[2].split(";");var rel=null;var parsedLinkParams=linkParams.reduce(function(result,param){var parsed=parseParam(param);if(!parsed)return result;if(parsed.key==="rel"){if(!rel){rel=parsed.value}return result}result[parsed.key]=parsed.value;return result},{});if(!rel)return null;return{url:linkUrl,rel:rel,params:parsedLinkParams}}function parseLinkHeader(linkHeader){if(!linkHeader)return{};return linkHeader.split(/,\s*=400){var gAPIError=new gapiError({request:request,body:xhr.response,statusCode:xhr.status});reject(gAPIError);return}resolve(xhr)};var body=request.body;if(typeof body==="string"){xhr.send(body)}else if(body){xhr.send(JSON.stringify(body))}else if(file){xhr.send(file)}else{xhr.send()}requestsUnderway[request.id]=xhr}).then(function(xhr){return createResponse(request,xhr)})}function createRequestXhr(request,accessToken){var url=request.url(accessToken);var xhr=new window.XMLHttpRequest;xhr.open(request.method,url);Object.keys(request.headers).forEach(function(key){xhr.setRequestHeader(key,request.headers[key])});xhr.timeout=request.timeout;return xhr}function browserSend(request){return Promise.resolve().then(function(){var xhr=createRequestXhr(request,request.client.accessToken);return sendRequestXhr(request,xhr)})}var browserLayer={browserAbort:browserAbort,sendRequestXhr:sendRequestXhr,browserSend:browserSend,createRequestXhr:createRequestXhr};var immutable=extend;var hasOwnProperty=Object.prototype.hasOwnProperty;function extend(){var target={};for(var i=0;imax.length?arr:max})}};v.equal=function equal(compareWith){return function equalValidator(value){if(value!==compareWith){return JSON.stringify(compareWith)}}};v.oneOf=function oneOf(){var options=Array.isArray(arguments[0])?arguments[0]:Array.prototype.slice.call(arguments);var validators=options.map(function(value){return v.equal(value)});return v.oneOfType.apply(this,validators)};v.range=function range(compareWith){var min=compareWith[0];var max=compareWith[1];return function rangeValidator(value){var validationResult=validate(v.number,value);if(validationResult||valuemax){return"number between "+min+" & "+max+" (inclusive)"}}};v.any=function any(){return};v.boolean=function boolean(value){if(typeof value!=="boolean"){return"boolean"}};v.number=function number(value){if(typeof value!=="number"){return"number"}};v.plainArray=function plainArray(value){if(!Array.isArray(value)){return"array"}};v.plainObject=function plainObject(value){if(!isPlainObj(value)){return"object"}};v.string=function string(value){if(typeof value!=="string"){return"string"}};v.func=function func(value){if(typeof value!=="function"){return"function"}};function validate(validator,value){if(value==null&&!validator.hasOwnProperty("__required")){return}var result=validator(value);if(result){return Array.isArray(result)?result:[result]}}function processMessage(message,options){var len=message.length;var result=message[len-1];var path=message.slice(0,len-1);if(path.length===0){path=[DEFAULT_ERROR_PATH]}options=immutable(options,{path:path});return typeof result==="function"?result(options):formatErrorMessage(options,prettifyResult(result))}function orList(list){if(list.length<2){return list[0]}if(list.length===2){return list.join(" or ")}return list.slice(0,-1).join(", ")+", or "+list.slice(-1)}function prettifyResult(result){return"must be "+addArticle(result)+"."}function addArticle(nounPhrase){if(/^an? /.test(nounPhrase)){return nounPhrase}if(/^[aeiou]/i.test(nounPhrase)){return"an "+nounPhrase}if(/^[a-z]/i.test(nounPhrase)){return"a "+nounPhrase}return nounPhrase}function formatErrorMessage(options,prettyResult){var arrayCulprit=isArrayCulprit(options.path);var output=options.path.join(".")+" "+prettyResult;var prepend=arrayCulprit?"Item at position ":"";return prepend+output}function isArrayCulprit(path){return typeof path[path.length-1]=="number"||typeof path[0]=="number"}function objectEntries(obj){return Object.keys(obj||{}).map(function(key){return{key:key,value:obj[key]}})}v.validate=validate;v.processMessage=processMessage;var lib=v;function file(value){if(typeof window!=="undefined"){if(value instanceof commonjsGlobal.Blob||value instanceof commonjsGlobal.ArrayBuffer){return}return"Blob or ArrayBuffer"}if(typeof value==="string"||value.pipe!==undefined){return}return"Filename or Readable stream"}function assertShape(validatorObj,apiName){return lib.assert(lib.strictShape(validatorObj),apiName)}function date(value){var msg="date";if(typeof value==="boolean"){return msg}try{var date=new Date(value);if(date.getTime&&isNaN(date.getTime())){return msg}}catch(e){return msg}}function coordinates(value){return lib.tuple(lib.number,lib.number)(value)}var validator=immutable(lib,{file:file,date:date,coordinates:coordinates,assertShape:assertShape});function createServiceFactory(ServicePrototype){return function(clientOrConfig){var client;if(gapiClient.prototype.isPrototypeOf.call(clientOrConfig)){client=clientOrConfig}else{client=browserClient(clientOrConfig)}var service=Object.create(ServicePrototype);service.client=client;return service}}var createServiceFactory_1=createServiceFactory;var Autocomplete={};Autocomplete.search=function(config){validator.assertShape({input:validator.required(validator.string),location:validator.string,radius:validator.number,limit:validator.number})(config);return this.client.createRequest({method:"GET",path:"/place/autocomplete",query:config})};Autocomplete.placeDetail=function(config){validator.assertShape({placeid:validator.required(validator.string)})(config);return this.client.createRequest({method:"GET",path:"/place/detail",query:config})};var autocomplete=createServiceFactory_1(Autocomplete);function objectMap(obj,cb){return Object.keys(obj).reduce(function(result,key){result[key]=cb(key,obj[key]);return result},{})}var objectMap_1=objectMap;function stringifyBoolean(obj){return objectMap_1(obj,function(_,value){return typeof value==="boolean"?JSON.stringify(value):value})}var stringifyBooleans=stringifyBoolean;var Directions={};Directions.getDirections=function(config){validator.assertShape({origin:validator.required(validator.string),destination:validator.required(validator.string),vehicle:validator.oneOf("car","bike","taxi"),type:validator.oneOf("fastest","shortest"),alternatives:validator.boolean})(config);var query=stringifyBooleans(config);return this.client.createRequest({method:"GET",path:"/Direction",query:query})};var directions=createServiceFactory_1(Directions);var Geocoding={};Geocoding.reverseGeocode=function(config){validator.assertShape({latlng:validator.required(validator.string)})(config);return this.client.createRequest({method:"GET",path:"/Geocode",query:config})};var geocoding=createServiceFactory_1(Geocoding);var DistanceMatrix={};DistanceMatrix.getMatrix=function(config){validator.assertShape({origins:validator.required(validator.string),destinations:validator.required(validator.string),vehicle:validator.oneOf("car","bike","taxi"),type:validator.oneOf("fastest","shortest")})(config);return this.client.createRequest({method:"GET",path:"/DistanceMatrix",query:config})};var distancematrix=createServiceFactory_1(DistanceMatrix);var Static={};Static.getStaticImage=function(config){validator.assertShape({origin:validator.required(validator.string),destination:validator.required(validator.string),width:validator.number,height:validator.number,vehicle:validator.oneOf("car","bike","taxi"),type:validator.oneOf("fastest","shortest"),color:validator.string})(config);return this.client.createRequest({method:"GET",path:"/staticmap/route",query:config,encoding:"binary"})};var _static=createServiceFactory_1(Static);function goongSdk(options){var client=browserClient(options);client.autocomplete=autocomplete(client);client.directions=directions(client);client.geocoding=geocoding(client);client.distancematrix=distancematrix(client);client.static=_static(client);return client}var bundle=goongSdk;return bundle});