forked from fac-14/Week3TakingAIME
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.js
37 lines (34 loc) · 1.04 KB
/
logic.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
var logic = {
apiRequest: function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) return callback(JSON.parse(xhr.responseText));
dom.showError();
}
};
xhr.open("GET", url, true);
xhr.send();
},
getLineStatus: function(lineName) {
var url =
"https://api.tfl.gov.uk/line/" + lineName + "/status?details=false";
logic.apiRequest(url, function(line) {
var lineStatus = line[0].lineStatuses[0].statusSeverityDescription;
dom.renderLineStatus(lineStatus, line[0].name);
logic.getGif(logic.removeWhitespace(lineStatus));
});
},
getGif: function(lineStatus) {
var query = convert.getValue("sentiment", lineStatus);
var url =
"https://api.giphy.com/v1/gifs/random?&api_key=dc6zaTOxFJmzC&tag=" +
query;
logic.apiRequest(url, function(gifObj) {
dom.renderGif(gifObj);
});
},
removeWhitespace: function(string) {
return string.replace(/ /g, "");
}
};