From 1b6c86f4d0fa5144163b9efed06169edb2393f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radovan=20Fekec=CC=8C?= Date: Mon, 18 Sep 2017 12:20:47 +0200 Subject: [PATCH 1/2] Bump version numbers in package.json, readme, packages tweaks --- README.md | 75 +++++++++++++++++++++--------------------- package.json | 4 +-- src/Route/Estimator.ts | 2 +- yarn.lock | 8 ++--- 4 files changed, 44 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index a7fc14d..b1bc226 100644 --- a/README.md +++ b/README.md @@ -12,46 +12,47 @@ The Sygic Travel SDK for JavaScript provides a set of client-side functionality - Enables you to get media (photos and videos) for a place - Spreads places on a map according to your configuration -You can also check out our [Reference documentation](http://docs.sygictravelapi.com/js-sdk/v1.0.0/). +You can also check out our [Reference documentation](http://docs.sygictravelapi.com/js-sdk/v1.1.0/). ## Installation You can get the UMD build from the CDN, which you can include to your document, ```html - + ``` or install it using Yarn or NPM (Typescript types included). ``` -yarn add sygic-travel/js-sdk.git#v1.0.0 +yarn add sygic-travel/js-sdk.git#v1.1.0 ``` ## Initialization -#### [`create`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/modules/_sdk_.html#create) -Creates an instance of [Sygic Travel SDK](http://docs.sygictravelapi.com/js-sdk/v1.0.0/classes/_stsdk_.stsdk.html) +#### [`create`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/modules/_sdk_.html#create) +Creates an instance of [Sygic Travel SDK](http://docs.sygictravelapi.com/js-sdk/v1.1.0/classes/_stsdk_.stsdk.html) ##### Arguments: - `apiUrl: string` - `clientKey: string` ##### Returns: -- [`StSDK`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/classes/_stsdk_.stsdk.html) +- [`StSDK`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/classes/_stsdk_.stsdk.html) ``` // const SygicTravelSDK = require('sygic-travel-js-sdk/index.node') for node -import * as SygicTravelSDK from ‘sygic-travel-js-sdk’; -const apiUrl: string = ‘https://api.sygictravelapi.com/1.0/en/'; -const clientKey: ‘CLIENT_KEY’; // Get your client key at https://travel.sygic.com/b2b/api-key +import * as SygicTravelSDK from 'sygic-travel-js-sdk'; +const apiUrl: string = 'https://api.sygictravelapi.com/1.0/en/'; +const clientKey: string = 'CLIENT_KEY'; // Get your client key at https://travel.sygic.com/b2b/api-key const stSDK: SygicTravelSDK.StSDK = SygicTravelSDK.create(apiUrl, clientKey); ``` ## Instance methods -### [`getPlaces`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/classes/_stsdk_.stsdk.html#getplaces) + +### [`getPlaces`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/classes/_modules_placesmodule_.placesmodule.html#getplaces) Fetches a list of places according to the applied filter. ##### Arguments: -- [`filter: Places.PlacesFilterJSON`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/interfaces/_places_filter_.placesfilterjson.html) - +- [`filter: Places.PlacesListFilterJSON`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/interfaces/_places_listfilter_.placeslistfilterjson.html) +PlacesListFilterJSON ###### PlacesFilter: -```ts +```ts // Filter full example -const placeFilter: SygicTravelSDK.Places.PlacesFilterJSON = { - query: 'Tower', +const placeFilter: SygicTravelSDK.Places.PlacesListFilterJSON = { + query: 'Tower', mapTiles: ['0121011'], // Matches places within map tile coordinate. For details see [Bing Maps docs](https://msdn.microsoft.com/en-us/library/bb259689.aspx) or Maptiler.org mapSpread: 1, bounds: { @@ -62,7 +63,7 @@ const placeFilter: SygicTravelSDK.Places.PlacesFilterJSON = { }, categories: ['eating', 'sightseeing'], // filter out only certain categories categoriesOperator: 'OR', - tags: ['indian_cousine', 'mexican_counsine'], + tags: ['indian_cousine', 'mexican_counsine'], tagsOperator: 'OR', parents: ['city:1', 'city:5'], // filter out only places that has certain parents parentsOperator: 'OR', @@ -89,11 +90,11 @@ const placeFilter: SygicTravelSDK.Places.PlacesFilterJSON = { | zoom | Zoom level of map. This is required for mapSpread. | ##### Returns: -- [`Promise`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/interfaces/_places_place_.place.html) +- [`Promise`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/interfaces/_places_place_.place.html) ##### Usage example: ```ts -const placeFilter: SygicTravelSDK.Places.PlacesFilterJSON = { +const placeFilter: SygicTravelSDK.Places.PlacesListFilterJSON = { query: null, // text query, for example from a search input field mapTiles: null, mapSpread: null, @@ -110,44 +111,44 @@ const placeFilter: SygicTravelSDK.Places.PlacesFilterJSON = { limit: 20 }; -stSDK.getPlaces(placeFilter).then((places: SygicTravelSDK.Places.Place[]) => { - console.log(places); -}); +const places: SygicTravelSDK.Places.Place[] = await stSDK.places.getPlaces(placeFilter); +console.log(places) ``` --- -### [`getPlaceDetailed`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/classes/_stsdk_.stsdk.html#getplacedetailed) -Returns a single place with populated [`detail`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/interfaces/_places_place_.place.html#detail) property. +### [`getPlaceDetailed`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/classes/_modules_placesmodule_.placesmodule.html#getplacedetailed) +Returns a single place with populated [`detail`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/interfaces/_places_place_.place.html#detail) property. ##### Arguments: - `id: string` - `photoSize: string` ##### Returns: -- [`Promise`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/interfaces/_places_place_.place.html) +- [`Promise`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/interfaces/_places_place_.place.html) --- -### [`getPlaceMedia`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/classes/_stsdk_.stsdk.html#getplacemedia) +### [`getPlaceMedia`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/classes/_modules_placesmodule_.placesmodule.html#getplacemedia) Fetches media for place. #### Arguments: - `id: string` #### Returns: -- [`Promise`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/interfaces/_media_media_.medium.html) +- [`Promise`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/interfaces/_media_media_.medium.html) --- -### [`spreadPlacesOnMap`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/classes/_stsdk_.stsdk.html#spreadplacesonmap) + +### [`spreadPlacesOnMap`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/classes/_modules_placesmodule_.placesmodule.html#spreadplacesonmap) Will calculate positions of places (map markers) according to spread configuration. #### Arguments: -- [`places: Places.Place[]`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/interfaces/_places_place_.place.html) -- [`bounds: Geo.Bounds`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/interfaces/_geo_bounds_.bounds.html) -- [`canvas: Spread.CanvasSize`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/interfaces/_spread_canvas_.canvassize.html) -- [`markerSizes (optional): Spread.SpreadSizeConfig[]`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/interfaces/_spread_config_.spreadsizeconfig.html) +- [`places: Places.Place[]`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/interfaces/_places_place_.place.html) +- [`bounds: Geo.Bounds`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/interfaces/_geo_bounds_.bounds.html) +- [`canvas: Spread.CanvasSize`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/interfaces/_spread_canvas_.canvassize.html) +- [`markerSizes (optional): Spread.SpreadSizeConfig[]`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/interfaces/_spread_config_.spreadsizeconfig.html) #### Returns: -- [`Spread.SpreadResult`](http://docs.sygictravelapi.com/js-sdk/v1.0.0/interfaces/_spread_spreader_.spreadresult.html) +- [`Spread.SpreadResult`](http://docs.sygictravelapi.com/js-sdk/v1.1.0/interfaces/_spread_spreader_.spreadresult.html) #### Usage example: ```ts -const placeFilter: SygicTravelSDK.Places.PlacesFilterJSON = { +const placeFilter: SygicTravelSDK.Places.PlacesListFilterJSON = { query: null, mapTiles: null, mapSpread: null, @@ -170,9 +171,7 @@ const canvasSize: SygicTravelSDK.Spread.CanvasSize = { height: 768 } -stSDK.getPlaces(placeFilter).then((places: SygicTravelSDK.Places.Place[]) => { - return stSDK.spreadPlacesOnMap(places, bounds, canvasSize); -}).then((spreadPlaces: SygicTravelSDK.Spread.SpreadResult) => { - console.log(spreadPlaces); -}); +const places: SygicTravelSDK.Places.Place[] = await stSDK.places.getPlaces(placeFilter); +const spreadPlaces: SygicTravelSDK.Spread.SpreadResult = await stSDK.places.spreadPlacesOnMap(places, bounds, canvasSize); +console.log(spreadPlaces); ``` diff --git a/package.json b/package.json index cb068ee..9fffa01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sygic-travel-js-sdk", - "version": "0.2.1", + "version": "1.1.0", "main": "index.js", "repository": {}, "license": "MIT", @@ -40,11 +40,11 @@ "webpack-dev-server": "^2.7.1" }, "dependencies": { + "@mapbox/polyline": "^0.2.0", "@types/geojson": "^1.0.2", "axios": "*", "humps": "^2.0.0", "lodash.clonedeep": "^4.5.0", - "polyline": "^0.2.0", "query-string": "^4.3.1" } } diff --git a/src/Route/Estimator.ts b/src/Route/Estimator.ts index c71d605..481a83e 100644 --- a/src/Route/Estimator.ts +++ b/src/Route/Estimator.ts @@ -1,4 +1,4 @@ -import { encode } from 'polyline'; +import { encode } from '@mapbox/polyline'; import { Direction } from '.'; import { EARTH_RADIUS, getDistance, Location } from '../Geo'; diff --git a/yarn.lock b/yarn.lock index 1589688..6a2e139 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,10 @@ # yarn lockfile v1 +"@mapbox/polyline@^0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/@mapbox/polyline/-/polyline-0.2.0.tgz#6e25980744aa22331f94b645a542c02d3fcfee97" + "@types/chai-as-promised@^0.0.30": version "0.0.30" resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-0.0.30.tgz#2341321cc796c6c3544a949a063e7609a222f303" @@ -2561,10 +2565,6 @@ pinkie@^2.0.0: version "2.0.4" resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870" -polyline@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/polyline/-/polyline-0.2.0.tgz#4f2b716ca81134a6cbaa488975d236ecb1cc2840" - portfinder@^1.0.9: version "1.0.13" resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.13.tgz#bb32ecd87c27104ae6ee44b5a3ccbf0ebb1aede9" From 429f014678935654717fc21246927884848132be Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Tue, 19 Sep 2017 13:08:24 +0200 Subject: [PATCH 2/2] hotels: Places in filter renamed to placeIds --- index.d.ts | 2 +- src/Hotels/DataAccess.test.ts | 4 ++-- src/Hotels/Filter.test.ts | 4 ++-- src/Hotels/Filter.ts | 14 +++++++------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/index.d.ts b/index.d.ts index 7083ebd..3bc87dc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -327,7 +327,7 @@ export namespace Hotels { maxPrice?: number | null; minPrice?: number | null; minReviewScore?: number | null; - places?: string[] | null; + placeIds?: string[] | null; bounds?: Geo.Bounds | null; mapTileBounds?: string[] | null; stars?: number[] | null; diff --git a/src/Hotels/DataAccess.test.ts b/src/Hotels/DataAccess.test.ts index 08b467f..e2d4d8f 100644 --- a/src/Hotels/DataAccess.test.ts +++ b/src/Hotels/DataAccess.test.ts @@ -31,14 +31,14 @@ describe('HotelsDataAccess', () => { adults: 2, checkIn: '2017-11-11', checkOut: '2017-11-12', - places: ['poi:1', 'poi:2'] + placeIds: ['poi:1', 'poi:2'] }); chai.expect(await Dao.getHotels(hotelsFilter)) .to.deep.equal(HotelsResults.availableHotels); chai.expect(apiStub.callCount).to.equal(1); chai.expect(apiStub.getCall(0).args[0]) - .to.equal('hotels/list/?adults=2&check_in=2017-11-11&check_out=2017-11-12&places=poi%3A1%7Cpoi%3A2'); + .to.equal('hotels/list/?adults=2&check_in=2017-11-11&check_out=2017-11-12&place_ids=poi%3A1%7Cpoi%3A2'); }); it('should use map tiles if bounds and zoom are passed', async () => { diff --git a/src/Hotels/Filter.test.ts b/src/Hotels/Filter.test.ts index 618b783..6a93f5c 100644 --- a/src/Hotels/Filter.test.ts +++ b/src/Hotels/Filter.test.ts @@ -105,7 +105,7 @@ describe('HotelsFilter', () => { north: 3, east: 4, }, - places: ['poi:1', 'poi:2'] + placeIds: ['poi:1', 'poi:2'] }); }; chai.expect(createFilter).to.throw( @@ -140,7 +140,7 @@ describe('HotelsFilter', () => { adults: 1, checkIn: '2017-11-11', checkOut: 'fdfdfd', - places: ['poi:1'], + placeIds: ['poi:1'], }); }; chai.expect(createFilter).to.throw('Invalid checkOut date.'); diff --git a/src/Hotels/Filter.ts b/src/Hotels/Filter.ts index 701bfbc..f71cb1c 100644 --- a/src/Hotels/Filter.ts +++ b/src/Hotels/Filter.ts @@ -10,7 +10,7 @@ export interface HotelsFilterJSON { maxPrice?: number | null; minPrice?: number | null; minReviewScore?: number | null; - places?: string[] | null; + placeIds?: string[] | null; bounds?: Bounds | null; mapTileBounds?: string[] | null; stars?: number[] | null; @@ -30,7 +30,7 @@ export interface HotelsFilterQuery { max_price?: number; min_price?: number; min_review_score?: number; - places?: string; + place_ids?: string; bounds?: string; map_tile_bounds?: string; stars?: string; @@ -50,7 +50,7 @@ export class HotelsFilter { protected _maxPrice?: number | null; protected _minPrice?: number | null; protected _minReviewScore?: number | null; - protected _places?: string[] | null; + protected _placeIds?: string[] | null; protected _bounds?: Bounds | null; protected _mapTileBounds?: string[] | null; protected _stars?: number[] | null; @@ -70,7 +70,7 @@ export class HotelsFilter { this._minPrice = filter.minPrice; this._minReviewScore = filter.minReviewScore; this._bounds = filter.bounds; - this._places = filter.places; + this._placeIds = filter.placeIds; this._mapTileBounds = filter.mapTileBounds; this._stars = filter.stars; this._currency = filter.currency; @@ -108,8 +108,8 @@ export class HotelsFilter { if (this._minReviewScore) { query.min_review_score = this._minReviewScore; } - if (this._places) { - query.places = this._places.join('|'); + if (this._placeIds) { + query.place_ids = this._placeIds.join('|'); } if (this._bounds) { query.bounds = this._bounds.south + ',' + this._bounds.west + ',' + this._bounds.north + ',' + this._bounds.east; @@ -156,7 +156,7 @@ export class HotelsFilter { if (!this._adults) { throw new Error('Adults count is mandatory.'); } - if ([this._bounds, this._mapTileBounds, this._places].filter((it) => it).length !== 1) { + if ([this._bounds, this._mapTileBounds, this._placeIds].filter((it) => it).length !== 1) { throw new Error('Bounds, mapTileBounds and places have to be used exclusively and one of them has to be present.'); } const chInDate = new Date(this._checkIn);