Reestructura APIClient
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
<script>
|
||||
class APIClient {
|
||||
static getApiKey() {
|
||||
return '{{md5($API_KEY)}}{{($login->isIn()) ? $login->getSeparator() . $login->getToken() : ''}}'
|
||||
}
|
||||
|
||||
static fetch(url, options=null, showErrors=false) {
|
||||
return fetchAPI(url, options, showErrors)
|
||||
}
|
||||
}
|
||||
function fetchAPI(url, options=null, showErrors=false) {
|
||||
if (options === null) {
|
||||
options = {}
|
||||
}
|
||||
@ -12,7 +12,7 @@
|
||||
options['headers'] = {}
|
||||
}
|
||||
if (!Object.hasOwn(options['headers'], 'Authorization')) {
|
||||
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}{{($login->isIn()) ? $login->getSeparator() . $login->getToken() : ''}}'
|
||||
options['headers']['Authorization'] = `Bearer ${APIClient.getApiKey()}`
|
||||
}
|
||||
return fetch(url, options).then(response => {
|
||||
if (response.ok) {
|
||||
@ -25,4 +25,8 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
function fetchAPI(url, options=null, showErrors=false) {
|
||||
return APIClient.fetch(url, options, showErrors)
|
||||
}
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user