From d9f5380ffaee4ce0cce32c475e7f46f3aaac167f Mon Sep 17 00:00:00 2001 From: Alvaro Navarro Date: Thu, 1 Oct 2020 12:04:28 +0200 Subject: [PATCH] Add support for Tours and Activities API --- README.md | 69 ++++++++++++------- spec/amadeus/namespaces.test.js | 29 ++++++++ src/amadeus/namespaces/shopping.js | 14 ++++ src/amadeus/namespaces/shopping/activities.js | 47 +++++++++++++ .../shopping/activities/by_square.js | 45 ++++++++++++ src/amadeus/namespaces/shopping/activity.js | 33 +++++++++ 6 files changed, 213 insertions(+), 24 deletions(-) create mode 100644 src/amadeus/namespaces/shopping/activities.js create mode 100644 src/amadeus/namespaces/shopping/activities/by_square.js create mode 100644 src/amadeus/namespaces/shopping/activity.js diff --git a/README.md b/README.md index f4f1be3..88b6381 100644 --- a/README.md +++ b/README.md @@ -363,6 +363,15 @@ amadeus.booking.hotelBookings.post( ) ) +// On-Demand Flight Status +// What's the current status of my flight? +amadeus.schedule.flights.get({ + carrierCode: 'AZ', + flightNumber: '319', + scheduledDepartureDate: '2021-03-13' +}) + + // Points of Interest // What are the popular places in Barcelona (based a geo location and a radius) amadeus.referenceData.locations.pointsOfInterest.get({ @@ -378,10 +387,45 @@ amadeus.referenceData.locations.pointsOfInterest.bySquare.get({ east: 2.177181 }) -// Points of Interest // Extract the information about point of interest with ID '9CB40CB5D0' amadeus.referenceData.locations.pointOfInterest('9CB40CB5D0').get() +// Safe Place +// How safe is Barcelona? (based a geo location and a radius) +amadeus.safety.safetyRatedLocations.get({ + latitude: 41.397158, + longitude: 2.160873 +}) + +// How safe is Barcelona? (based on a square) +amadeus.safety.safetyRatedLocations.bySquare.get({ + north: 41.397158, + west: 2.160873, + south: 41.394582, + east: 2.177181 +}) + +// What is the safety information of a location based on its Id? +amadeus.safety.safetyRatedLocation('Q930400801').get() + +// Tours and Activities +// What are the best tours and activities in Barcelona? +amadeus.shopping.activities.get({ + latitude: 41.397158, + longitude: 2.160873 +}) + +// What are the best tours and activities in Barcelona? (based on a Square) +amadeus.shopping.activities.bySquare.get({ + north: 41.397158, + west: 2.160873, + south: 41.394582, + east: 2.177181 +}) + +// Extract the information about an activity with ID '56777' +amadeus.shopping.activity('56777').get() + // Hotel Ratings // Get Sentiment Analysis of reviews about Holiday Inn Paris Notre Dame. amadeus.eReputation.hotelSentiments.get({ @@ -432,29 +476,6 @@ amadeus.referenceData.recommendedLocations.get({ travelerCountryCode: 'FR' }) -// Safe Place -// How safe is Barcelona? (based a geo location and a radius) -amadeus.safety.safetyRatedLocations.get({ - latitude: 41.397158, - longitude: 2.160873 -}) -// How safe is Barcelona? (based on a square) -amadeus.safety.safetyRatedLocations.bySquare.get({ - north: 41.397158, - west: 2.160873, - south: 41.394582, - east: 2.177181 -}) -// What is the safety information of a location based on it's Id? -amadeus.safety.safetyRatedLocation('Q930400801').get() - -// On-Demand Flight Status -// What's the current status of my flight? -amadeus.schedule.flights.get({ - carrierCode: 'AZ', - flightNumber: '319', - scheduledDepartureDate: '2021-03-13' -}) ``` ## Development & Contributing diff --git a/spec/amadeus/namespaces.test.js b/spec/amadeus/namespaces.test.js index 5615029..7421273 100644 --- a/spec/amadeus/namespaces.test.js +++ b/spec/amadeus/namespaces.test.js @@ -52,6 +52,10 @@ describe('Namespaces', () => { expect(amadeus.shopping.flightOffers.pricing).toBeDefined(); expect(amadeus.shopping.seatmaps).toBeDefined(); + expect(amadeus.shopping.activities).toBeDefined(); + expect(amadeus.shopping.activities.bySquare).toBeDefined(); + expect(amadeus.shopping.activity).toBeDefined(); + expect(amadeus.booking).toBeDefined(); expect(amadeus.booking.flightOrders).toBeDefined(); @@ -107,6 +111,10 @@ describe('Namespaces', () => { expect(amadeus.shopping.hotelOffersByHotel.get).toBeDefined(); expect(amadeus.shopping.hotelOffer('XXX').get).toBeDefined(); + expect(amadeus.shopping.activities.get).toBeDefined(); + expect(amadeus.shopping.activities.bySquare.get).toBeDefined(); + expect(amadeus.shopping.activity('XXX').get).toBeDefined(); + expect(amadeus.booking.flightOrder('XXX').get).toBeDefined(); expect(amadeus.schedule.flights.get).toBeDefined(); @@ -331,6 +339,27 @@ describe('Namespaces', () => { .toHaveBeenCalledWith('/v2/shopping/hotel-offers/XXX', {}); }); + it('.amadeus.shopping.activities.get', () => { + amadeus.client.get = jest.fn(); + amadeus.shopping.activities.get(); + expect(amadeus.client.get) + .toHaveBeenCalledWith('/v1/shopping/activities', {}); + }); + + it('.amadeus.shopping.activities.bySquare.get', () => { + amadeus.client.get = jest.fn(); + amadeus.shopping.activities.bySquare.get(); + expect(amadeus.client.get) + .toHaveBeenCalledWith('/v1/shopping/activities/by-square', {}); + }); + + it('.amadeus.shopping.activity().get', () => { + amadeus.client.get = jest.fn(); + amadeus.shopping.activity('XXX').get(); + expect(amadeus.client.get) + .toHaveBeenCalledWith('/v1/shopping/activities/XXX'); + }); + it('.amadeus.booking.flightOrder().get', () => { amadeus.client.get = jest.fn(); amadeus.booking.flightOrder('XXX').get(); diff --git a/src/amadeus/namespaces/shopping.js b/src/amadeus/namespaces/shopping.js index 87c065e..584580d 100644 --- a/src/amadeus/namespaces/shopping.js +++ b/src/amadeus/namespaces/shopping.js @@ -6,6 +6,8 @@ import Seatmaps from './shopping/seatmaps'; import HotelOffers from './shopping/hotel_offers'; import HotelOffersByHotel from './shopping/hotel_offers_by_hotel'; import HotelOffer from './shopping/hotel_offer'; +import Activities from './shopping/activities'; +import Activity from './shopping/activity'; /** @@ -39,6 +41,7 @@ class Shopping { this.seatmaps = new Seatmaps(client); this.hotelOffers = new HotelOffers(client); this.hotelOffersByHotel = new HotelOffersByHotel(client); + this.activities = new Activities(client); } @@ -51,6 +54,17 @@ class Shopping { hotelOffer(offerId) { return new HotelOffer(this.client, offerId); } + + /** + * Loads a namespaced path for a specific activity ID + * + * @param {string} [activityId] The ID of the activity for a dedicated tour or activity + * @return {Activity} + **/ + activity(activityId) { + return new Activity(this.client, activityId); + } + } export default Shopping; diff --git a/src/amadeus/namespaces/shopping/activities.js b/src/amadeus/namespaces/shopping/activities.js new file mode 100644 index 0000000..563eeac --- /dev/null +++ b/src/amadeus/namespaces/shopping/activities.js @@ -0,0 +1,47 @@ +import BySquare from './activities/by_square'; + +/** + * A namespaced client for the + * `/v1/shopping/activities` endpoints + * + * Access via the {@link Amadeus} object + * + * ```js + * let amadeus = new Amadeus(); + * amadeus.shopping.activities + * ``` + * + * @param {Client} client + */ +class Activities { + constructor(client) { + this.client = client; + this.bySquare = new BySquare(client); + } + + /** + * /shopping/activities + * + * @param {Object} params + * @param {Double} params.latitude latitude location to be at the center of + * the search circle - required + * @param {Double} params.longitude longitude location to be at the center of + * the search circle - required + * @param {Double} params.radius radius of the search in Kilometer - optional + * @return {Promise.} a Promise + * + * What are the best tours and activities in Barcelona? (based a geo location and a radius) + * + * ```js + * amadeus.shopping.activities.get({ + * longitude: 2.160873, + * latitude: 41.397158 + * }); + * ``` + */ + get(params = {}) { + return this.client.get('/v1/shopping/activities', params); + } +} + +export default Activities; diff --git a/src/amadeus/namespaces/shopping/activities/by_square.js b/src/amadeus/namespaces/shopping/activities/by_square.js new file mode 100644 index 0000000..91b004f --- /dev/null +++ b/src/amadeus/namespaces/shopping/activities/by_square.js @@ -0,0 +1,45 @@ +/** + * A namespaced client for the + * `/v1/shopping/activities/by-square` endpoints + * + * Access via the {@link Amadeus} object + * + * ```js + * let amadeus = new Amadeus(); + * amadeus.shopping.activities.bySquare; + * ``` + * + * @param {Client} client + */ +class bySquare { + constructor(client) { + this.client = client; + } + + /** + * Returns a list of tours and activities a given area. + * + * @param {Object} params + * @param {Double} params.north latitude north of bounding box - required + * @param {Double} params.west longitude west of bounding box - required + * @param {Double} params.south latitude south of bounding box - required + * @param {Double} params.east longitude east of bounding box - required + * @return {Promise.} a Promise + * + * Find relevant tours and activities within an area in Barcelona + * + * ```js + * amadeus.shopping.activities.bySquare.get({ + * north: 41.397158, + * west: 2.160873, + * south: 41.394582, + * east: 2.177181 + * }); + * ``` + */ + get(params = {}) { + return this.client.get('/v1/shopping/activities/by-square', params); + } +} + +export default bySquare; diff --git a/src/amadeus/namespaces/shopping/activity.js b/src/amadeus/namespaces/shopping/activity.js new file mode 100644 index 0000000..22f9792 --- /dev/null +++ b/src/amadeus/namespaces/shopping/activity.js @@ -0,0 +1,33 @@ +/** + * A namespaced client for the + * `/v1/shopping/activities/{activityId}` endpoints + * + * Access via the {@link Amadeus} object + * + * ```js + * let amadeus = new Amadeus(); + * amadeus.shopping.activity + * ``` + * + * @param {Client} client + */ +class Activity { + constructor(client, activityId) { + this.client = client; + this.activityId = activityId; + } + + /** + * Retieve information of an activity by its Id. + * + * What is the activity information with Id 3216547684? + * ```js + * amadeus.shopping.activity('3216547684').get(); + * ``` + */ + get() { + return this.client.get(`/v1/shopping/activities/${this.activityId}`); + } +} + +export default Activity;