-
Notifications
You must be signed in to change notification settings - Fork 1
/
angular-httpshooter.min.js
1 lines (1 loc) · 3.25 KB
/
angular-httpshooter.min.js
1
!function(){"use strict";function e(e,t,a,o,u){var r={error:"timeout",statusCode:599,message:"timeout"},l=function(e,a){var r=!0;console.info(o.httpshooter_queuedCalls),o.httpshooter_queuedCalls?u.blockDuplicateCalls&&o.httpshooter_queuedCalls.length&&o.httpshooter_queuedCalls.forEach(function(t,a){u.compareDuplicateParam.url&&t.config.url==e.url&&(r=!1),u.compareDuplicateParam.data&&angular.equals(t.config.data,e.data)&&(r=!1)}):o.httpshooter_queuedCalls=[];var l=t.defer();return r?(o.httpshooter_queuedCalls.push({config:e,deferred:l,time:a?a:u.defaultTimeOut}),1===o.httpshooter_queuedCalls.length&&("get"!=e.method&&o.$broadcast("HTTP_CALL_STARTED",e),n()),l.promise):t.reject({data:"",headers:{},status:400,config:e})},n=function(){var e=o.httpshooter_queuedCalls[0].config;switch(e.method.toLowerCase()){case"get":h(e,o.httpshooter_queuedCalls[0].time);break;case"delete":p(e,o.httpshooter_queuedCalls[0].time);break;case"head":m(e,o.httpshooter_queuedCalls[0].time);break;case"post":c(e,o.httpshooter_queuedCalls[0].time);break;case"patch":i(e,o.httpshooter_queuedCalls[0].time);break;case"put":f(e,o.httpshooter_queuedCalls[0].time)}},s=function(e){o.$broadcast("HTTP_CALL_STOPPED",o.httpshooter_queuedCalls[0].config),o.httpshooter_queuedCalls[0].deferred.resolve(e),o.httpshooter_queuedCalls.shift(),o.httpshooter_queuedCalls.length>0&&n()},d=function(e){o.$broadcast("HTTP_CALL_STOPPED",o.httpshooter_queuedCalls[0].config),o.httpshooter_queuedCalls[0].deferred.reject(e),o.httpshooter_queuedCalls.shift(),o.httpshooter_queuedCalls.length>0&&n()},h=function(t,u){var l=o.httpshooter_queuedCalls[0].deferred,n=a(function(){l.reject(r)},u);e({url:t.url,method:"GET",headers:t.headers,timeout:n}).then(function(e){s(e.data)},function(e){d(e.data)})["finally"](function(){a.cancel(n)})},c=function(t,u){var l=o.httpshooter_queuedCalls[0].deferred,n=a(function(){l.reject(r)},u);e({url:t.url,method:"POST",headers:t.headers,data:t.data,timeout:n}).then(function(e){s(e.data)},function(e){d(e.data)})["finally"](function(){a.cancel(n)})},i=function(t,u){var l=o.httpshooter_queuedCalls[0].deferred,n=a(function(){l.reject(r)},u);e({url:t.url,method:"POST",headers:t.headers,data:t.data,timeout:n}).then(function(e){s(e.data)},function(e){d(e.data)})["finally"](function(){a.cancel(n)})},f=function(t,u){var l=o.httpshooter_queuedCalls[0].deferred,n=a(function(){l.reject(r)},u);e({url:t.url,method:"POST",headers:t.headers,data:t.data,timeout:n}).then(function(e){s(e.data)},function(e){d(e.data)})["finally"](function(){a.cancel(n)})},p=function(t,u){var l=o.httpshooter_queuedCalls[0].deferred,n=a(function(){l.reject(r)},u);return e({url:t.url,method:"DELETE",data:t.data,headers:t.headers,timeout:n}).then(function(e){s(e.data)},function(e){d(e.data)})["finally"](function(){a.cancel(n)}),l.promise},m=function(t,u){var l=o.httpshooter_queuedCalls[0].deferred,n=a(function(){l.reject(r)},u);e({url:url,method:"HEAD",timeout:n}).then(function(e){s(e.data)},function(e){d(e.data)})["finally"](function(){a.cancel(n)})};return{queue:l}}angular.module("angular-httpshooter",[]).factory("$httpshooter",e),e.$inject=["$http","$q","$timeout","$rootScope","shootConfig"],angular.module("angular-httpshooter").constant("shootConfig",{defaultTimeOut:36e3,blockDuplicateCalls:!0,compareDuplicateParam:{url:!0,data:!1}})}();