Skip to content

Commit

Permalink
update getHotels to support language param
Browse files Browse the repository at this point in the history
  • Loading branch information
Achraf-El-khaier committed Jan 31, 2025
1 parent 692fd7a commit fb28f2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,10 @@ class LiteApi {
* The minimum required information is the country code in ISO-2 format. The API supports additional search criteria such as city name, geo coordinates, and radius.
* This endpoint provides detailed hotel metadata, including names, addresses, ratings, amenities, and images, facilitating robust hotel search and display features within applications.
* @param {string} parameters - The search criteria parameters.
* @param {string} language - Language code for the response (optional)
* @returns {array} - The result of the operation.
*/
async getHotels(parameters) {
async getHotels(parameters, language) {
const options = {
method: 'GET',
headers: {
Expand All @@ -418,7 +419,8 @@ class LiteApi {
};

const query = decodeURIComponent(new URLSearchParams(parameters || {}).toString());
const response = await fetch(this.serviceURL + '/data/hotels?' + query, options)
const languageQuery = language ? '&language=' + encodeURIComponent(language) : '';
const response = await fetch(this.serviceURL + '/data/hotels?' + query + languageQuery, options)
const data = await response.json();

if (!response.ok) {
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ describe('LiteAPI SDK Test Suite', function() {
});

it('should retrieve hotels by country and city', async function() {
const result = await liteApi.getHotels({ countryCode: 'IT', cityName: 'Rome' });
const result = await liteApi.getHotels({ countryCode: 'IT', cityName: 'Rome', language: 'fr' });
expect(result).to.have.property('status', 'success');
expect(result).to.have.property('data');
expect(result.data).to.be.an('array');
});

it('should retrieve hotel details by ID', async function() {
const result = await liteApi.getHotelDetails('lp1897');
const result = await liteApi.getHotelDetails('lp1897', 'fr');
expect(result).to.have.property('status', 'success');
expect(result).to.have.property('data');
expect(result.data).to.be.an('object');
Expand Down

0 comments on commit fb28f2a

Please sign in to comment.