From 26c6bf228d836b89e24883d1828d4dc9b2ad83f6 Mon Sep 17 00:00:00 2001 From: Javier Ubillos Date: Sat, 6 Sep 2014 18:49:54 +0200 Subject: [PATCH 1/3] Added ending ";" to angular-googleapi.js The missing cemicolon made it impossible for me to include the .js file. It now works perfectly! :D --- src/angular-googleapi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/angular-googleapi.js b/src/angular-googleapi.js index 4852c2f..28ad720 100644 --- a/src/angular-googleapi.js +++ b/src/angular-googleapi.js @@ -110,4 +110,4 @@ angular.module('googleApi', []) }); - }) + }); From 1e48eec5bd6bdfe0dd8146ef7c95a5dd423e82df Mon Sep 17 00:00:00 2001 From: Javier Ubillos Date: Wed, 24 Sep 2014 18:58:45 +0200 Subject: [PATCH 2/3] Isolated scope (and as a consequence indented everything one step). Change-Id: I87c18c5f41c14a40543d051a6330f1c29e9ea210 --- src/angular-googleapi.js | 175 ++++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 85 deletions(-) diff --git a/src/angular-googleapi.js b/src/angular-googleapi.js index 28ad720..b0fdb8a 100644 --- a/src/angular-googleapi.js +++ b/src/angular-googleapi.js @@ -1,113 +1,118 @@ -angular.module('googleApi', []) - .value('version', '0.1') +(function(){ + 'use strict'; + angular.module('googleApi', []) + .value('version', '0.1') .service("googleApiBuilder", function($q) { - this.loadClientCallbacks = []; - - this.build = function(requestBuilder, responseTransformer) { - return function(args) { - var deferred = $q.defer(); - var response; - request = requestBuilder(args); - request.execute(function(resp, raw) { - if(resp.error) { - deferred.reject(resp.error); - } else { - response = responseTransformer ? responseTransformer(resp) : resp; - deferred.resolve(response); - } - - }); - return deferred.promise; - + this.loadClientCallbacks = []; + + this.build = function(requestBuilder, responseTransformer) { + return function(args) { + var deferred = $q.defer(); + var response; + var request = requestBuilder(args); + request.execute(function(resp, raw) { + if(resp.error) { + deferred.reject(resp.error); + } else { + response = responseTransformer ? responseTransformer(resp) : resp; + deferred.resolve(response); } - }; - this.afterClientLoaded = function(callback) { - this.loadClientCallbacks.push(callback); - }; + }); + return deferred.promise; - this.runClientLoadedCallbacks = function() { - for(var i=0; i < this.loadClientCallbacks.length; i++) { - this.loadClientCallbacks[i](); - } - }; + } + }; + + this.afterClientLoaded = function(callback) { + this.loadClientCallbacks.push(callback); + }; + + this.runClientLoadedCallbacks = function() { + for(var i=0; i < this.loadClientCallbacks.length; i++) { + this.loadClientCallbacks[i](); + } + }; }) .provider('googleLogin', function() { - this.configure = function(conf) { - this.config = conf; - }; - - this.$get = function ($q, googleApiBuilder, $rootScope) { - var config = this.config; - var deferred = $q.defer(); - return { - login: function () { - gapi.auth.authorize({ client_id: config.clientId, scope: config.scopes, immediate: false}, this.handleAuthResult); - - return deferred.promise; - }, - - handleClientLoad: function () { - gapi.auth.init(function () { }); - window.setTimeout(checkAuth, 1); - }, - - checkAuth: function() { - gapi.auth.authorize({ client_id: config.clientId, scope: config.scopes, immediate: true }, this.handleAuthResult ); - }, - - handleAuthResult: function(authResult) { - if (authResult && !authResult.error) { - var data = {}; - $rootScope.$broadcast("google:authenticated", authResult); - googleApiBuilder.runClientLoadedCallbacks(); - deferred.resolve(data); - } else { - deferred.reject(authResult.error); - } - }, + this.configure = function(conf) { + this.config = conf; + }; + + this.$get = function ($q, googleApiBuilder, $rootScope) { + var config = this.config; + var deferred = $q.defer(); + return { + login: function () { + gapi.auth.authorize({ client_id: config.clientId, scope: config.scopes, immediate: false}, this.handleAuthResult); + + return deferred.promise; + }, + + handleClientLoad: function () { + gapi.auth.init(function () { }); + window.setTimeout(checkAuth, 1); + }, + + checkAuth: function() { + gapi.auth.authorize({ client_id: config.clientId, scope: config.scopes, immediate: true }, this.handleAuthResult ); + }, + + handleAuthResult: function(authResult) { + if (authResult && !authResult.error) { + var data = {}; + $rootScope.$broadcast("google:authenticated", authResult); + googleApiBuilder.runClientLoadedCallbacks(); + deferred.resolve(data); + } else { + deferred.reject(authResult.error); } - }; + }, + } + }; }) .service("googleCalendar", function(googleApiBuilder, $rootScope) { - var self = this; - var itemExtractor = function(resp) { return resp.items; }; + var self = this; + var itemExtractor = function(resp) { return resp.items; }; - googleApiBuilder.afterClientLoaded(function() { - gapi.client.load('calendar', 'v3', function() { + googleApiBuilder.afterClientLoaded(function() { + gapi.client.load('calendar', 'v3', function() { - self.listEvents = googleApiBuilder.build(gapi.client.calendar.events.list, itemExtractor); - self.listCalendars = googleApiBuilder.build(gapi.client.calendar.calendarList.list, itemExtractor); - self.createEvent = googleApiBuilder.build(gapi.client.calendar.events.insert); - - $rootScope.$broadcast("googleCalendar:loaded") - }); + self.listEvents = googleApiBuilder.build(gapi.client.calendar.events.list, itemExtractor); + self.listCalendars = googleApiBuilder.build(gapi.client.calendar.calendarList.list, itemExtractor); + self.createEvent = googleApiBuilder.build(gapi.client.calendar.events.insert); + $rootScope.$broadcast("googleCalendar:loaded") }); + }); + }) - .service("googlePlus", function(googleApiBuilder, $rootScope) { + .service("googlePlus", function(googleApiBuilder, $rootScope) { + + var self = this; + var itemExtractor = function(resp) { return resp.items; }; - var self = this; - var itemExtractor = function(resp) { return resp.items; }; + googleApiBuilder.afterClientLoaded(function() { + gapi.client.load('plus', 'v1', function() { + self.getPeople = googleApiBuilder.build(gapi.client.plus.people.get); + self.getCurrentUser = function() { + return self.getPeople({userId: "me"}); + } + $rootScope.$broadcast("googlePlus:loaded") + }); - googleApiBuilder.afterClientLoaded(function() { - gapi.client.load('plus', 'v1', function() { - self.getPeople = googleApiBuilder.build(gapi.client.plus.people.get); - self.getCurrentUser = function() { - return self.getPeople({userId: "me"}); - } - $rootScope.$broadcast("googlePlus:loaded") - }); + }); }); - }); + }); +})(); \ No newline at end of file From b25c5d9fcb5da9f088f26af9231ef1c30a68ecd3 Mon Sep 17 00:00:00 2001 From: Javier Ubillos Date: Wed, 24 Sep 2014 19:16:50 +0200 Subject: [PATCH 3/3] Added a googledrive service. Change-Id: Ib3df37bef07eb1cc367582c37a1a86c8fd5f024a --- src/angular-googleapi.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/angular-googleapi.js b/src/angular-googleapi.js index b0fdb8a..33524bf 100644 --- a/src/angular-googleapi.js +++ b/src/angular-googleapi.js @@ -112,7 +112,16 @@ }); - }); + }) + .service("googleDrive", function(googleApiBuilder, $rootScope) { + var self = this; + var itemExtractor = function(resp) { return resp.items; }; + googleApiBuilder.afterClientLoaded(function() { + gapi.client.load('drive', 'v2', function() { + self.listFiles = googleApiBuilder.build(gapi.client.drive.files.list); + }); + $rootScope.$broadcast("googleDrive:loaded") + }); }); })(); \ No newline at end of file