-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaia.js
41 lines (34 loc) · 957 Bytes
/
gaia.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
const request = require('request-promise');
const Promise = require('bluebird');
const GAIA_URL = "http://gaiaro.int.expedia.com";
const requestOptions = {
timeout: 10000
};
/**
* Interfaces with Expedia GAIA API.
*/
class Gaia {
/**
* Gets a geographic region.
*
* @param geoId Region ID
* @returns {string} Region name
*/
getRegionName(geoId) {
/**
* Gets the geo name out of a GAIA response.
*/
function getGeoName(gaiaResponse) {
const json = JSON.parse(gaiaResponse);
const name = json.name;
const geoName = name.split(',')[0];
return geoName;
}
const gaiaUrl = `${GAIA_URL}/features/${geoId}?cid=CAPS&apk=PROMISE_TUTO`;
return request(gaiaUrl, requestOptions).then(function (gaiaResponse) {
return getGeoName(gaiaResponse);
});
}
}
module.exports = new Gaia();