Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Created January 15, 2016 19:05
Show Gist options
  • Save brandon-beacher/ceff45109d68237a47d2 to your computer and use it in GitHub Desktop.
Save brandon-beacher/ceff45109d68237a47d2 to your computer and use it in GitHub Desktop.
var Google = require("googleapis");
var r = require("../../rethink");
var AuthClient = require("../auth/client");
var GoogleAccount = require("../../models/google/account");
function GoogleCalendarClient(googleAccountId) {
var authClient = AuthClient.create();
var googleAccount;
function getGoogleAccount() {
return GoogleAccount
.get(googleAccountId)
.then(function (_googleAccount) {
googleAccount = _googleAccount;
return googleAccount;
});
}
function setCredentials() {
authClient.setCredentials(googleAccount.body.token);
}
return getGoogleAccount()
.then(setCredentials)
.then(function () {
return Google.calendar({ version: "v3", auth: authClient });
});
}
module.exports = GoogleCalendarClient;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment