2016-02-09 04:57:08 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
|
2015-12-13 04:42:28 +00:00
|
|
|
/**
|
|
|
|
* Responsible for all HTTP requests.
|
2016-02-09 04:57:08 +00:00
|
|
|
*
|
2015-12-13 04:42:28 +00:00
|
|
|
* IMPORTANT:
|
2016-02-09 04:57:08 +00:00
|
|
|
* If the user has a good enough connection to stream music, he or she shouldn't
|
2015-12-13 04:42:28 +00:00
|
|
|
* encounter any HTTP errors. That's why Koel doesn't handle HTTP errors.
|
|
|
|
* After all, even if there were errors, how bad can it be?
|
|
|
|
*/
|
|
|
|
export default {
|
2016-01-19 11:00:23 +00:00
|
|
|
request(method, url, data, successCb = null, errorCb = null) {
|
|
|
|
return Vue.http[method](url, data).then(successCb, errorCb);
|
2015-12-13 04:42:28 +00:00
|
|
|
},
|
|
|
|
|
2016-01-19 11:00:23 +00:00
|
|
|
get(url, data = {}, successCb = null, errorCb = null) {
|
|
|
|
return this.request('get', url, data, successCb, errorCb);
|
2015-12-29 01:35:22 +00:00
|
|
|
},
|
|
|
|
|
2016-01-19 11:00:23 +00:00
|
|
|
post(url, data, successCb = null, errorCb = null) {
|
|
|
|
return this.request('post', url, data, successCb, errorCb);
|
2015-12-13 04:42:28 +00:00
|
|
|
},
|
|
|
|
|
2016-01-19 11:00:23 +00:00
|
|
|
put(url, data, successCb = null, errorCb = null) {
|
|
|
|
return this.request('put', url, data, successCb, errorCb);
|
2015-12-13 04:42:28 +00:00
|
|
|
},
|
|
|
|
|
2016-01-19 11:00:23 +00:00
|
|
|
delete(url, data = {}, successCb = null, errorCb = null) {
|
|
|
|
return this.request('delete', url, data, successCb, errorCb);
|
2015-12-13 04:42:28 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A shortcut method to ping and check if the user session is still valid.
|
|
|
|
*/
|
|
|
|
ping() {
|
|
|
|
return this.get('/');
|
|
|
|
},
|
|
|
|
};
|