diff --git a/.gitignore b/.gitignore index 6f92a01..0e19c83 100644 --- a/.gitignore +++ b/.gitignore @@ -116,3 +116,4 @@ dist .yarn/install-state.gz .pnp.* +test.js \ No newline at end of file diff --git a/README.md b/README.md index 90312b4..54b2a53 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ # jotify -It's pronounced "jiff" \ No newline at end of file +``` +gotify = require("jotify") + +gotify.url = "https://gotify.domain.tld" +gotify.token = "ABCXYZ" +gotify.priority = 7 + +gotify.send("Title", "Message") +``` + +> Pronounced with a hard J \ No newline at end of file diff --git a/index.js b/index.js index 043b056..274c5e1 100644 --- a/index.js +++ b/index.js @@ -10,20 +10,21 @@ gotify = { throw "gotify url value empty, please use: gotify.url == 'https://gotify.mydomain.tld'" } else if(gotify.token == "") { throw "gotify url value empty, please use: gotify.token == 'xyzxyz'" + } else if(message === undefined) { + throw "gotify message value was undefined" + } else if(title === undefined) { + throw "gotify title value was undefined" + } else { + if (!priority){ + priority = gotify.priority + } + + fetch(gotify.url+'/message?token='+gotify.token, { + method: 'POST', + body: 'title='+title+"&message="+message+"&priority="+priority , + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }}) } - if (!priority){ - priority = gotify.priority - } - - fetch(gotify.url+'/message?token='+gotify.token, { - method: 'POST', - body: 'title='+title+"&message="+message+"&priority="+priority , - headers: { 'Content-Type': 'application/x-www-form-urlencoded' }}) - .then(res => res.text()) - .then(body => console.log(body)) - } } - module.exports = gotify \ No newline at end of file