2022-08-28 09:14:02 +02:00
|
|
|
const API_VERSION = "0";
|
|
|
|
const API_URL = `/api/${API_VERSION}`;
|
|
|
|
|
|
|
|
const TOKEN = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
|
|
|
|
|
|
|
async function get(url, params) {
|
|
|
|
return await axios.get(url, {
|
|
|
|
params: params,
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': TOKEN
|
|
|
|
}
|
|
|
|
}).then(response => {
|
|
|
|
return response.data;
|
|
|
|
}).catch(error => {
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function query(endpoint, params) {
|
|
|
|
return await get(`${API_URL}/${endpoint}`, params);
|
|
|
|
}
|
|
|
|
|
2024-01-08 19:41:57 +01:00
|
|
|
function getQuizz(region) {
|
|
|
|
return query('game/quizz', { region })
|
2022-08-28 09:14:02 +02:00
|
|
|
}
|
|
|
|
|
2024-01-08 19:41:57 +01:00
|
|
|
function getRegion(lat, lon) {
|
|
|
|
return query('region', { lat, lon })
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkAnswer(species) {
|
|
|
|
return query('game/check', {
|
|
|
|
species: species
|
|
|
|
})
|
2022-08-28 09:14:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const client = {
|
|
|
|
getQuizz,
|
2024-01-08 19:41:57 +01:00
|
|
|
getRegion,
|
2022-08-29 10:38:42 +02:00
|
|
|
checkAnswer
|
2022-08-28 09:14:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default client;
|