From ce98a31a119653c813b0a277f14558cbdcd7e99a Mon Sep 17 00:00:00 2001 From: maximepvrt Date: Mon, 2 Nov 2015 00:25:34 +0100 Subject: [PATCH] new version with angular-google-gapi v 1.0.0-SNAPSHOT --- app/app.js | 10 +++++++--- index.html | 4 +++- vendors/angular-google-gapi.min.js | 5 ++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/app.js b/app/app.js index 9b6fccd..6a21982 100644 --- a/app/app.js +++ b/app/app.js @@ -8,8 +8,10 @@ var app = angular.module('angular-google-api-example', [ ]); -app.run(['GAuth', 'GApi', '$state', '$rootScope', '$window', - function(GAuth, GApi, $state, $rootScope, $window) { +app.run(['GAuth', 'GApi', 'GData', '$state', '$rootScope', '$window', + function(GAuth, GApi, GData, $state, $rootScope, $window) { + + $rootScope.gdata = GData; var CLIENT = '526374069175-4vv42arm0ksdr9a1lgkve6vbktfkmlvv.apps.googleusercontent.com'; var BASE; @@ -19,6 +21,8 @@ app.run(['GAuth', 'GApi', '$state', '$rootScope', '$window', BASE = 'https://cloud-endpoints-gae.appspot.com/_ah/api'; } + BASE = 'https://cloud-endpoints-gae.appspot.com/_ah/api'; + GApi.load('myContactApi', 'v1', BASE); GApi.load('calendar', 'v3'); GAuth.setClient(CLIENT); @@ -40,4 +44,4 @@ app.run(['GAuth', 'GApi', '$state', '$rootScope', '$window', }); }; } -]); \ No newline at end of file +]); diff --git a/index.html b/index.html index f41459d..f7f4494 100644 --- a/index.html +++ b/index.html @@ -30,6 +30,7 @@ @@ -46,7 +47,8 @@ - + + diff --git a/vendors/angular-google-gapi.min.js b/vendors/angular-google-gapi.min.js index f404bdf..f13ab0e 100644 --- a/vendors/angular-google-gapi.min.js +++ b/vendors/angular-google-gapi.min.js @@ -1,7 +1,6 @@ /** * An AngularJS module for use all Google Apis and your Google Cloud Endpoints - * @version v0.1.2 + * @version 1.0.0-SNAPSHOT * @link https://github.com/maximepvrt/angular-google-gapi */ - - angular.module("angular-google-gapi",[]),angular.module("angular-google-gapi").factory("GClient",["$document","$q","$timeout","$interval","$window",function(e,n,o,t,i){function r(t){var i=n.defer(),r=e[0].createElement("script");return r.onload=function(e){o(function(){i.resolve(e)})},r.onerror=function(e){o(function(){i.reject(e)})},r.src=t,e[0].body.appendChild(r),i.promise}function a(e){r(c).then(function(){var n=function(e){void 0!=i.gapi.client&&(e(),t.cancel(o))};n(e);var o=t(function(){n(e)},10);u=!0})}var u=!1,c="https://apis.google.com/js/client.js";return{get:function(e){u?e():a(e)}}}]),angular.module("angular-google-gapi").factory("GData",["$rootScope",function(e){e.gapi={};var n=!1,o=null;return{isLogin:function(o){return 0==arguments.length?n:(n=o,void(e.gapi.login=o))},getUser:function(n){return 0==arguments.length?o:(o=n,void(e.gapi.user=n))}}}]),angular.module("angular-google-gapi").factory("GAuth",["$rootScope","$q","GClient","GApi","GData","$interval","$window","$location",function(e,n,o,t,i,r,a){function u(e){if(0==s){var n=arguments.length;o.get(function(){a.gapi.client.load("oauth2","v2",function(){s=!0,1==n&&e()})})}else e()}function c(e,n){u(function(){a.gapi.auth.authorize({client_id:f,scope:p,immediate:e,response_type:d},n)})}function l(){function e(n){if("https://accounts.google.com"===n.origin){var i=JSON.parse(n.data);a.removeEventListener("message",e),i=o(i.a[0],"code"),void 0==i?t.reject():t.resolve(i)}}function o(e,n){n=n.replace(/[[]/,"[").replace(/[]]/,"]");var o=n+"=([^&#]*)",t=new RegExp(o),i=t.exec(e);return null==i?void 0:i[1]}var t=n.defer(),i=$location.protocol+"//"+$location.hostname;console.log($location.port),""!=$location.port&&(i=i+":"+$location.port);a.open("https://accounts.google.com/o/oauth2/auth?scope="+encodeURI(p)+"&redirect_uri=postmessage&response_type=code&client_id="+f+"&access_type=offline&approval_prompt=force&origin="+i,null,"width=800, height=600");return a.addEventListener("message",e),t.promise}function g(){var e=n.defer();return a.gapi.client.oauth2.userinfo.get().execute(function(n){if(n.code)e.reject();else{i.isLogin(!0),t.executeCallbacks();var o={};o.email=n.email,o.picture=n.picture,o.id=n.id,o.name=void 0==n.name?n.email:n.name,o.link=n.link,i.getUser(o),e.resolve()}}),e.promise}var f,s=!1,p="https://www.googleapis.com/auth/userinfo.email",d="token id_token";return{setClient:function(e){f=e},setScope:function(e){p=e},load:function(e){var n=arguments.length;o.get(function(){a.gapi.client.load("oauth2","v2",function(){1==n&&e()})})},checkAuth:function(){var e=n.defer();return c(!0,function(){g().then(function(){e.resolve()},function(){e.reject()})}),e.promise},login:function(){var e=n.defer();return c(!1,function(){g().then(function(){e.resolve()},function(){e.reject()})}),e.promise},logout:function(){var e=n.defer();return u(function(){a.gapi.auth.setToken(null),i.isLogin(!1),i.getUser(null),e.resolve()}),e.promise},offline:function(){var e=n.defer();return l().then(function(n){e.resolve(n)},function(){e.reject()}),e.promise}}}]),angular.module("angular-google-gapi").factory("GApi",["$q","GClient","GData","$window",function(e,n,o,t){function i(e,n,o,t,i){var r={};r.api=e,r.apiLoad=!1,r.method=n,r.params=o,r.auth=t,r.deferred=i,g.push(r)}function r(e,o,i){n.get(function(){t.gapi.client.load(e,o,function(){console.log(e+" "+o+" api loaded"),l.push(e),a(e)},i)})}function a(e){for(var n=e,t=0;t-1&&g.splice(t--,1))}}function u(e,n,o,i){for(var r=n.split("."),e=t.gapi.client[e],a=0;a-1?u(n,o,t,a):i(n,o,t,r,a),a.promise}var l=[],g=[];return{executeCallbacks:function(){a()},load:function(e,n,o){r(e,n,o)},execute:function(e,n,o){return 3==arguments.length?c(e,n,o,!1):2==arguments.length?c(e,n,null,!1):void 0},executeAuth:function(e,n,o){return 3==arguments.length?c(e,n,o,!0):2==arguments.length?c(e,n,null,!0):void 0}}}]); \ No newline at end of file +angular.module("angular-google-gapi",["ngCookies"]),angular.module("angular-google-gapi").factory("GClient",["$document","$q","$window",function($document,$q,$window){function loadScript(src){var deferred=$q.defer();$window._gapiOnLoad=function(){deferred.resolve()};var script=$document[0].createElement("script");return script.onerror=function(e){$timeout(function(){deferred.reject(e)})},script.src=src,$document[0].body.appendChild(script),deferred.promise}var LOAD_GAE_API=!1,LOADING_GAE_API=!1,URL="https://apis.google.com/js/client.js?onload=_gapiOnLoad",API_KEY=null,OBSERVER_CALLBACKS=[];return{get:function(){var deferred=$q.defer();return LOAD_GAE_API?deferred.resolve():LOADING_GAE_API?OBSERVER_CALLBACKS.push(deferred):(LOADING_GAE_API=!0,loadScript(URL).then(function(){$window.gapi.client.setApiKey(API_KEY),LOAD_GAE_API=!0,LOADING_GAE_API=!1,deferred.resolve();for(var i=0;i-1&&observerCallbacks.splice(i--,1))}}function createRequest(api,method,params){for(var pathMethod=method.split("."),api=$window.gapi.client[api],i=0;i-1?runGapi(api,method,params,deferred):registerObserverCallback(api,method,params,auth,deferred),deferred.promise}var apisLoad=[],observerCallbacks=[];return{executeCallbacks:function(){executeCallbacks()},load:load,createRequest:createRequest,execute:function(api,method,params){return 3==arguments.length?execute(api,method,params,!1):2==arguments.length?execute(api,method,null,!1):void 0},executeAuth:function(api,method,params){return 3==arguments.length?execute(api,method,params,!0):2==arguments.length?execute(api,method,null,!0):void 0}}}]);