2015-07-24 17:37:01 +02:00
|
|
|
import $ from 'jquery';
|
|
|
|
|
2015-10-12 13:06:20 +02:00
|
|
|
const GET_TIMEOUT = 5000;
|
|
|
|
const POST_TIMEOUT = 10000;
|
|
|
|
|
2016-04-18 09:30:07 +02:00
|
|
|
// TODO
|
|
|
|
// implement queue meganism
|
|
|
|
const queue = [];
|
|
|
|
|
2015-07-24 17:37:01 +02:00
|
|
|
export function get (url) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
dataType: 'json',
|
2015-10-12 13:06:20 +02:00
|
|
|
timeout: GET_TIMEOUT,
|
2016-04-18 09:30:12 +02:00
|
|
|
type: 'GET',
|
2015-07-24 17:37:01 +02:00
|
|
|
success: (response) => {
|
|
|
|
if (response.status === 'success') {
|
2015-07-27 16:32:11 +02:00
|
|
|
resolve(response.data, response.msg);
|
2015-07-24 17:37:01 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
reject(response.msg);
|
|
|
|
}
|
|
|
|
}
|
2015-10-12 12:33:33 +02:00
|
|
|
}).fail(reject);
|
2015-07-24 17:37:01 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function post (url, data) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
2015-10-12 13:06:20 +02:00
|
|
|
timeout: POST_TIMEOUT,
|
2015-07-24 17:37:01 +02:00
|
|
|
success: (response) => {
|
|
|
|
if (response.status === 'success') {
|
|
|
|
resolve(response.data);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
reject(response.msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-07-23 19:12:50 +02:00
|
|
|
import 'github/fetch';
|
|
|
|
|
|
|
|
export function get (url) {
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
fetch(url).then((response) => {
|
|
|
|
|
|
|
|
return response.json();
|
|
|
|
|
|
|
|
}).then((json) => {
|
|
|
|
|
|
|
|
if (json.status === 'success') {
|
|
|
|
resolve(json.data);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
reject(json.msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
}).catch(reject);
|
2015-07-24 17:37:01 +02:00
|
|
|
|
2015-07-23 19:12:50 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function post (url, data) {
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
fetch(url, {
|
|
|
|
method: 'post',
|
2015-07-24 17:37:01 +02:00
|
|
|
enctype: 'x-www-form-urlencoded',
|
2015-07-23 19:12:50 +02:00
|
|
|
headers: {
|
2015-07-24 17:37:01 +02:00
|
|
|
'Accept': 'application/json'
|
2015-07-23 19:12:50 +02:00
|
|
|
},
|
|
|
|
body: JSON.stringify(data)
|
|
|
|
}).then((response) => {
|
|
|
|
|
|
|
|
return response.json();
|
|
|
|
|
|
|
|
}).then((json) => {
|
|
|
|
|
|
|
|
if (json.status === 'success') {
|
|
|
|
resolve(json.data);
|
2015-07-15 15:06:18 +02:00
|
|
|
}
|
2015-07-23 19:12:50 +02:00
|
|
|
else {
|
|
|
|
reject(json.msg);
|
2015-07-15 15:06:18 +02:00
|
|
|
}
|
2015-07-23 19:12:50 +02:00
|
|
|
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
2015-07-24 17:37:01 +02:00
|
|
|
}
|
|
|
|
*/
|