oembed = {
const BASE_URL = 'https://www.data.gouv.fr'
const OEMBED_URL = `${BASE_URL}/api/1/oembed`;
const ATTRS = ['dataset', 'reuse']
const LANG = document.documentElement.lang;
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
} else {
const error = new Error(response.statusText);
error.response = response;
throw error;
}
}
function fetchOEmbed(url) {
return fetch(`${OEMBED_URL}?url=${encodeURIComponent(url)}`)
.then(checkStatus)
.then(response => response.json());
}
function toTitle(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
function createOEmbed(id, type){
return fetchOEmbed(`${BASE_URL}/${LANG}/${type}s/${id}/`)
}
return createOEmbed
}