54 lines
1.0 KiB
JavaScript
Executable File
54 lines
1.0 KiB
JavaScript
Executable File
const API_URL = '/api';
|
|
|
|
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);
|
|
}
|
|
|
|
function getQuestion(region) {
|
|
return query('game/question', { region })
|
|
}
|
|
|
|
function getQuizz(region) {
|
|
return query('game/quizz', { region })
|
|
}
|
|
|
|
|
|
function getRegion(lat, lon) {
|
|
return query('region', { lat, lon })
|
|
}
|
|
|
|
function checkAnswer(species) {
|
|
return query('game/check', {
|
|
species: species
|
|
})
|
|
}
|
|
|
|
// function getSpeciesCompletion(term) {
|
|
// return query('game/species/completion', {
|
|
// q: term
|
|
// })
|
|
// }
|
|
|
|
const client = {
|
|
getQuestion,
|
|
getQuizz,
|
|
getRegion,
|
|
checkAnswer
|
|
}
|
|
|
|
export default client; |