-
Notifications
You must be signed in to change notification settings - Fork 22
/
m2x-0.4.0.min.js
7 lines (6 loc) · 9.7 KB
/
m2x-0.4.0.min.js
1
2
3
4
5
6
7
/**
* almond 0.2.6 Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/almond for details
*/
(function(e,t){typeof define=="function"&&define.amd?define(t):e.M2X=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f<e.length;f+=1){h=e[f];if(h===".")e.splice(f,1),f-=1;else if(h===".."){if(f===1&&(e[2]===".."||e[0]===".."))break;f>0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v<t.length;v+=1){p=o(t[v],i),l=p.f;if(l==="require")g[v]=u.require(e);else if(l==="exports")g[v]=u.exports(e),w=!0;else if(l==="module")s=g[v]=u.module(e);else if(d(a,l)||d(f,l)||d(c,l))g[v]=b(l);else{if(!p.p)throw new Error(e+" missing "+l);p.p.load(p.n,m(i,!0),y(l),{}),g[v]=a[l]}}h=n.apply(a[e],g);if(e)if(s&&s.exports!==r&&s.exports!==a[e])a[e]=s.exports;else if(h!==r||!w)a[e]=h}else e&&(a[e]=n)},e=t=s=function(e,t,n,a,f){return typeof e=="string"?u[e]?u[e](t):b(o(e,t).f):(e.splice||(l=e,t.splice?(e=t,t=n,n=null):e=r),t=t||function(){},typeof n=="function"&&(n=a,a=f),a?i(r,e,t,n):setTimeout(function(){i(r,e,t,n)},4),s)},s.config=function(e){return l=e,l.deps&&s(l.deps,l.callback),s},e._defined=a,n=function(e,t,n){t.splice||(n=t,t=[]),!d(a,e)&&!d(f,e)&&(f[e]=[e,t,n])},n.amd={jQuery:!0}}(),n("../dist/lib/almond",function(){}),n("helpers",[],function(){function e(e){var t=[].slice.call(arguments,1),n;for(n=0;n<t.length;n++){var r=t[n],i;for(i in r)e[i]=r[i]}return e}function t(e){var t=arguments.length;while(t--)e=e.replace(new RegExp("\\{"+t+"\\}","gm"),arguments[t+1]);return e}function n(e){var n=Array.prototype.slice.call(arguments,1).map(function(e){return encodeURIComponent(e)});return t.apply(this,[e].concat(n))}return{extend:e,format:t,url:n}}),n("Client",["helpers"],function(e){function n(e){var t,n;for(t in e){var r=e[t];n=n?n+"&":"",n+=encodeURIComponent(t)+"="+encodeURIComponent(r)}return n}function r(e,t,r){var i=new XMLHttpRequest,s=n(e.qs),o=s?e.path+"?"+s:e.path;if("withCredentials"in i)i.open(e.verb,o,!0);else{if(typeof XDomainRequest=="undefined")throw"CORS is not supported by this browser.";i=new XDomainRequest,i.open(e.verb,o)}for(var u in e.headers)i.setRequestHeader(u,e.headers[u]);return i.onerror=r,i.onload=function(){if(t){var e=i.responseText?JSON.parse(i.responseText):{};t.apply(i,[e])}},i.send(e.body),i}var t="http://api-m2x.att.com/v1",i=function(e,n){this.apiKey=e,this.apiBase=n||t,this.defaultHeaders={"X-M2X-KEY":this.apiKey};var r=["get","post","put","del","head","options","patch"],i;for(i=0;i<r.length;i++){var s=r[i];this[s]=function(e){return function(t,n,r){this.request(e,t,n,r)}}(s)}};return i.prototype.request=function(t,i,s,o){var u,a;typeof s=="function"&&(o=s,s={}),a=e.extend(this.defaultHeaders,s.headers||{}),a["Content-Type"]||(a["Content-Type"]="application/x-www-form-urlencoded");if(s.params)switch(a["Content-Type"]){case"application/json":u=JSON.stringify(s.params);break;case"application/x-www-form-urlencoded":u=n(s.params);break;default:throw"Unrecognized Content-Type `"+a["Content-Type"]+"`"}r({path:this.apiBase+i,qs:s.qs,verb:t,headers:a,body:u},o,function(){})},i}),n("Batches",["helpers"],function(e){var t=function(e){this.client=e};return t.prototype.search=function(e,t){return this.client.get("/batches",{params:e},t)},t.prototype.list=function(e){return this.search({},e)},t.prototype.create=function(e,t){return this.client.post("/batches",{params:e},t)},t.prototype.view=function(t,n){return this.client.get(e.url("/batches/%s",t),n)},t.prototype.update=function(t,n,r){return this.client.put(e.url("/batches/%s",t),{params:n},r)},t.prototype.datasources=function(t,n,r){return n={params:n||{}},this.client.get(e.url("/batches/%s/datasources",t),n,r)},t.prototype.addDatasource=function(t,n,r){var i={params:{serial:n}};return this.client.post(e.url("/batches/%s/datasources",t),i,r)},t.prototype.del=function(t,n){return this.client.del(e.url("/batches/%s",t),n)},t}),n("Blueprints",["helpers"],function(e){var t=function(e){this.client=e};return t.prototype.search=function(e,t){return this.client.get("/blueprints",{params:e},t)},t.prototype.list=function(e){return this.search({},e)},t.prototype.create=function(e,t){return this.client.post("/blueprints",{params:e},t)},t.prototype.view=function(t,n){return this.client.get(e.url("/blueprints/%s",t),n)},t.prototype.update=function(t,n,r){return this.client.put(e.url("/blueprints/%s",t),{params:n},r)},t.prototype.del=function(t,n){return this.client.del(e.url("/blueprints/%s",t),n)},t}),n("Datasources",["helpers"],function(e){var t=function(e){this.client=e};return t.prototype.search=function(e,t){return this.client.get("/datasources",e,t)},t.prototype.list=function(e){return this.search({},e)},t.prototype.create=function(e,t){return this.client.post("/datasources",{params:e},t)},t.prototype.view=function(t,n){return this.client.get(e.url("/datasources/%s",t),n)},t.prototype.update=function(t,n,r){return this.client.put(e.url("/datasources/%s",t),{params:n},r)},t.prototype.del=function(t,n){return this.client.del(e.url("/datasources/%s",t),n)},t}),n("Keys",["helpers"],function(e){var t=function(e){this.client=e};return t.prototype.list=function(e){return this.client.get("/keys",e)},t.prototype.view=function(t,n){return this.client.get(e.url("/keys/{0}",t),n)},t.prototype.del=function(t,n){return this.client.del(e.url("/keys/{0}",t),n)},t.prototype.create=function(e,t){return this.client.post("/keys",{headers:{"Content-Type":"application/json"},params:e},t)},t.prototype.update=function(t,n,r){return this.client.put(e.url("/keys/{0}",t),{headers:{"Content-Type":"application/json"},params:n},r)},t.prototype.regenerate=function(t,n){return this.client.post(e.url("/keys/{0}/regenerate",t),n)},t}),n("Feeds",["helpers","Keys"],function(e,t){var n=function(e){this.client=e,this.keysAPI=new t(this.client)};return n.prototype.search=function(e,t){return this.client.get("/feeds",{qs:e||{}},t)},n.prototype.list=function(e){return this.search({},e)},n.prototype.view=function(t,n){return this.client.get(e.url("/feeds/{0}",t),n)},n.prototype.log=function(t,n){return this.client.get(e.url("/feeds/{0}/log",t),n)},n.prototype.location=function(t,n){return this.client.get(e.url("/feeds/{0}/location",t),n)},n.prototype.updateLocation=function(t,n,r){return this.client.put(e.url("/feeds/{0}/location",t),{params:n},r)},n.prototype.streams=function(t,n){return this.client.get(e.url("/feeds/{0}/streams",t),n)},n.prototype.stream=function(t,n,r){return this.client.get(e.url("/feeds/{0}/streams/{1}",t,n),r)},n.prototype.streamValues=function(t,n,r,i){var s=e.url("/feeds/{0}/streams/{1}/values",t,n);return typeof r=="function"&&(i=r,r={}),this.client.get(s,{qs:r},i)},n.prototype.updateStream=function(t,n,r,i){return this.client.put(e.url("/feeds/{0}/streams/{1}",t,n),{params:r},i)},n.prototype.deleteStream=function(t,n,r){return this.client.del(e.url("/feeds/{0}/streams/{1}",t,n),r)},n.prototype.keys=function(e,t){return this.client.get("/keys",{qs:{feed:e}},t)},n.prototype.createKey=function(t,n,r){this.keysAPI.create(e.extend(n,{feed:t}),r)},n.prototype.updateKey=function(t,n,r,i){this.keysAPI.update(n,e.extend(r,{feed:t}),i)},n.prototype.postMultiple=function(t,n,r){return this.client.post(e.url("/feeds/{0}",t),{headers:{"Content-Type":"application/json"},params:{values:n}},r)},n.prototype.triggers=function(t,n){return this.client.get(e.url("/feeds/%s/triggers",t),n)},n.prototype.trigger=function(t,n,r){return this.client.get(e.url("/feeds/%s/triggers/%s",t,n),r)},n.prototype.createTrigger=function(t,n,r){return this.client.post(e.url("/feeds/%s/triggers",t),{params:n},r)},n.prototype.updateTrigger=function(t,n,r,i){return this.client.put(e.url("/feeds/%s/triggers/%s",t,n),{params:r},i)},n.prototype.testTrigger=function(t,n,r){return this.client.post(e.url("/feeds/%s/triggers/%s",t,n),r)},n.prototype.deleteTrigger=function(t,n,r){return this.client.del(e.url("/feeds/%s/triggers/%s",t,n),r)},n}),n("m2x",["Client","Batches","Blueprints","Datasources","Feeds","Keys"],function(e,t,n,r,i,s){var o=function(o,u){this.client=new e(o,u),this.batches=new t(this.client),this.blueprints=new n(this.client),this.datasources=new r(this.client),this.feeds=new i(this.client),this.keys=new s(this.client)};return o.prototype.status=function(e){return this.client.get("/status",e)},o}),t("m2x")});