-
Notifications
You must be signed in to change notification settings - Fork 2
/
ng-ovh.min.js
2 lines (2 loc) · 4.94 KB
/
ng-ovh.min.js
1
2
/*! ngOvh v0.2.0 by Jean-Philippe Blary (@blary_jp) - https://github.com/blaryjp/ng-ovh - License MIT */
angular.module("ngOvh",[]),angular.module("ngOvh").provider("Ovh",function(){"use strict";var a,b="https://api.ovh.com/1.0",c=[{method:"GET",path:"/*"},{method:"POST",path:"/*"},{method:"PUT",path:"/*"},{method:"DELETE",path:"/*"}],d={ak:"",as:"",ck:""},e=!1;this.setBaseUrl=function(a){b=a},this.setAppKey=function(a){d.ak=a},this.setAppSecret=function(a){d.as=a},this.setConsumerKey=function(a){d.ck=a,localStorage.setItem("ovh-ck",a)},this.setAccessRules=function(a){c=a},this.setPreventReturnData=function(a){e=a},this.$get=["$http","$q","$cacheFactory","$window",function(f,g,h,i){function j(a){return o()&&(localStorage.removeItem("ovh-ck"),d.ck=null),f({method:"POST",url:b+"/auth/credential",headers:{"X-Ovh-Application":d.ak},data:{accessRules:c,redirection:a||i.location.href}}).then(function(a){return d.ck=a.data.consumerKey,localStorage.setItem("ovh-ck",d.ck),i.location=a.data.validationUrl,a.data},function(a){return g.reject(a)})}function k(){return o()?p().then(function(a){return f({method:"POST",url:b+"/auth/logout",headers:r({method:"POST",url:b+"/auth/logout",body:"",diff:a})}).then(function(){localStorage.removeItem("ovh-ck"),d.ck=null},function(a){return localStorage.removeItem("ovh-ck"),d.ck=null,g.reject(a)})},function(a){return g.reject(a)}):g.reject({data:{errorCode:"NOT_CREDENTIAL",message:"You're not logged."}})}function l(a){return o()||a.noAuthentication?p().then(function(b){var c=a.params;a.params&&~a.url.indexOf("{")&&(c=angular.copy(a.params),angular.forEach(c,function(b,d){new RegExp("{"+d+"}").test(a.url)&&(a.url=a.url.replace("{"+d+"}",encodeURIComponent(b)),delete c[d])})),a.params=c;var d=URI(a.url).addSearch(a.params||{}).toString();return a.headers=a.noAuthentication?r():r({method:a.method,url:d,body:a.data?angular.toJson(a.data):"",diff:b}),f(a).then(function(a){return e?a:a.data},function(a){return g.reject(a)})},function(a){return g.reject(a)}):g.reject({data:{errorCode:"NOT_CREDENTIAL",message:"You're not logged."}})}function m(a){return f({method:"GET",url:b+a+".json",cache:t,headers:r()}).then(function(a){return a.data},function(a){return g.reject(a)})}function n(a,b){return m(a).then(function(a){return b?a.models[b]?a.models[b]:g.reject({data:{errorCode:"NOT_FOUND",message:"Models not found."}}):a.models},function(a){return g.reject(a)})}function o(){return!!d.ck}function p(){return void 0===a?f({method:"GET",url:b+"/auth/time",cache:t,headers:r()}).then(function(b){return a=Math.floor(Date.now()/1e3)-b.data},function(a){return g.reject(a)}):g.when(!0).then(function(){return a})}function q(a){return"$1$"+s([d.as,d.ck,a.method,a.url,a.body,a.diff].join("+"))}function r(a){if(a){var b=(Math.floor(Date.now()/1e3)-a.diff).toString();return{"Content-Type":"application/json;charset=utf-8","X-Ovh-Application":d.ak,"X-Ovh-Consumer":d.ck,"X-Ovh-Timestamp":b,"X-Ovh-Signature":q({method:a.method,url:a.url,body:a.body,diff:b})}}return{"Content-Type":"application/json;charset=utf-8"}}function s(a){function b(a,b){var c=a<<b|a>>>32-b;return c}function c(a){var b,c,d="";for(b=7;b>=0;b--)c=a>>>4*b&15,d+=c.toString(16);return d}function d(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;c<a.length;c++){var d=a.charCodeAt(c);128>d?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b}var e,f,g,h,i,j,k,l,m,n=new Array(80),o=1732584193,p=4023233417,q=2562383102,r=271733878,s=3285377520;a=d(a);var t=a.length,u=new Array;for(f=0;t-3>f;f+=4)g=a.charCodeAt(f)<<24|a.charCodeAt(f+1)<<16|a.charCodeAt(f+2)<<8|a.charCodeAt(f+3),u.push(g);switch(t%4){case 0:f=2147483648;break;case 1:f=a.charCodeAt(t-1)<<24|8388608;break;case 2:f=a.charCodeAt(t-2)<<24|a.charCodeAt(t-1)<<16|32768;break;case 3:f=a.charCodeAt(t-3)<<24|a.charCodeAt(t-2)<<16|a.charCodeAt(t-1)<<8|128}for(u.push(f);u.length%16!=14;)u.push(0);for(u.push(t>>>29),u.push(t<<3&4294967295),e=0;e<u.length;e+=16){for(f=0;16>f;f++)n[f]=u[e+f];for(f=16;79>=f;f++)n[f]=b(n[f-3]^n[f-8]^n[f-14]^n[f-16],1);for(h=o,i=p,j=q,k=r,l=s,f=0;19>=f;f++)m=b(h,5)+(i&j|~i&k)+l+n[f]+1518500249&4294967295,l=k,k=j,j=b(i,30),i=h,h=m;for(f=20;39>=f;f++)m=b(h,5)+(i^j^k)+l+n[f]+1859775393&4294967295,l=k,k=j,j=b(i,30),i=h,h=m;for(f=40;59>=f;f++)m=b(h,5)+(i&j|i&k|j&k)+l+n[f]+2400959708&4294967295,l=k,k=j,j=b(i,30),i=h,h=m;for(f=60;79>=f;f++)m=b(h,5)+(i^j^k)+l+n[f]+3395469782&4294967295,l=k,k=j,j=b(i,30),i=h,h=m;o=o+h&4294967295,p=p+i&4294967295,q=q+j&4294967295,r=r+k&4294967295,s=s+l&4294967295}var m=c(o)+c(p)+c(q)+c(r)+c(s);return m.toLowerCase()}var t=h("OvhProvider");d.ck=localStorage.getItem("ovh-ck");var u={login:j,logout:k,isLogged:o,getSchema:m,getModels:n};return angular.forEach(["get","put","post","delete","remove","del"],function(a){u[a]=function(c,d){return l(angular.extend(d||{},{method:("remove"===a||"del"===a?"delete":a).toUpperCase(),url:b+c}))}}),u}]});