-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-google-endpoints.min.js
1 lines (1 loc) · 2.13 KB
/
angular-google-endpoints.min.js
1
function google_endpoints_init(){var e=angular.element(document.body).injector();var t=e.get("$googleEndpoints");t._init()}(function(){angular.module("ngGoogleEndpoints",["ng"]);angular.module("ngGoogleEndpoints").factory("$googleEndpoints",["$q",function(e){function n(){var e=t.apis.length;var n=function(){if(--e==0){if(t.requiresOAuth2){i(false,r)}else{s()}}};if(t.requiresOAuth2){e++;gapi.client.load("oauth2","v2",n)}for(var o=0;o<t.apis.length;o++){var u=t.apis[o];gapi.client.load(u.apiName,u.apiVersion,n,u.apiRoot)}}function r(){var e=gapi.client.oauth2.userinfo.get().execute(function(e){if(!e.code){t.currentUser=e;s()}else{o(e)}})}function i(e,n){gapi.auth.authorize({client_id:t.clientId,scope:"https://www.googleapis.com/auth/userinfo.email",immediate:e},n)}function s(){for(var e=0;e<t.apis.length;e++){t.apis[e].defered.resolve()}}function o(e){for(var n=0;n<t.apis.length;n++){t.apis[n].defered.reject(e)}}function u(e){var t=gapi.client[e.apiName];a(e.service,t,new Array,e)}function a(t,n,r,i){for(var s in n){if(n.hasOwnProperty(s)&&s!="kB"){var o=n[s];if(typeof o=="object"){var u={};var f=r.slice(0);f.push(s);t[s]=u;a(u,o,f,i)}if(typeof o=="function"){var l=gapi.client[i.apiName];for(var c=0;c<r.length;c++){var h=r[c];l=l[h]}var p=l[s];t[s]=function(){var t=p;return function(){var n=e.defer();t.apply(null,arguments).execute(function(e){if(e.code){n.reject(e)}else{n.resolve(e)}});return n.promise}}()}}}}function f(e){t.clientId=e}function l(){t.requiresOAuth2=true}function c(n,r,i){var s=e.defer();var o={apiName:n,apiVersion:r,apiRoot:typeof i=="undefined"?"//"+window.location.host+"/_ah/api":i,defered:e.defer(),service:{loaded:false,failed:false,onceLoaded:s.promise}};o.defered.promise.then(function(){u(o);o.service.loaded=true;o.service.currentUser=t.currentUser;s.resolve()},function(){o.service.failed=true;s.reject()});t.apis.push(o);return o.service}var t={clientId:null,requiresOAuth2:false,apis:new Array,currentUser:null};var h=document.createElement("SCRIPT");h.src="https://apis.google.com/js/client.js?onload=google_endpoints_init";document.body.appendChild(h);return{initClientId:f,requireOAuth2:l,createApiClient:c,_init:n}}])})()