analytics/assets/js/dashboard/api.js

21 lines
556 B
JavaScript
Raw Normal View History

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, {
date: query.date ? formatISO(query.date) : undefined,
filters: query.filters ? JSON.stringify(query.filters) : undefined
}, ...extraQuery)
url = url + `?${serialize(query)}`
return fetch(url).then(res => res.json())
}