Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
version 1.0.0-beta.2
Browse files Browse the repository at this point in the history
fix #61 & #62
  • Loading branch information
maximepvrt committed Mar 22, 2016
1 parent 64bc6d0 commit 235d848
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 37 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-google-gapi",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"homepage": "https://maximepvrt.github.io/angular-google-gapi",
"authors": [
"maximepvrt <[email protected]>"
Expand Down
62 changes: 32 additions & 30 deletions dist/angular-google-gapi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* An AngularJS module for use all Google Apis and your Google Cloud Endpoints
* @version 1.0.0-beta.1
* @version 1.0.0-beta.2
* @link https://github.com/maximepvrt/angular-google-gapi
*/

Expand Down Expand Up @@ -94,34 +94,35 @@
}

//exponentialBackoff
function retryExecute(actionPromise, args) {
var queryResults = $q.defer();
var iter = 0;
retry(actionPromise, iter);
function retry(actionPromise, iter) {
actionPromise.apply(this, args).then(function(body) {
queryResults.resolve(body);
}).catch(function(error){
if((error.code == 403 && error.message.toLowerCase().indexOf('limit exceeded')>-1) || error.code == 503){
var base = 2;
var ms = 1000;
var randomMilliseconds = Math.floor((Math.random() * 1000) + 1);
if(iter < 5){
setTimeout(function(){
retry(actionPromise, ++iter);
}, (ms * Math.pow(base, iter)) + randomMilliseconds);
}
else{
queryResults.reject(error);
}
}
else{
queryResults.reject(error);
}
});
}
return queryResults.promise;
}
function retryExecute(actionPromise, args) {
var queryResults = $q.defer();
var iter = 0;
retry(actionPromise, iter);
function retry(actionPromise, iter) {
actionPromise.apply(this, args).then(function(body) {
queryResults.resolve(body);
}).catch(function(error){
if((error.code == 403 && error.message.toLowerCase().indexOf('limit exceeded')>-1) || error.code == 503){
var base = 2;
var ms = 1000;
var randomMilliseconds = Math.floor((Math.random() * 1000) + 1);
if(iter < 5){
setTimeout(function(){
retry(actionPromise, ++iter);
}, (ms * Math.pow(base, iter)) + randomMilliseconds);
}
else{
queryResults.reject(error);
}
}
else{
queryResults.reject(error);
}
});
}
return queryResults.promise;
}


return {

Expand Down Expand Up @@ -273,7 +274,7 @@
var deferred = $q.defer();
signin(false, function() {
getUser().then(function (user) {
deferred.resolve();
deferred.resolve(user);
}, function () {
deferred.reject();
});
Expand Down Expand Up @@ -328,6 +329,7 @@

}]);
})();

(function() {
'use strict';
angular.module('angular-google-gapi').factory('GClient', ['$document', '$q', '$window',
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-google-gapi.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-google-gapi",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "An AngularJS module for use all Google Apis and your Google Cloud Endpoints (Google App Engine) with OAuth. This module use Google APIs Client Library for JavaScript, available for all GApis.",
"main": "dist/angular-google-gapi.min.js",
"repository": {
Expand All @@ -25,6 +25,10 @@
"dependencies": {
"angular": "~1.x"
},
"files": ["dist"],
"scripts": {
"build": "glup"
},
"devDependencies": {
"del": "^2.0.2",
"gulp": "^3.9.0",
Expand Down
2 changes: 1 addition & 1 deletion src/angular-google-gapi.module.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* An AngularJS module for use all Google Apis and your Google Cloud Endpoints
* @version 1.0.0-beta.1
* @version 1.0.0-beta.2
* @link https://github.com/maximepvrt/angular-google-gapi
*/

Expand Down
35 changes: 33 additions & 2 deletions src/factories/GApi.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,37 @@
return deferred.promise;
}

//exponentialBackoff
function retryExecute(actionPromise, args) {
var queryResults = $q.defer();
var iter = 0;
retry(actionPromise, iter);
function retry(actionPromise, iter) {
actionPromise.apply(this, args).then(function(body) {
queryResults.resolve(body);
}).catch(function(error){
if((error.code == 403 && error.message.toLowerCase().indexOf('limit exceeded')>-1) || error.code == 503){
var base = 2;
var ms = 1000;
var randomMilliseconds = Math.floor((Math.random() * 1000) + 1);
if(iter < 5){
setTimeout(function(){
retry(actionPromise, ++iter);
}, (ms * Math.pow(base, iter)) + randomMilliseconds);
}
else{
queryResults.reject(error);
}
}
else{
queryResults.reject(error);
}
});
}
return queryResults.promise;
}


return {

executeCallbacks : function() {
Expand All @@ -101,9 +132,9 @@

executeAuth: function(api, method, params){
if(arguments.length == 3)
return execute(api, method, params, true);
return retryExecute(execute, arguments); //return execute(api, method, params, true)
if(arguments.length == 2)
return execute(api, method, null, true);
return retryExecute(execute, arguments); //return execute(api, method, null, true)
},
}
}]);
Expand Down

0 comments on commit 235d848

Please sign in to comment.