Skip to content

Commit

Permalink
Merge pull request #195 from amadeus4dev/transfer
Browse files Browse the repository at this point in the history
Add Cars & Transfers APIs
  • Loading branch information
tsolakoua authored Jun 20, 2023
2 parents b96d942 + 766ae96 commit 759bdb1
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,16 @@ amadeus.dutyOfCare.diseases.covid19Report.get({
language: 'EN'
});

//Cars & Transfers APIs
// Transfer Search API: Search Transfer
amadeus.shopping.transferOffers.post(JSON.stringify(body));

// Transfer Book API: Book a transfer based on the offer id
amadeus.ordering.transferOrders.post(JSON.stringify(body),offerId='2094123123');

// Transfer Management API: Cancel a transfer based on the order id & confirmation number
amadeus.ordering.transferOrder('XXX').transfers.cancellation.post(JSON.stringify({}), confirmNbr='12345');

```
## Development & Contributing
Expand Down
30 changes: 30 additions & 0 deletions spec/amadeus/namespaces.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ describe('Namespaces', () => {
expect(amadeus.shopping.availability).toBeDefined();
expect(amadeus.shopping.availability.flightAvailabilities).toBeDefined();

expect(amadeus.shopping.transferOffers).toBeDefined();

expect(amadeus.booking.flightOrder).toBeDefined();
expect(amadeus.booking.hotelBookings).toBeDefined();

Expand All @@ -81,6 +83,10 @@ describe('Namespaces', () => {
expect(amadeus.media).toBeDefined();
expect(amadeus.media.files).toBeDefined();

expect(amadeus.ordering).toBeDefined();
expect(amadeus.ordering.transferOrders).toBeDefined();
expect(amadeus.ordering.transferOrder('XXX').transfers.cancellation).toBeDefined();

expect(amadeus.airport).toBeDefined();
expect(amadeus.airport.directDestinations).toBeDefined();
expect(amadeus.airport.predictions).toBeDefined();
Expand Down Expand Up @@ -165,6 +171,9 @@ describe('Namespaces', () => {
expect(amadeus.shopping.flightOffers.pricing.post).toBeDefined();
expect(amadeus.shopping.seatmaps.post).toBeDefined();
expect(amadeus.booking.hotelBookings.post).toBeDefined();
expect(amadeus.shopping.transferOffers.post).toBeDefined();
expect(amadeus.ordering.transferOrders.post).toBeDefined();
expect(amadeus.ordering.transferOrder('XXX').transfers.cancellation.post).toBeDefined();
});

it('should define all expected .delete methods', () => {
Expand Down Expand Up @@ -537,5 +546,26 @@ describe('Namespaces', () => {
.toHaveBeenCalledWith('/v1/airline/destinations', {});
});

it('.amadeus.shopping.transferOffers.post', () => {
amadeus.client.post = jest.fn();
amadeus.shopping.transferOffers.post();
expect(amadeus.client.post)
.toHaveBeenCalledWith('/v1/shopping/transfer-offers', {});
});

it('.amadeus.ordering.transferOrders.post', () => {
amadeus.client.post = jest.fn();
amadeus.ordering.transferOrders.post({}, '1234123123');
expect(amadeus.client.post)
.toHaveBeenCalledWith('/v1/ordering/transfer-orders?offerId=1234123123', {});
});

it('.amadeus.ordering.transferOrders().transfers.cancellation.post', () => {
amadeus.client.post = jest.fn();
amadeus.ordering.transferOrder('XXX').transfers.cancellation.post({}, 12345);
expect(amadeus.client.post)
.toHaveBeenCalledWith('/v1/ordering/transfer-orders/XXX/transfers/cancellation?confirmNbr=12345', {});
});

});
});
2 changes: 2 additions & 0 deletions src/amadeus.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Booking from './amadeus/namespaces/booking';
import Travel from './amadeus/namespaces/travel';
import EReputation from './amadeus/namespaces/e_reputation';
import Media from './amadeus/namespaces/media';
import Ordering from './amadeus/namespaces/ordering';
import Airport from './amadeus/namespaces/airport';
import Safety from './amadeus/namespaces/safety';
import Schedule from './amadeus/namespaces/schedule';
Expand Down Expand Up @@ -72,6 +73,7 @@ class Amadeus {
this.travel = new Travel(this.client);
this.eReputation = new EReputation(this.client);
this.media = new Media(this.client);
this.ordering = new Ordering(this.client);
this.airport = new Airport(this.client);
this.pagination = new Pagination(this.client);
this.safety = new Safety(this.client);
Expand Down
27 changes: 27 additions & 0 deletions src/amadeus/namespaces/ordering.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import TransferOrders from './ordering/transfer_orders';
import TransferOrder from './ordering/transfer_order';

/**
* A namespaced client for the
* `/v1/ordering` endpoints
*
* Access via the {@link Amadeus} object
*
* ```js
* let amadeus = new Amadeus();
* amadeus.ordering;
* ```
*
* @param {Client} client
* @property {TransferOrders} transferOrders
* @property {TransferOrder} transferOrder
*/
class Ordering {
constructor(client) {
this.client = client;
this.transferOrders = new TransferOrders(client);
this.transferOrder = (orderId) => new TransferOrder(client, orderId);
}
}

export default Ordering;
25 changes: 25 additions & 0 deletions src/amadeus/namespaces/ordering/transfer_order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Transfers from './transfer_orders/transfers';

/**
* A namespaced client for the
* `/v1/ordering/transfer-orders/XXXXX` endpoints
*
* Access via the {@link Amadeus} object
*
* ```js
* let amadeus = new Amadeus();
* amadeus.ordering.transferOrder('XXX');
* ```
*
* @param {Client} client
* @param {string} orderId
*/
class TransferOrder {
constructor(client, orderId) {
this.client = client;
this.orderId = orderId;
this.transfers = new Transfers(client, orderId);
}
}

export default TransferOrder;
36 changes: 36 additions & 0 deletions src/amadeus/namespaces/ordering/transfer_orders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* A namespaced client for the
* `/v1/ordering/transfer-orders` endpoints
*
* Access via the {@link Amadeus} object
*
* ```js
* let amadeus = new Amadeus();
* amadeus.ordering.transferOrders;
* ```
*
* @param {Client} client
*/
class TransferOrders {
constructor(client) {
this.client = client;

}

/**
* To book the selected transfer-offer and create a transfer-order
*
* @return {Promise.<Response,ResponseError>} a Promise
*
* To book the transfer-offer(s) suggested by transferOffers and create a transfer-order
*
* ```js
* amadeus.ordering.transferOrders.post(body, '2094123123');;
* ```
*/
post(body, offerId) {
return this.client.post(`/v1/ordering/transfer-orders?offerId=${offerId}`, body);
}
}

export default TransferOrders;
24 changes: 24 additions & 0 deletions src/amadeus/namespaces/ordering/transfer_orders/transfers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Cancellation from './transfers/cancellation';

/**
* A namespaced client for the
* `/v1/ordering/transfer-orders/XXXXX/transfers` endpoints
*
* Access via the {@link Amadeus} object
*
* ```js
* let amadeus = new Amadeus();
* amadeus.ordering.transferOrders('XXX').transfers;
* ```
*
* @param {Client} client
*/
class Transfers {
constructor(client, orderId) {
this.client = client;
this.orderId = orderId;
this.cancellation = new Cancellation(client, orderId);
}
}

export default Transfers;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* A namespaced client for the
* `/v1/ordering/transfer-orders/XXX/transfers/cancellation` endpoints
*
* Access via the {@link Amadeus} object
*
* ```js
* let amadeus = new Amadeus();
* amadeus.ordering.transferOrder('XXX').transfers.cancellation.post(JSON.stringify({}), 12345);;
* ```
*
* @param {Client} client
*/
class Cancellation {
constructor(client, orderId) {
this.client = client;
this.orderId = orderId;
}

/**
* To cancel a transfer order based on its id
* @return {Promise.<Response,ResponseError>} a Promise
*
* To cancel a transfer order with ID 'XXX' and confirmation number '12345'
*
* ```js
* amadeus.ordering.transferOrder('XXX').transfers.cancellation.post(JSON.stringify({}), 12345);;
* ```
*/
post(body, confirmNbr) {
return this.client.post(
`/v1/ordering/transfer-orders/${this.orderId}/transfers/cancellation?confirmNbr=${confirmNbr}`, body);
}
}

export default Cancellation;
4 changes: 3 additions & 1 deletion src/amadeus/namespaces/shopping.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import HotelOffersSearch from './shopping/hotel_offers_search';
import Activities from './shopping/activities';
import Activity from './shopping/activity';
import Availability from './shopping/availability';

import TransferOffers from './shopping/transfer_offers';

/**
* A namespaced client for the
Expand All @@ -30,6 +30,7 @@ import Availability from './shopping/availability';
* @property {HotelOfferSearch} hotelOffers
* @property {HotelOffersSearch} hotelOffers
* @property {Availability} availability
* @property {TransferOffers} transferOffers
*/
class Shopping {
constructor(client) {
Expand All @@ -42,6 +43,7 @@ class Shopping {
this.hotelOffersSearch = new HotelOffersSearch(client);
this.activities = new Activities(client);
this.availability = new Availability(client);
this.transferOffers = new TransferOffers(client);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/amadeus/namespaces/shopping/hotel_offer_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @param {Client} client
* @property {number} offerId
*/
class hotelOfferSearch {
class HotelOfferSearch {
constructor(client, offerId) {
this.client = client;
this.offerId = offerId;
Expand All @@ -37,4 +37,4 @@ class hotelOfferSearch {
}
}

export default hotelOfferSearch;
export default HotelOfferSearch;
4 changes: 2 additions & 2 deletions src/amadeus/namespaces/shopping/hotel_offers_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @param {Client} client
*/
class hotelOffersSearch {
class HotelOffersSearch {
constructor(client) {
this.client = client;
}
Expand Down Expand Up @@ -39,4 +39,4 @@ class hotelOffersSearch {
}
}

export default hotelOffersSearch;
export default HotelOffersSearch;
38 changes: 38 additions & 0 deletions src/amadeus/namespaces/shopping/transfer_offers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

/**
* A namespaced client for the
* `/v1/shopping/transfer-offers` endpoints
*
* Access via the {@link Amadeus} object
*
* ```js
* let amadeus = new Amadeus();
* amadeus.shopping.transferOffers;
* ```
*
* @param {Client} client
*/
class TransferOffers {
constructor(client) {
this.client = client;
}

/**
* To search the list of transfer offers.
*
* @param {Object} params
* @return {Promise.<Response,ResponseError>} a Promise
*
* To search the list of transfer offers
*
* ```js
* amadeus.shopping.transferOffers.post(body)
* ```
*/
post(params = {}) {
return this.client.post('/v1/shopping/transfer-offers', params);
}
}

export default TransferOffers;

0 comments on commit 759bdb1

Please sign in to comment.