Create igdb class
This commit is contained in:
parent
9ce1b72394
commit
107fb69730
|
@ -0,0 +1,32 @@
|
|||
export class igdb {
|
||||
constructor() {
|
||||
// make a new token every day
|
||||
setInterval(() => {
|
||||
this.makeClientCred();
|
||||
}, 86000000);
|
||||
this.makeClientCred()
|
||||
}
|
||||
|
||||
makeClientCred() {
|
||||
console.log("Making a token");
|
||||
|
||||
fetch(
|
||||
`https://id.twitch.tv/oauth2/token?client_id=${process.env.igdbClientId}&client_secret=${process.env.igdbClientSecret}&grant_type=client_credentials`,
|
||||
{
|
||||
method: 'POST',
|
||||
},
|
||||
)
|
||||
.then(r => r.json().then(data => ({ status: r.status, headers: r.headers, body: data })))
|
||||
.then(resp => {
|
||||
if (resp.status != 200) {
|
||||
console.log('Failed with ', resp.status, resp.body);
|
||||
return;
|
||||
}
|
||||
process.env.igdbAccessToken = resp.body.access_token;
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
})
|
||||
.finally();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue