From fd1ce4d741cc5992cc5d3d6109dc46cddf871ec2 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 4 Jun 2018 14:21:46 -0700 Subject: Begin adding unconfigured notifier --- app/scripts/lib/4486-notifier.js | 29 ----------------------------- app/scripts/lib/bug-notifier.js | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 29 deletions(-) delete mode 100644 app/scripts/lib/4486-notifier.js create mode 100644 app/scripts/lib/bug-notifier.js (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/4486-notifier.js b/app/scripts/lib/4486-notifier.js deleted file mode 100644 index b1b153419..000000000 --- a/app/scripts/lib/4486-notifier.js +++ /dev/null @@ -1,29 +0,0 @@ -class BugNotifier { - notify (message) { - - postData('http://example.com/answer', {answer: 42}) - .then(data => console.log(data)) // JSON from `response.json()` call - .catch(error => console.error(error)) - } -} - -function postData(url, data) { - // Default options are marked with * - return fetch(url, { - body: JSON.stringify(data), // must match 'Content-Type' header - cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached - credentials: 'same-origin', // include, same-origin, *omit - headers: { - 'user-agent': 'Mozilla/4.0 MDN Example', - 'content-type': 'application/json' - }, - method: 'POST', // *GET, POST, PUT, DELETE, etc. - mode: 'cors', // no-cors, cors, *same-origin - redirect: 'follow', // manual, *follow, error - referrer: 'no-referrer', // *client, no-referrer - }) - .then(response => response.json()) // parses response to JSON -} - -module.exports = BugNotifier - diff --git a/app/scripts/lib/bug-notifier.js b/app/scripts/lib/bug-notifier.js new file mode 100644 index 000000000..d6a2ed2c9 --- /dev/null +++ b/app/scripts/lib/bug-notifier.js @@ -0,0 +1,24 @@ +class BugNotifier { + notify (uri, message) { + return postData(uri, message) + .then(data => console.log(data)) // JSON from `response.json()` call + .catch(error => console.error(error)) + } +} + +function postData(uri, data) { + + return fetch(url, { + body: JSON.stringify(data), // must match 'Content-Type' header + credentials: 'same-origin', // include, same-origin, *omit + headers: { + 'content-type': 'application/json' + }, + method: 'POST', // *GET, POST, PUT, DELETE, etc. + mode: 'cors', // no-cors, cors, *same-origin + }) + .then(response => response.json()) // parses response to JSON +} + +module.exports = BugNotifier + -- cgit v1.2.3