Created
January 15, 2016 19:05
-
-
Save brandon-beacher/ceff45109d68237a47d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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