2018-06-04 23:05:56 +02:00
|
|
|
class BugNotifier {
|
2018-06-04 23:21:46 +02:00
|
|
|
notify (uri, message) {
|
|
|
|
return postData(uri, message)
|
2018-06-04 23:05:56 +02:00
|
|
|
.then(data => console.log(data)) // JSON from `response.json()` call
|
|
|
|
.catch(error => console.error(error))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-04 23:21:46 +02:00
|
|
|
function postData(uri, data) {
|
|
|
|
|
2018-06-04 23:05:56 +02:00
|
|
|
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
|
|
|
|
|