jam-cloud/web/app/assets/javascripts/events/jam_rest.js

63 lines
1.6 KiB
JavaScript

(function (context) {
/**
* Javascript wrappers for the REST API
*/
"use strict";
var Rest2 = {}
context.JK = context.JK || {};
context.JK.Rest2 = Rest2
Rest2.listLiveStreams = () => {
return fetch('/api/live_streams', {
method: 'get',
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
},
})
}
Rest2.getLiveStream = (id) => {
return fetch('/api/live_streams/' + id, {
method: 'get',
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
},
})
}
Rest2.authorizeLiveStream = (data) => {
return fetch('/api/live_streams/claim', {
method: 'post',
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
},
cache: 'no-cache',
body: JSON.stringify(data)
})
}
Rest2.getConfigClient = (options) => {
if(!options) {
options = {}
}
var query = Object.keys(options)
.map(k => `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}`)
.join('&');
return fetch('/api/config/client?' + query, {
method: 'get',
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
},
cache: 'no-cache'
})
}
})(window);