-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFMECloud.min.js
More file actions
1 lines (1 loc) · 2.74 KB
/
FMECloud.min.js
File metadata and controls
1 lines (1 loc) · 2.74 KB
1
var FMECloud=(function(){if(!Array.prototype.indexOf){Array.prototype.indexOf=function(k,l){for(var h=(l||0),g=this.length;h<g;h++){if(this[h]===k){return h}}return -1}}if(typeof String.prototype.trim!=="function"){String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}}var c={version:"v1",server:"https://api.fmecloud.safe.com",xdomain:false};function b(g){g=g||null;if(g){return c[g]}return c}function f(){if(b().token){return true}throw new Error("You must initialize FMECloud using the FMECloud.init() method.")}function e(h,m,i,l,k,g){i=i||"GET";l=l||null;k=k||null;g=g||"application/json";var j;if(m===null||typeof m!="function"){throw new Error("A callback function must be defined in order to use the FME Cloud REST API.")}if(b("xdomain")){throw new Error("IE8 and IE9 do not support the custom headers required for Cloud CORS requests. Browser Not Supported.")}else{var j=new XMLHttpRequest();j.open(i,h,true);j.setRequestHeader("Accept",g);j.setRequestHeader("Authorization","Bearer "+b("token"));if(k!==null){j.setRequestHeader("Content-type",k)}j.onreadystatechange=function(){var n=4;if(j.readyState==n){var p;try{p=j.responseText;if(p.length===0&&j.status==204){p='{ "delete" : "true" }'}else{if(p.length===0&&j.status==202){p='{ "value" : "true" }'}}p=JSON.parse(p)}catch(o){p=j.response}finally{m(p)}}};j.send(l)}}function a(g){g=g.replace(/{{svr}}/g,b("server"));g=g.replace(/{{ver}}/g,b("version"));return g}var d={init:function(g){if(g==undefined){throw new Error("You did not specify a token in your configuration paramaters.")}b().token=g;if(location.host!=b("server").split("//")[1].split("/")[0]&&navigator.appName=="Microsoft Internet Explorer"&&(navigator.appVersion.indexOf("MSIE 9")!==-1||navigator.appVersion.indexOf("MSIE 8")!==-1)){b().xdomain=true}},launchInstance:function(h,i){i=i||null;var g=a("{{svr}}/{{ver}}/instances");e(g,i,"POST",h,"application/x-www-form-urlencoded")},pauseInstance:function(i,h){h=h||null;var g=a("{{svr}}/{{ver}}/instances/"+i+"/pause");e(g,h,"PUT")},startInstance:function(i,h){h=h||null;var g=a("{{svr}}/{{ver}}/instances/"+i+"/start");e(g,h,"PUT")},restartInstance:function(i,h){h=h||null;var g=a("{{svr}}/{{ver}}/instances/"+i+"/restart");e(g,h,"PUT")},terminateInstance:function(i,h){h=h||null;var g=a("{{svr}}/{{ver}}/instances/"+i+"/terminate");e(g,h,"PUT")},getInstances:function(h){h=h||null;var g=a("{{svr}}/{{ver}}/instances");e(g,h)},getInstance:function(i,h){h=h||null;var g=a("{{svr}}/{{ver}}/instances/"+i);e(g,h)},getCredentials:function(i,h){h=h||null;var g=a("{{svr}}/{{ver}}/instances/"+i+"/credentials");e(g,h)},checkBalance:function(h){h=h||null;var g=a("{{svr}}/{{ver}}/account/balance");e(g,h)},getVersions:function(h){h=h||null;var g=a("{{svr}}/{{ver}}/fme_server_version.json");e(g,h)}};return d}());