-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgoogleFlightsAPI.js
More file actions
93 lines (85 loc) · 2.51 KB
/
googleFlightsAPI.js
File metadata and controls
93 lines (85 loc) · 2.51 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var request = require('request');
var auth = require('./auth.js');
var googleFlightsAPIKey = auth.googleFlightsAPIKey;
// get JSON response from Google FLights API
// console.log('api key', googleFlightsAPIKey);
var getResults = function getResults(origin, destination, date, coordinates, cb) {
var result;
var callingBody = {
"request": {
"slice": [{
"origin": origin,
"destination": destination,
"date": date, //"2015-11-10"
"permittedCarrier": ["EK"],
}],
"passengers": {
"adultCount": 1,
"infantInLapCount": 0,
"infantInSeatCount": 0,
"childCount": 0,
"seniorCount": 0
},
"solutions": 20,
"refundable": false,
"saleCountry": "US"
}
};
var FlightRequest = {
"request": {
"slice": [
{
"origin": "DCA",
"destination": "LAX",
"date": "2015-11-11"
}
],
"passengers": {
"adultCount": 1,
"infantInLapCount": 0,
"infantInSeatCount": 0,
"childCount": 0,
"seniorCount": 0
},
"solutions": 20,
"refundable": false
}
};
// send POST request to Google Flights API
var options = {
uri: "https://www.googleapis.com/qpxExpress/v1/trips/search?key=AIzaSyDjiBoO8LXLflipnTcgBFXGYTi0oWk7sYw",
method: "POST",
headers: {
"content-type": "application/json"
},
body: JSON.stringify(callingBody)
}
request(options, function(err, response, body) {
// console.log('this is body', body);
cb(body, coordinates, destination);
})
// request({
// method: "POST",
// contentType: "application/json",
// uri: "https://www.googleapis.com/qpxExpress/v1/trips/search?key=AIzaSyDjiBoO8LXLflipnTcgBFXGYTi0oWk7sYw",
// // uri: "https://www.googleapis.com/qpxExpress/v1/trips/search?key=" + googleFlightsAPIKey,
// dataType: "jsonp",
// data: JSON.stringify(FlightRequest)
// // muteHttpExceptions : true
// }, function(error, response, body) {
// console.log('37body', body);
// // console.log('38response', response);
// if (error) {
// console.log("There was an error with getResults:", error);
// }
// if (!error && response.statusCode == 200) {
// return result = response;
// }
// });
// console.log('the results', result)
// return result;
};
// console.log('results thing', getResults("SFO", "DXB"));
module.exports = {
getResults
}