Last active
October 14, 2017 06:21
-
-
Save n-j-m/03f1503e5fc1b6731fcd61b8d0343d61 to your computer and use it in GitHub Desktop.
Revisions
-
n-j-m renamed this gist
Apr 8, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
n-j-m created this gist
Apr 8, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,86 @@ const app_settings = require('json!./app_settings.json') let clientsLoaded = 0 let auth2Loaded = false let signin2Loaded = false let auth2 const apiLoader = { client() { return new Promise(resolve => { let ids = 0 const check = () => { if (ids ++ > 1000 || app_settings.libraries.length === clientsLoaded) { resolve() } else { setTimeout(check, 50) } } check() }) }, auth() { return new Promise(resolve => { const check = () => { if (auth2Loaded && signin2Loaded) { resolve() } else { setTimeout(check, 50) } } check() }) }, gapiLoaded() { return new Promise(resolve => { const hasgapi = () => { if (typeof gapi !== 'undefined' && gapi.client) { resolve() } else { setTimeout(hasgapi, 50) } } hasgapi() }) }, getAuth2() { return auth2 }, signId() { const options = new gapi.auth2.SigninOptionsBuilder({ scopes: app_settings.scopes.join(' ') }) this.getAuth2().signIn(options) } } apiLoader.gapiLoaded() .then(() => { gapi.load('auth2', () => { auth2 = gapi.auth2.init({ client_id: CLIENT_ID, scopes: app_settings.scopes.join(' ') }) auth2Loaded = true }) gapi.load('signin2', () => signin2Loaded = true) const incrementClients = () => clientsLoaded++ for (let i = 0, l = app_settings.libraries.length; i < l; i++) { let client = app_settings.libraries[i] gapi.client.load(client.name, client.version, incrementClients) } }) export default apiLoader