-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevTo.ctrl.js
More file actions
29 lines (25 loc) · 891 Bytes
/
devTo.ctrl.js
File metadata and controls
29 lines (25 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const devToApi = {
endpoint: '{{base}}api.v1/dev-to?',
config: {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('token'),
'Content-Type': 'application/json'
}
},
call:async (paramString) => {
return await fetch(devToApi.endpoint + paramString, devToApi.config).then(res => res.json());
}
};
document.querySelector('#dev-api-key-form').addEventListener('submit', event=>{
let apiKey = document.querySelector('#api-key');
devToApi.call('apiKey='+apiKey.value).then(body =>{
if(typeof body.test.error !== 'undefined'){
alert('This API key does not seem to work! Please reenter.');
apiKey.value = '';
} else {
document.querySelector('#webhook-token').textContent = body.token;
}
});
event.preventDefault();
});