Skip to content

Instantly share code, notes, and snippets.

@ThomasKruegl
Created February 17, 2020 16:55
Show Gist options
  • Save ThomasKruegl/7f866a174231911fcc4690fa803d1d72 to your computer and use it in GitHub Desktop.
Save ThomasKruegl/7f866a174231911fcc4690fa803d1d72 to your computer and use it in GitHub Desktop.
// original call
getCredentials(path.resolve(__dirname, "../../config/google_clientid.json")).then( async (content) => {
const buff_content = JSON.parse(content);
const accessData = await authorize(JSON.parse(content), syncdinfo);
const googleGroupData = await createGoogleGroup(accessData)
console.log("googleGroupData = " + JSON.stringify(googleGroupData));
});
// next call
async function authorize(credentials, accessData) {
// does a load of async calls out to db's and services to checks stuff then send cab call back two two different possibilities
// If the creds are there or not. If they are there it goes to the call
if (!accessData.Item.access_token) {
return getAccessToken(accessData);
}
return accessData;
}
async function getAccessToken(accessData) {
// does a load of stuff
return accessData;
}
async function createGoogleGroup ( auth , accessData ) {
const calendar = google.calendar({version: "v3", auth});
/*console.log("Creating group in google to match ours");
console.log("accessData at createGoogleGroup - " + JSON.stringify(accessData) );*/
let googleCal = {
description: accessData.data.group_description,
summary: accessData.data.group_name,
}
console.log("googleCal at createGoogleGroup - " + JSON.stringify(googleCal) );
let EGID = await calendar.calendars.insert({
requestBody: googleCal,
}).catch(console.error);
console.log("EGID at createGoogleGroup - " + JSON.stringify(EGID) );
return EGID;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment