Merge pull request #2021 from ndom91/update-compliments-module-advice-api

Update Compliments Module - Add Advice API
This commit is contained in:
Michael Teeuw 2020-05-24 13:47:30 +02:00 committed by GitHub
commit bbf48a0dd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
*This release is scheduled to be released on 2020-07-01.*
### Added
- Compliments Module - Add Advice API (https://api.adviceslip.com/) Option
### Updated
- Cleaned up alert module code

View File

@ -39,7 +39,8 @@ Module.register("compliments", {
afternoonStartTime: 12,
afternoonEndTime: 17,
random: true,
mockDate: null
mockDate: null,
advice: false
},
lastIndexUsed:-1,
// Set currentweather from module
@ -62,6 +63,18 @@ Module.register("compliments", {
self.config.compliments = JSON.parse(response);
self.updateDom();
});
} else if (this.config.advice) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open("GET", "https://api.adviceslip.com/advice", true);
xobj.onreadystatechange = function() {
if (xobj.readyState === 4 && xobj.status === 200) {
const adviceResp = JSON.parse(xobj.responseText);
self.config.compliments = adviceResp.slip.advice
self.updateDom();
}
};
xobj.send(null);
}
// Schedule update timer.