liteapi-node-sdk
Advanced tools
Comparing version 4.2.0 to 4.3.0
49
index.js
@@ -467,3 +467,16 @@ class LiteApi { | ||
} | ||
/** | ||
* Retrieves a list of reviews for a specific hotel identified by hotelId. | ||
* @deprecated This method is deprecated and will be removed in future versions. Use `getDataReviews` instead. | ||
* @param {string} hotelId - Unique ID of a hotel | ||
* @param {number} limit - Limit number of reviews (max 1000) | ||
* @param {boolean} getSentiment - If set to true, the sentiment analysis of the review text will be returned | ||
* @returns {object} - The reviews and sentiment analysis of the hotel | ||
*/ | ||
async getHotelReviews(hotelId, limit, getSentiment) { | ||
return await this.getDataReviews(hotelId, limit, getSentiment); | ||
} | ||
/** | ||
* Retrieves a list of reviews for a specific hotel identified by hotelId | ||
@@ -473,7 +486,7 @@ * @param {string} hotelId - Unique ID of a hotel | ||
* @param {boolean} getSentiment - If set to true, the sentiment analysis of the review text will be returned | ||
* @returns {array} - The reviews of the hotel | ||
* @returns {object} - The reviews and sentiment analysis of the hotel | ||
*/ | ||
async getHotelReviews(hotelId, limit, getSentiment) { | ||
async getDataReviews(hotelId, limit, getSentiment) { | ||
let errors = []; | ||
if (hotelId == "" || hotelId === undefined) { | ||
if (!hotelId) { | ||
errors.push("The Hotel code is required"); | ||
@@ -486,4 +499,5 @@ } | ||
"errors": errors | ||
} | ||
}; | ||
} | ||
const options = { | ||
@@ -497,16 +511,23 @@ method: 'GET', | ||
}; | ||
try { | ||
const response = await fetch(`${this.serviceURL}/data/reviews?hotelId=${hotelId}&limit=${limit}&getSentiment=${getSentiment}`, options); | ||
const result = await response.json(); | ||
const response = await fetch(`${this.serviceURL}/data/reviews?hotelId=${hotelId}&limit=${limit}&timeout=5&getSentiment=${getSentiment}`, options); | ||
const data = await response.json(); | ||
if (!response.ok) { | ||
if (!response.ok) { | ||
return { | ||
"status": "failed", | ||
"error": result.error || "Failed to fetch reviews" | ||
}; | ||
} | ||
return { | ||
"status": "success", | ||
"data": result.data || [], | ||
"sentimentAnalysis": result.sentimentAnalysis || { } | ||
}; | ||
} catch (error) { | ||
return { | ||
"status": "failed", | ||
"error": data.error | ||
} | ||
"error": error.message || "Unknown error occurred" | ||
}; | ||
} | ||
return { | ||
"status": "success", | ||
"data": data.data | ||
} | ||
} | ||
@@ -513,0 +534,0 @@ /** |
{ | ||
"name": "liteapi-node-sdk", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "Start building travel apps with liteAPI. Instantly access millions of hotels to build new or existing apps and platforms.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -146,7 +146,9 @@ const expect = require('expect.js'); | ||
it('should retrieve hotel reviews by ID', async function() { | ||
const result = await liteApi.getHotelReviews('lp1897', 5, true); | ||
const result = await liteApi.getDataReviews('lp1897', 5, true); | ||
expect(result).to.have.property('status', 'success'); | ||
expect(result).to.have.property('data'); | ||
expect(result.data).to.be.an('array'); | ||
}); | ||
expect(result).to.have.property('sentimentAnalysis'); | ||
expect(result.sentimentAnalysis).to.be.an('object'); | ||
}); | ||
@@ -153,0 +155,0 @@ it('should retrieve available countries', async function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
176685
1230