48 lines
1004 B
JavaScript
48 lines
1004 B
JavaScript
|
|
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);
|
|
}
|
|
|
|
function getQuizz(lat, lng) {
|
|
return query('game/quizz', { lat, lng })
|
|
.then(data => {
|
|
return data;
|
|
}).catch(error => {
|
|
throw error;
|
|
});
|
|
}
|
|
|
|
function checkResponse(speciesId) {
|
|
return query('game/check', {
|
|
species: speciesId
|
|
}).then(response => {
|
|
return response.data.correct
|
|
}).catch(error => {
|
|
throw error;
|
|
});
|
|
}
|
|
|
|
const client = {
|
|
getQuizz,
|
|
checkResponse
|
|
}
|
|
|
|
export default client; |