2019-11-19 07:30:42 +03:00
|
|
|
import {formatISO} from './date'
|
|
|
|
|
|
|
|
function serialize(obj) {
|
|
|
|
var str = [];
|
|
|
|
for (var p in obj)
|
|
|
|
if (obj.hasOwnProperty(p)) {
|
|
|
|
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
|
|
|
|
}
|
|
|
|
return str.join("&");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function get(url, query, ...extraQuery) {
|
|
|
|
query = Object.assign({}, query, {
|
2019-11-20 08:48:27 +03:00
|
|
|
date: query.date ? formatISO(query.date) : undefined,
|
|
|
|
filters: query.filters ? JSON.stringify(query.filters) : undefined
|
2019-11-19 07:30:42 +03:00
|
|
|
}, ...extraQuery)
|
|
|
|
|
|
|
|
url = url + `?${serialize(query)}`
|
|
|
|
return fetch(url).then(res => res.json())
|
|
|
|
}
|