-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiss_promised.js
More file actions
30 lines (23 loc) · 758 Bytes
/
Copy pathiss_promised.js
File metadata and controls
30 lines (23 loc) · 758 Bytes
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
const request = require('request-promise-native');
const fetchMyIP = function() {
return request('https://api.ipify.org?format=json');
};
const fetchCoordsByIP = function(body) {
const ip = JSON.parse(body).ip;
return request(`http://ipwho.is/${ip}`);
};
const fetchISSFlyOverTimes = function(body) {
const { latitude, longitude } = JSON.parse(body);
const url = `https://iss-flyover.herokuapp.com/json/?lat=${latitude}&lon=${longitude}`;
return request(url);
};
const nextISSTimesForMyLocation = function() {
return fetchMyIP()
.then(fetchCoordsByIP)
.then(fetchISSFlyOverTimes)
.then((data) => {
const { response } = JSON.parse(data);
return response;
});
};
module.exports = { nextISSTimesForMyLocation };