Skip to content

Commit

Permalink
Add Redundancy to MyAcurite Token Refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
leoherzog authored Apr 5, 2022
1 parent da910dc commit 84700a1
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,39 @@ function refreshFromAcurite_() {
}

headers['x-one-vue-token'] = token;

let hubs;
try {
hubs = UrlFetchApp.fetch('https://marapi.myacurite.com/accounts/' + accountId + '/dashboard/hubs/', {"headers": headers}).getContentText();
hubs = JSON.parse(hubs);
}
catch(e) {

const credentials = {
"remember": true,
"email": acuriteUsername,
"password": acuritePassword
}

let hubs = UrlFetchApp.fetch('https://marapi.myacurite.com/accounts/' + accountId + '/dashboard/hubs/', {"headers": headers}).getContentText();
hubs = JSON.parse(hubs);
let token = UrlFetchApp.fetch('https://marapi.myacurite.com/users/login', {
"headers": headers,
"method": "post",
"payload": JSON.stringify(credentials)
}).getContentText();
token = JSON.parse(token);

accountId = token['user']['account_users'][0]['account_id'].toString();
token = token['token_id'];

CacheService.getScriptCache().put('myAcuriteAccountId', accountId, 21600);
CacheService.getScriptCache().put('myAcuriteToken', token, 21600);

Utilities.sleep(5000);

hubs = UrlFetchApp.fetch('https://marapi.myacurite.com/accounts/' + accountId + '/dashboard/hubs/', {"headers": headers}).getContentText();
hubs = JSON.parse(hubs);

}

// console.log(JSON.stringify(hubs));

Expand Down

0 comments on commit 84700a1

Please sign in to comment.