diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a70a14a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.grunt +node_modules diff --git a/Gruntfile.coffee b/Gruntfile.coffee new file mode 100644 index 0000000..a7937a6 --- /dev/null +++ b/Gruntfile.coffee @@ -0,0 +1,49 @@ +module.exports = (grunt) -> + grunt.initConfig + uglify: + options: + mangle: true + compress: {} + sourceMap: true + sourceMapIncludeSources: true + build: + src: 'dist/jquery.rest/**/*.js' + dest: 'dist/jquery.rest.min.js' + coffee: + main: + options: + sourceMap: true + expand: true + cwd: 'src' + src: ['**/*.coffee'] + dest: 'dist/jquery.rest/' + ext: '.js' + spec: + options: + bare: true + expand: true + cwd: 'spec_src' + src: ['**/*.coffee'] + dest: 'spec/' + ext: '.js' + jasmine: + src: [ 'dist/jquery.rest.min.js' ] + options: + specs: [ 'spec/*.js' ] + vendor: [ + 'vendor/jquery/dist/jquery.min.js', + 'vendor/jquery.rest/dist/1/jquery.rest.min.js', + 'vendor/knockout/dist/knockout.js', + 'vendor/sjcl/sjcl.js' + ] + watch: + files: ['<%= coffee.main.src %>', '<%= coffee.spec.src %>'] + tasks: ['coffee', 'uglify'] + + grunt.loadNpmTasks 'grunt-contrib-coffee' + grunt.loadNpmTasks 'grunt-contrib-uglify' + grunt.loadNpmTasks 'grunt-contrib-jasmine' + grunt.loadNpmTasks 'grunt-contrib-watch' + + grunt.registerTask 'default', ['coffee', 'uglify'] + grunt.registerTask 'test', ['jasmine'] diff --git a/README.md b/README.md index 304a05c..d32ebc4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ jQuery REST Client ===== -v1.0.1 +v1.0.2 diff --git a/dist/1/jquery.rest.js b/dist/1/jquery.rest.js deleted file mode 100644 index 916553f..0000000 --- a/dist/1/jquery.rest.js +++ /dev/null @@ -1,393 +0,0 @@ -// jQuery REST Client - v1.0.2 - https://github.com/jpillora/jquery.rest -// Jaime Pillora - MIT Copyright 2014 -(function(window,$,undefined) {'use strict'; -var Cache, Resource, Verb, defaultOpts, deleteWarning, encode64, error, inheritExtend, s, stringify, validateOpts, validateStr; - -error = function(msg) { - throw new Error("ERROR: jquery.rest: " + msg); -}; - -s = function(n) { - var t; - t = ""; - while (n-- > 0) { - t += " "; - } - return t; -}; - -encode64 = function(s) { - if (!window.btoa) { - error("You need a polyfill for 'btoa' to use basic auth."); - } - return window.btoa(s); -}; - -stringify = function(obj) { - if (!window.JSON) { - error("You need a polyfill for 'JSON' to use stringify."); - } - return window.JSON.stringify(obj); -}; - -inheritExtend = function(a, b) { - var F; - F = function() {}; - F.prototype = a; - return $.extend(true, new F(), b); -}; - -validateOpts = function(options) { - if (!(options && $.isPlainObject(options))) { - return false; - } - $.each(options, function(name) { - if (defaultOpts[name] === undefined) { - return error("Unknown option: '" + name + "'"); - } - }); - return null; -}; - -validateStr = function(name, str) { - if ('string' !== $.type(str)) { - return error("'" + name + "' must be a string"); - } -}; - -deleteWarning = function() { - return alert('"delete()" has been deprecated. Please use "destroy()" or "del()" instead.'); -}; - -defaultOpts = { - url: '', - cache: 0, - request: function(resource, options) { - return $.ajax(options); - }, - isSingle: false, - autoClearCache: true, - cachableMethods: ['GET'], - methodOverride: false, - stringifyData: false, - stripTrailingSlash: false, - password: null, - username: null, - verbs: { - 'create': 'POST', - 'read': 'GET', - 'update': 'PUT', - 'destroy': 'DELETE' - }, - ajax: { - dataType: 'json' - } -}; - -Cache = (function() { - function Cache(parent) { - this.parent = parent; - this.c = {}; - } - - Cache.prototype.valid = function(date) { - var diff; - diff = new Date().getTime() - date.getTime(); - return diff <= this.parent.opts.cache * 1000; - }; - - Cache.prototype.key = function(obj) { - var key, - _this = this; - key = ""; - $.each(obj, function(k, v) { - return key += k + "=" + ($.isPlainObject(v) ? "{" + _this.key(v) + "}" : v) + "|"; - }); - return key; - }; - - Cache.prototype.get = function(key) { - var result; - result = this.c[key]; - if (!result) { - return; - } - if (this.valid(result.created)) { - return result.data; - } - }; - - Cache.prototype.put = function(key, data) { - return this.c[key] = { - created: new Date(), - data: data - }; - }; - - Cache.prototype.clear = function(regexp) { - var _this = this; - if (regexp) { - return $.each(this.c, function(k) { - if (k.match(regexp)) { - return delete _this.c[k]; - } - }); - } else { - return this.c = {}; - } - }; - - return Cache; - -})(); - -Verb = (function() { - function Verb(name, method, options, parent) { - this.name = name; - this.method = method; - if (options == null) { - options = {}; - } - this.parent = parent; - validateStr('name', this.name); - validateStr('method', this.method); - validateOpts(options); - if (this.parent[this.name]) { - error("Cannot add Verb: '" + name + "' already exists"); - } - this.method = method.toUpperCase(); - if (!options.url) { - options.url = ''; - } - this.opts = inheritExtend(this.parent.opts, options); - this.root = this.parent.root; - this.custom = !defaultOpts.verbs[this.name]; - this.call = $.proxy(this.call, this); - this.call.instance = this; - } - - Verb.prototype.call = function() { - var data, url, _ref; - _ref = this.parent.extractUrlData(this.method, arguments), url = _ref.url, data = _ref.data; - if (this.custom) { - url += this.opts.url || this.name; - } - return this.parent.ajax.call(this, this.method, url, data); - }; - - Verb.prototype.show = function(d) { - return console.log(s(d) + this.name + ": " + this.method); - }; - - return Verb; - -})(); - -Resource = (function() { - function Resource(nameOrUrl, options, parent) { - if (options == null) { - options = {}; - } - validateOpts(options); - if (parent && parent instanceof Resource) { - this.name = nameOrUrl; - validateStr('name', this.name); - this.constructChild(parent, options); - } else { - this.url = nameOrUrl || ''; - validateStr('url', this.url); - this.constructRoot(options); - } - } - - Resource.prototype.constructRoot = function(options) { - this.opts = inheritExtend(defaultOpts, options); - this.root = this; - this.expectedIds = 0; - this.urlNoId = this.url; - this.cache = new Cache(this); - this.parent = null; - return this.name = this.opts.name || 'ROOT'; - }; - - Resource.prototype.constructChild = function(parent, options) { - this.parent = parent; - validateStr('name', this.name); - if (!(this.parent instanceof Resource)) { - this.error("Invalid parent"); - } - if (this.parent[this.name]) { - this.error("'" + name + "' already exists"); - } - if (!options.url) { - options.url = ''; - } - this.opts = inheritExtend(this.parent.opts, options); - this.opts.isSingle = 'isSingle' in options && options.isSingle; - this.root = this.parent.root; - this.urlNoId = this.parent.url + ("" + (this.opts.url || this.name) + "/"); - this.url = this.urlNoId; - this.expectedIds = this.parent.expectedIds; - if (!this.opts.isSingle) { - this.expectedIds += 1; - this.url += ":ID_" + this.expectedIds + "/"; - } - $.each(this.opts.verbs, $.proxy(this.addVerb, this)); - if (this.destroy) { - this.del = this.destroy; - return this["delete"] = deleteWarning; - } - }; - - Resource.prototype.error = function(msg) { - return error("Cannot add Resource: " + msg); - }; - - Resource.prototype.add = function(name, options) { - return this[name] = new Resource(name, options, this); - }; - - Resource.prototype.addVerb = function(name, method, options) { - return this[name] = new Verb(name, method, options, this).call; - }; - - Resource.prototype.show = function(d) { - if (d == null) { - d = 0; - } - if (d > 25) { - error("Plugin Bug! Recursion Fail"); - } - if (this.name) { - console.log(s(d) + this.name + ": " + this.url); - } - $.each(this, function(name, fn) { - if ($.type(fn) === 'function' && fn.instance instanceof Verb && name !== 'del') { - return fn.instance.show(d + 1); - } - }); - $.each(this, function(name, res) { - if (name !== "parent" && name !== "root" && res instanceof Resource) { - return res.show(d + 1); - } - }); - return null; - }; - - Resource.prototype.toString = function() { - return this.name; - }; - - Resource.prototype.extractUrlData = function(name, args) { - var arg, canUrl, canUrlNoId, data, i, id, ids, msg, params, providedIds, t, url, _i, _j, _len, _len1; - ids = []; - data = null; - params = null; - for (_i = 0, _len = args.length; _i < _len; _i++) { - arg = args[_i]; - t = $.type(arg); - if (t === 'string' || t === 'number') { - ids.push(arg); - } else if (t === 'object' && data === null) { - data = arg; - } else if (t === 'object' && params === null) { - params = arg; - } else { - error(("Invalid argument: " + arg + " (" + t + ").") + " Must be strings or ints (IDs) followed by one optional object and one optional query params object."); - } - } - providedIds = ids.length; - canUrl = name !== 'create'; - canUrlNoId = name !== 'update' && name !== 'delete'; - url = null; - if (canUrl && providedIds === this.expectedIds) { - url = this.url; - } - if (canUrlNoId && providedIds === this.expectedIds - 1) { - url = this.urlNoId; - } - if (url === null) { - if (canUrlNoId) { - msg = this.expectedIds - 1; - } - if (canUrl) { - msg = (msg ? msg + ' or ' : '') + this.expectedIds; - } - error("Invalid number of ID arguments, required " + msg + ", provided " + providedIds); - } - for (i = _j = 0, _len1 = ids.length; _j < _len1; i = ++_j) { - id = ids[i]; - url = url.replace(new RegExp("\/:ID_" + (i + 1) + "\/"), "/" + id + "/"); - } - if (params) { - url += "?" + ($.param(params)); - } - return { - url: url, - data: data - }; - }; - - Resource.prototype.ajax = function(method, url, data) { - var ajaxOpts, encoded, escapedUrl, headers, key, req, useCache, - _this = this; - if (!method) { - error("method missing"); - } - if (!url) { - error("url missing"); - } - headers = {}; - if (this.opts.username && this.opts.password) { - encoded = encode64(this.opts.username + ":" + this.opts.password); - headers.Authorization = "Basic " + encoded; - } - if (data && this.opts.stringifyData && (method !== 'GET' && method !== 'HEAD')) { - data = stringify(data); - headers['Content-Type'] = "application/json"; - } - if (this.opts.methodOverride && (method !== 'GET' && method !== 'HEAD' && method !== 'POST')) { - headers['X-HTTP-Method-Override'] = method; - method = 'POST'; - } - if (this.opts.stripTrailingSlash) { - url = url.replace(/\/$/, ""); - } - ajaxOpts = { - url: url, - type: method, - headers: headers - }; - if (data) { - ajaxOpts.data = data; - } - ajaxOpts = $.extend(true, {}, this.opts.ajax, ajaxOpts); - useCache = this.opts.cache && $.inArray(method, this.opts.cachableMethods) >= 0; - if (useCache) { - key = this.root.cache.key(ajaxOpts); - req = this.root.cache.get(key); - if (req) { - return req; - } - } - if (this.opts.cache && this.opts.autoClearCache && $.inArray(method, this.opts.cachableMethods) === -1) { - escapedUrl = url.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); - this.root.cache.clear(new RegExp(escapedUrl)); - } - req = this.opts.request(this.parent, ajaxOpts); - if (useCache) { - req.done(function() { - return _this.root.cache.put(key, req); - }); - } - return req; - }; - - return Resource; - -})(); - -Resource.defaults = defaultOpts; - -$.RestClient = Resource; -}.call(this,window,jQuery)); \ No newline at end of file diff --git a/dist/1/jquery.rest.min.js b/dist/1/jquery.rest.min.js deleted file mode 100644 index 2abfe53..0000000 --- a/dist/1/jquery.rest.min.js +++ /dev/null @@ -1,3 +0,0 @@ -// jQuery REST Client - v1.0.2 - https://github.com/jpillora/jquery.rest -// Jaime Pillora - MIT Copyright 2014 -(function(a,b,c){"use strict";var d,e,f,g,h,i,j,k,l,m,n,o;j=function(a){throw new Error("ERROR: jquery.rest: "+a)},l=function(a){var b;for(b="";a-->0;)b+=" ";return b},i=function(b){return a.btoa||j("You need a polyfill for 'btoa' to use basic auth."),a.btoa(b)},m=function(b){return a.JSON||j("You need a polyfill for 'JSON' to use stringify."),a.JSON.stringify(b)},k=function(a,c){var d;return d=function(){},d.prototype=a,b.extend(!0,new d,c)},n=function(a){return a&&b.isPlainObject(a)?(b.each(a,function(a){return g[a]===c?j("Unknown option: '"+a+"'"):void 0}),null):!1},o=function(a,c){return"string"!==b.type(c)?j("'"+a+"' must be a string"):void 0},h=function(){return alert('"delete()" has been deprecated. Please use "destroy()" or "del()" instead.')},g={url:"",cache:0,request:function(a,c){return b.ajax(c)},isSingle:!1,autoClearCache:!0,cachableMethods:["GET"],methodOverride:!1,stringifyData:!1,stripTrailingSlash:!1,password:null,username:null,verbs:{create:"POST",read:"GET",update:"PUT",destroy:"DELETE"},ajax:{dataType:"json"}},d=function(){function a(a){this.parent=a,this.c={}}return a.prototype.valid=function(a){var b;return b=(new Date).getTime()-a.getTime(),b<=1e3*this.parent.opts.cache},a.prototype.key=function(a){var c,d=this;return c="",b.each(a,function(a,e){return c+=a+"="+(b.isPlainObject(e)?"{"+d.key(e)+"}":e)+"|"}),c},a.prototype.get=function(a){var b;return(b=this.c[a])?this.valid(b.created)?b.data:void 0:void 0},a.prototype.put=function(a,b){return this.c[a]={created:new Date,data:b}},a.prototype.clear=function(a){var c=this;return a?b.each(this.c,function(b){return b.match(a)?delete c.c[b]:void 0}):this.c={}},a}(),f=function(){function a(a,c,d,e){this.name=a,this.method=c,null==d&&(d={}),this.parent=e,o("name",this.name),o("method",this.method),n(d),this.parent[this.name]&&j("Cannot add Verb: '"+a+"' already exists"),this.method=c.toUpperCase(),d.url||(d.url=""),this.opts=k(this.parent.opts,d),this.root=this.parent.root,this.custom=!g.verbs[this.name],this.call=b.proxy(this.call,this),this.call.instance=this}return a.prototype.call=function(){var a,b,c;return c=this.parent.extractUrlData(this.method,arguments),b=c.url,a=c.data,this.custom&&(b+=this.opts.url||this.name),this.parent.ajax.call(this,this.method,b,a)},a.prototype.show=function(a){return console.log(l(a)+this.name+": "+this.method)},a}(),e=function(){function a(b,c,d){null==c&&(c={}),n(c),d&&d instanceof a?(this.name=b,o("name",this.name),this.constructChild(d,c)):(this.url=b||"",o("url",this.url),this.constructRoot(c))}return a.prototype.constructRoot=function(a){return this.opts=k(g,a),this.root=this,this.expectedIds=0,this.urlNoId=this.url,this.cache=new d(this),this.parent=null,this.name=this.opts.name||"ROOT"},a.prototype.constructChild=function(c,d){return this.parent=c,o("name",this.name),this.parent instanceof a||this.error("Invalid parent"),this.parent[this.name]&&this.error("'"+name+"' already exists"),d.url||(d.url=""),this.opts=k(this.parent.opts,d),this.opts.isSingle="isSingle"in d&&d.isSingle,this.root=this.parent.root,this.urlNoId=this.parent.url+(""+(this.opts.url||this.name)+"/"),this.url=this.urlNoId,this.expectedIds=this.parent.expectedIds,this.opts.isSingle||(this.expectedIds+=1,this.url+=":ID_"+this.expectedIds+"/"),b.each(this.opts.verbs,b.proxy(this.addVerb,this)),this.destroy?(this.del=this.destroy,this["delete"]=h):void 0},a.prototype.error=function(a){return j("Cannot add Resource: "+a)},a.prototype.add=function(b,c){return this[b]=new a(b,c,this)},a.prototype.addVerb=function(a,b,c){return this[a]=new f(a,b,c,this).call},a.prototype.show=function(c){return null==c&&(c=0),c>25&&j("Plugin Bug! Recursion Fail"),this.name&&console.log(l(c)+this.name+": "+this.url),b.each(this,function(a,d){return"function"===b.type(d)&&d.instance instanceof f&&"del"!==a?d.instance.show(c+1):void 0}),b.each(this,function(b,d){return"parent"!==b&&"root"!==b&&d instanceof a?d.show(c+1):void 0}),null},a.prototype.toString=function(){return this.name},a.prototype.extractUrlData=function(a,c){var d,e,f,g,h,i,k,l,m,n,o,p,q,r,s,t;for(k=[],g=null,m=null,q=0,s=c.length;s>q;q++)d=c[q],o=b.type(d),"string"===o||"number"===o?k.push(d):"object"===o&&null===g?g=d:"object"===o&&null===m?m=d:j("Invalid argument: "+d+" ("+o+"). Must be strings or ints (IDs) followed by one optional object and one optional query params object.");for(n=k.length,e="create"!==a,f="update"!==a&&"delete"!==a,p=null,e&&n===this.expectedIds&&(p=this.url),f&&n===this.expectedIds-1&&(p=this.urlNoId),null===p&&(f&&(l=this.expectedIds-1),e&&(l=(l?l+" or ":"")+this.expectedIds),j("Invalid number of ID arguments, required "+l+", provided "+n)),h=r=0,t=k.length;t>r;h=++r)i=k[h],p=p.replace(new RegExp("/:ID_"+(h+1)+"/"),"/"+i+"/");return m&&(p+="?"+b.param(m)),{url:p,data:g}},a.prototype.ajax=function(a,c,d){var e,f,g,h,k,l,n,o=this;return a||j("method missing"),c||j("url missing"),h={},this.opts.username&&this.opts.password&&(f=i(this.opts.username+":"+this.opts.password),h.Authorization="Basic "+f),d&&this.opts.stringifyData&&"GET"!==a&&"HEAD"!==a&&(d=m(d),h["Content-Type"]="application/json"),this.opts.methodOverride&&"GET"!==a&&"HEAD"!==a&&"POST"!==a&&(h["X-HTTP-Method-Override"]=a,a="POST"),this.opts.stripTrailingSlash&&(c=c.replace(/\/$/,"")),e={url:c,type:a,headers:h},d&&(e.data=d),e=b.extend(!0,{},this.opts.ajax,e),n=this.opts.cache&&b.inArray(a,this.opts.cachableMethods)>=0,n&&(k=this.root.cache.key(e),l=this.root.cache.get(k))?l:(this.opts.cache&&this.opts.autoClearCache&&-1===b.inArray(a,this.opts.cachableMethods)&&(g=c.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1"),this.root.cache.clear(new RegExp(g))),l=this.opts.request(this.parent,e),n&&l.done(function(){return o.root.cache.put(k,l)}),l)},a}(),e.defaults=g,b.RestClient=e}).call(this,window,jQuery); \ No newline at end of file diff --git a/dist/jquery.rest.min.js b/dist/jquery.rest.min.js index 2a0e9f3..c4106b9 100644 --- a/dist/jquery.rest.min.js +++ b/dist/jquery.rest.min.js @@ -1,3 +1,2 @@ -// jQuery REST Client - v0.0.7 - https://github.com/jpillora/jquery.rest -// Jaime Pillora - MIT Copyright 2013 -!function(a,b,c,d){"use strict";var e,f,g,h,i,j,k,l,m,n,o,p;k=function(a){throw"ERROR: jquery.rest: "+a},m=function(a){var b;for(b="";a-->0;)b+=" ";return b},j=function(b){return a.btoa||k("You need a polyfill for 'btoa' to use basic auth."),a.btoa(b)},n=function(b){return a.JSON||k("You need a polyfill for 'JSON' to use stringify."),a.JSON.stringify(b)},l=function(a,b){var d;return d=function(){},d.prototype=a,c.extend(!0,new d,b)},o=function(a){return a&&c.isPlainObject(a)?(c.each(a,function(a){return h[a]===d?k("Unknown option: '"+a+"'"):void 0}),null):!1},p=function(a,b){return"string"!==c.type(b)?k("'"+a+"' must be a string"):void 0},i=function(){return alert('"delete()" has been deprecated. Please use "destroy()" or "del()" instead.')},h={url:"",cache:0,request:function(a,b){return c.ajax(b)},cachableMethods:["GET"],methodOverride:!1,stringifyData:!1,stripTrailingSlash:!1,password:null,username:null,verbs:{create:"POST",read:"GET",update:"PUT",destroy:"DELETE"},ajax:{dataType:"json"}},e=function(){function a(a){this.parent=a,this.c={}}return a.prototype.valid=function(a){var b;return b=(new Date).getTime()-a.getTime(),b<=1e3*this.parent.opts.cache},a.prototype.key=function(a){var b,d=this;return b="",c.each(a,function(a,e){return b+=a+"="+(c.isPlainObject(e)?"{"+d.key(e)+"}":e)+"|"}),b},a.prototype.get=function(a){var b;return(b=this.c[a])?this.valid(b.created)?b.data:void 0:void 0},a.prototype.put=function(a,b){return this.c[a]={created:new Date,data:b}},a.prototype.clear=function(a){var b=this;return a?c.each(this.c,function(c){return c.match(a)?delete b.c[c]:void 0}):this.c={}},a}(),g=function(){function a(a,b,d,e){this.name=a,this.method=b,null==d&&(d={}),this.parent=e,p("name",this.name),p("method",this.method),o(d),this.parent[this.name]&&k("Cannot add Verb: '"+a+"' already exists"),this.method=b.toUpperCase(),d.url||(d.url=""),this.opts=l(this.parent.opts,d),this.root=this.parent.root,this.custom=!h.verbs[this.name],this.call=c.proxy(this.call,this),this.call.instance=this}return a.prototype.call=function(){var a,b,c;return c=this.parent.extractUrlData(this.method,arguments),b=c.url,a=c.data,this.custom&&(b+=this.opts.url||this.name),this.parent.ajax.call(this,this.method,b,a)},a.prototype.show=function(a){return console.log(m(a)+this.name+": "+this.method)},a}(),f=function(){function a(b,c,d){null==c&&(c={}),o(c),d&&d instanceof a?(this.name=b,p("name",this.name),this.constructChild(d,c)):(this.url=b||"",p("url",this.url),this.constructRoot(c))}return a.prototype.constructRoot=function(a){return this.opts=l(h,a),this.root=this,this.numParents=0,this.urlNoId=this.url,this.cache=new e(this),this.parent=null,this.name=this.opts.name||"ROOT"},a.prototype.constructChild=function(b,d){return this.parent=b,p("name",this.name),this.parent instanceof a||this.error("Invalid parent"),this.parent[this.name]&&this.error("'"+name+"' already exists"),d.url||(d.url=""),this.opts=l(this.parent.opts,d),this.root=this.parent.root,this.numParents=this.parent.numParents+1,this.urlNoId=this.parent.url+(""+(this.opts.url||this.name)+"/"),this.url=this.urlNoId+(":ID_"+this.numParents+"/"),c.each(this.opts.verbs,c.proxy(this.addVerb,this)),this.destroy?(this.del=this.destroy,this["delete"]=i):void 0},a.prototype.error=function(a){return k("Cannot add Resource: "+a)},a.prototype.add=function(b,c){return this[b]=new a(b,c,this)},a.prototype.addVerb=function(a,b,c){return this[a]=new g(a,b,c,this).call},a.prototype.show=function(b){return null==b&&(b=0),b>25&&k("Plugin Bug! Recursion Fail"),this.name&&console.log(m(b)+this.name+": "+this.url),c.each(this,function(a,d){return"function"===c.type(d)&&d.instance instanceof g&&"del"!==a?d.instance.show(b+1):void 0}),c.each(this,function(c,d){return"parent"!==c&&"root"!==c&&d instanceof a?d.show(b+1):void 0}),null},a.prototype.toString=function(){return this.name},a.prototype.extractUrlData=function(a,b){var d,e,f,g,h,i,j,l,m,n,o,p,q,r,s,t;for(j=[],g=null,n=null,q=0,s=b.length;s>q;q++)d=b[q],o=c.type(d),"string"===o||"number"===o?j.push(d):"object"===o&&null===g?g=d:"object"===o&&null===n?n=d:k("Invalid argument: "+d+" ("+o+")."+" Must be strings or ints (IDs) followed by one optional object and one optional query params object.");for(m=j.length,e="create"!==a,f="update"!==a&&"delete"!==a,p=null,e&&m===this.numParents&&(p=this.url),f&&m===this.numParents-1&&(p=this.urlNoId),null===p&&(f&&(l=this.numParents-1),e&&(l=(l?l+" or ":"")+this.numParents),k("Invalid number of ID arguments, required "+l+", provided "+m)),h=r=0,t=j.length;t>r;h=++r)i=j[h],p=p.replace(new RegExp("/:ID_"+(h+1)+"/"),"/"+i+"/");return n&&(p+="?"+c.param(n)),{url:p,data:g}},a.prototype.ajax=function(a,b,d){var e,f,g,h,i,l,m=this;return a||k("method missing"),b||k("url missing"),g={},this.opts.username&&this.opts.password&&(f=j(this.opts.username+":"+this.opts.password),g.Authorization="Basic "+f),d&&this.opts.stringifyData&&(d=n(d),g["Content-Type"]="application/json"),this.opts.methodOverride&&"GET"!==a&&"HEAD"!==a&&"POST"!==a&&(g["X-HTTP-Method-Override"]=a,a="POST"),this.opts.stripTrailingSlash&&(b=b.replace(/\/$/,"")),e={url:b,type:a,headers:g},d&&(e.data=d),e=c.extend(!0,{},this.opts.ajax,e),l=this.opts.cache&&c.inArray(a,this.opts.cachableMethods)>=0,l&&(h=this.root.cache.key(e),i=this.root.cache.get(h))?i:(i=this.opts.request(this.parent,e),l&&i.done(function(){return m.root.cache.put(h,i)}),i)},a}(),f.defaults=h,c.RestClient=f}(window,document,jQuery); \ No newline at end of file +(function(){"use strict";var a,b,c,d,e,f,g,h,i,j,k,l;g=function(a){throw new Error("ERROR: jquery.rest: "+a)},i=function(a){var b;for(b="";a-- >0;)b+=" ";return b},f=function(a){return window.btoa||g("You need a polyfill for 'btoa' to use basic auth."),window.btoa(a)},j=function(a){return window.JSON||g("You need a polyfill for 'JSON' to use stringify."),window.JSON.stringify(a)},h=function(a,b){var c;return c=function(){},c.prototype=a,$.extend(!0,new c,b)},k=function(a){return a&&$.isPlainObject(a)?($.each(a,function(a){return void 0===d[a]?g("Unknown option: '"+a+"'"):void 0}),null):!1},l=function(a,b){return"string"!==$.type(b)?g("'"+a+"' must be a string"):void 0},e=function(){return alert('"delete()" has been deprecated. Please use "destroy()" or "del()" instead.')},d={url:"",cache:0,request:function(a,b){return $.ajax(b)},isSingle:!1,autoClearCache:!0,cachableMethods:["GET"],methodOverride:!1,stringifyData:!1,stripTrailingSlash:!1,password:null,username:null,verbs:{create:"POST",read:"GET",update:"PUT",destroy:"DELETE"},ajax:{dataType:"json"}},a=function(){function a(a){this.parent=a,this.c={}}return a.prototype.valid=function(a){var b;return b=(new Date).getTime()-a.getTime(),b<=1e3*this.parent.opts.cache},a.prototype.key=function(a){var b;return b="",$.each(a,function(a){return function(c,d){return b+=c+"="+($.isPlainObject(d)?"{"+a.key(d)+"}":d)+"|"}}(this)),b},a.prototype.get=function(a){var b;return(b=this.c[a])&&this.valid(b.created)?$.when(JSON.parse(JSON.stringify(b.data))):void 0},a.prototype.put=function(a,b){return b=JSON.parse(JSON.stringify(b.responseJSON)),this.c[a]={created:new Date,data:b}},a.prototype.clear=function(a){return a?$.each(this.c,function(b){return function(c){return c.match(a)?delete b.c[c]:void 0}}(this)):this.c={}},a}(),c=function(){function a(a,b,c,e){this.name=a,this.method=b,null==c&&(c={}),this.parent=e,l("name",this.name),l("method",this.method),k(c),this.parent[this.name]&&g("Cannot add Verb: '"+name+"' already exists"),this.method=this.method.toUpperCase(),c.url||(c.url=""),this.opts=h(this.parent.opts,c),this.root=this.parent.root,this.custom=!d.verbs[this.name],this.call=$.proxy(this.call,this),this.call.instance=this}return a.prototype.call=function(){var a,b,c;return b=this.parent.extractUrlData(this.method,arguments),c=b.url,a=b.data,this.custom&&(c+=this.opts.url||this.name),this.parent.ajax.call(this,this.method,c,a)},a.prototype.show=function(a){return console.log(i(a)+this.name+": "+this.method)},a}(),b=function(){function b(a,c,d){null==c&&(c={}),k(c),d&&d instanceof b?(this.name=a,l("name",this.name),this.constructChild(d,c)):(this.url=a||"",l("url",this.url),this.constructRoot(c))}return b.prototype.constructRoot=function(b){return this.opts=h(d,b),this.root=this,this.expectedIds=0,this.urlNoId=this.url,this.cache=new a(this),this.parent=null,this.name=this.opts.name||"ROOT"},b.prototype.constructChild=function(a,c){return this.parent=a,l("name",this.name),this.parent instanceof b||this.error("Invalid parent"),this.parent[this.name]&&this.error("'"+name+"' already exists"),c.url||(c.url=""),this.opts=h(this.parent.opts,c),this.opts.isSingle="isSingle"in c&&c.isSingle,this.root=this.parent.root,this.urlNoId=this.parent.url+((this.opts.url||this.name)+"/"),this.url=this.urlNoId,this.expectedIds=this.parent.expectedIds,this.opts.isSingle||(this.expectedIds+=1,this.url+=":ID_"+this.expectedIds+"/"),$.each(this.opts.verbs,$.proxy(this.addVerb,this)),this.destroy?(this.del=this.destroy,this["delete"]=e):void 0},b.prototype.error=function(a){return g("Cannot add Resource: "+a)},b.prototype.add=function(a,c){return this[a]=new b(a,c,this)},b.prototype.addVerb=function(a,b,d){return this[a]=new c(a,b,d,this).call},b.prototype.show=function(a){return null==a&&(a=0),a>25&&g("Plugin Bug! Recursion Fail"),this.name&&console.log(i(a)+this.name+": "+this.url),$.each(this,function(b,d){return"function"===$.type(d)&&d.instance instanceof c&&"del"!==b?d.instance.show(a+1):void 0}),$.each(this,function(c,d){return"parent"!==c&&"root"!==c&&d instanceof b?d.show(a+1):void 0}),null},b.prototype.toString=function(){return this.name},b.prototype.extractUrlData=function(a,b){var c,d,e,f,h,i,j,k,l,m,n,o,p,q,r,s;for(j=[],f=null,p=null,k=0,m=b.length;m>k;k++)c=b[k],r=$.type(c),"string"===r||"number"===r?j.push(c):"object"===r&&null===f?f=c:"object"===r&&null===p?p=c:g("Invalid argument: "+c+" ("+this[a]+(": "+r+").")+" Must be strings or ints (IDs) followed by one optional object and one optional query params object.");for(q=j.length,d="create"!==a,e="update"!==a&&"delete"!==a,s=null,d&&q===this.expectedIds&&(s=this.url),e&&q===this.expectedIds-1&&(s=this.urlNoId),null===s&&(e&&(o=this.expectedIds-1),d&&(o=(o?o+" or ":"")+this.expectedIds),g("Invalid number of ID arguments, required "+o+", provided "+q)),h=l=0,n=j.length;n>l;h=++l)i=j[h],s=s.replace(new RegExp("/:ID_"+(h+1)+"/"),"/"+i+"/");return p&&(s+="?"+$.param(p)),{url:s,data:f}},b.prototype.ajax=function(a,b,c){var d,e,h,i,k,l,m;return a||g("method missing"),b||g("url missing"),i={},this.opts.username&&this.opts.password&&(e=f(this.opts.username+":"+this.opts.password),i.Authorization="Basic "+e),c&&this.opts.stringifyData&&"GET"!==a&&"HEAD"!==a&&(c=j(c),i["Content-Type"]="application/json"),this.opts.methodOverride&&"GET"!==a&&"HEAD"!==a&&"POST"!==a&&(i["X-HTTP-Method-Override"]=a,a="POST"),this.opts.stripTrailingSlash&&(b=b.replace(/\/$/,"")),d={url:b,type:a,headers:i},c&&(d.data=c),d=$.extend(!0,{},this.opts.ajax,d),m=this.opts.cache&&$.inArray(a,this.opts.cachableMethods)>=0,m&&(k=this.root.cache.key(d),l=this.root.cache.get(k))?l:(this.opts.cache&&this.opts.autoClearCache&&-1===$.inArray(a,this.opts.cachableMethods)&&(h=b.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1"),this.root.cache.clear(new RegExp(h))),l=this.opts.request(this.parent,d),m&&l.done(function(a){return function(){return a.root.cache.put(k,l)}}(this)),l)},b}(),b.defaults=d,$.RestClient=b}).call(this); +//# sourceMappingURL=jquery.rest.min.js.map \ No newline at end of file diff --git a/dist/jquery.rest.min.js.map b/dist/jquery.rest.min.js.map new file mode 100644 index 0000000..4eaf225 --- /dev/null +++ b/dist/jquery.rest.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["jquery.rest/jquery.js"],"names":["Cache","Resource","Verb","defaultOpts","deleteWarning","encode64","error","inheritExtend","s","stringify","validateOpts","validateStr","msg","Error","n","t","window","btoa","obj","JSON","a","b","F","prototype","$","extend","options","isPlainObject","each","name","undefined","str","type","alert","url","cache","request","resource","ajax","isSingle","autoClearCache","cachableMethods","methodOverride","stringifyData","stripTrailingSlash","password","username","verbs","create","read","update","destroy","dataType","parent1","this","parent","c","valid","date","diff","Date","getTime","opts","key","_this","k","v","get","result","created","when","parse","data","put","responseJSON","clear","regexp","match","name1","method1","method","toUpperCase","root","custom","call","proxy","instance","ref","extractUrlData","arguments","show","d","console","log","nameOrUrl","constructChild","constructRoot","expectedIds","urlNoId","addVerb","del","add","fn","res","toString","args","arg","canUrl","canUrlNoId","i","id","ids","j","l","len","len1","params","providedIds","length","push","replace","RegExp","param","ajaxOpts","encoded","escapedUrl","headers","req","useCache","Authorization","inArray","done","defaults","RestClient"],"mappings":"CAAA,WACE,YACA,IAAIA,GAAOC,EAAUC,EAAMC,EAAaC,EAAeC,EAAUC,EAAOC,EAAeC,EAAGC,EAAWC,EAAcC,CAEnHL,GAAQ,SAASM,GACf,KAAM,IAAIC,OAAM,uBAAyBD,IAG3CJ,EAAI,SAASM,GACX,GAAIC,EAEJ,KADAA,EAAI,GACGD,KAAM,GACXC,GAAK,IAEP,OAAOA,IAGTV,EAAW,SAASG,GAIlB,MAHKQ,QAAOC,MACVX,EAAM,qDAEDU,OAAOC,KAAKT,IAGrBC,EAAY,SAASS,GAInB,MAHKF,QAAOG,MACVb,EAAM,oDAEDU,OAAOG,KAAKV,UAAUS,IAG/BX,EAAgB,SAASa,EAAGC,GAC1B,GAAIC,EAGJ,OAFAA,GAAI,aACJA,EAAEC,UAAYH,EACPI,EAAEC,QAAO,EAAM,GAAIH,GAAKD,IAGjCX,EAAe,SAASgB,GACtB,MAAMA,IAAWF,EAAEG,cAAcD,IAGjCF,EAAEI,KAAKF,EAAS,SAAS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WAAapI,IAEdmF,KAAK9B","file":"jquery.rest.min.js","sourcesContent":["(function() {\n 'use strict';\n var Cache, Resource, Verb, defaultOpts, deleteWarning, encode64, error, inheritExtend, s, stringify, validateOpts, validateStr;\n\n error = function(msg) {\n throw new Error(\"ERROR: jquery.rest: \" + msg);\n };\n\n s = function(n) {\n var t;\n t = \"\";\n while (n-- > 0) {\n t += \" \";\n }\n return t;\n };\n\n encode64 = function(s) {\n if (!window.btoa) {\n error(\"You need a polyfill for 'btoa' to use basic auth.\");\n }\n return window.btoa(s);\n };\n\n stringify = function(obj) {\n if (!window.JSON) {\n error(\"You need a polyfill for 'JSON' to use stringify.\");\n }\n return window.JSON.stringify(obj);\n };\n\n inheritExtend = function(a, b) {\n var F;\n F = function() {};\n F.prototype = a;\n return $.extend(true, new F(), b);\n };\n\n validateOpts = function(options) {\n if (!(options && $.isPlainObject(options))) {\n return false;\n }\n $.each(options, function(name) {\n if (defaultOpts[name] === undefined) {\n return error(\"Unknown option: '\" + name + \"'\");\n }\n });\n return null;\n };\n\n validateStr = function(name, str) {\n if ('string' !== $.type(str)) {\n return error(\"'\" + name + \"' must be a string\");\n }\n };\n\n deleteWarning = function() {\n return alert('\"delete()\" has been deprecated. Please use \"destroy()\" or \"del()\" instead.');\n };\n\n defaultOpts = {\n url: '',\n cache: 0,\n request: function(resource, options) {\n return $.ajax(options);\n },\n isSingle: false,\n autoClearCache: true,\n cachableMethods: ['GET'],\n methodOverride: false,\n stringifyData: false,\n stripTrailingSlash: false,\n password: null,\n username: null,\n verbs: {\n 'create': 'POST',\n 'read': 'GET',\n 'update': 'PUT',\n 'destroy': 'DELETE'\n },\n ajax: {\n dataType: 'json'\n }\n };\n\n Cache = (function() {\n function Cache(parent1) {\n this.parent = parent1;\n this.c = {};\n }\n\n Cache.prototype.valid = function(date) {\n var diff;\n diff = new Date().getTime() - date.getTime();\n return diff <= this.parent.opts.cache * 1000;\n };\n\n Cache.prototype.key = function(obj) {\n var key;\n key = \"\";\n $.each(obj, (function(_this) {\n return function(k, v) {\n return key += k + \"=\" + ($.isPlainObject(v) ? \"{\" + _this.key(v) + \"}\" : v) + \"|\";\n };\n })(this));\n return key;\n };\n\n Cache.prototype.get = function(key) {\n var result;\n result = this.c[key];\n if (!result) {\n return;\n }\n if (this.valid(result.created)) {\n return $.when(JSON.parse(JSON.stringify(result.data)));\n }\n };\n\n Cache.prototype.put = function(key, data) {\n data = JSON.parse(JSON.stringify(data.responseJSON));\n return this.c[key] = {\n created: new Date(),\n data: data\n };\n };\n\n Cache.prototype.clear = function(regexp) {\n if (regexp) {\n return $.each(this.c, (function(_this) {\n return function(k) {\n if (k.match(regexp)) {\n return delete _this.c[k];\n }\n };\n })(this));\n } else {\n return this.c = {};\n }\n };\n\n return Cache;\n\n })();\n\n Verb = (function() {\n function Verb(name1, method1, options, parent1) {\n this.name = name1;\n this.method = method1;\n if (options == null) {\n options = {};\n }\n this.parent = parent1;\n validateStr('name', this.name);\n validateStr('method', this.method);\n validateOpts(options);\n if (this.parent[this.name]) {\n error(\"Cannot add Verb: '\" + name + \"' already exists\");\n }\n this.method = this.method.toUpperCase();\n if (!options.url) {\n options.url = '';\n }\n this.opts = inheritExtend(this.parent.opts, options);\n this.root = this.parent.root;\n this.custom = !defaultOpts.verbs[this.name];\n this.call = $.proxy(this.call, this);\n this.call.instance = this;\n }\n\n Verb.prototype.call = function() {\n var data, ref, url;\n ref = this.parent.extractUrlData(this.method, arguments), url = ref.url, data = ref.data;\n if (this.custom) {\n url += this.opts.url || this.name;\n }\n return this.parent.ajax.call(this, this.method, url, data);\n };\n\n Verb.prototype.show = function(d) {\n return console.log(s(d) + this.name + \": \" + this.method);\n };\n\n return Verb;\n\n })();\n\n Resource = (function() {\n function Resource(nameOrUrl, options, parent) {\n if (options == null) {\n options = {};\n }\n validateOpts(options);\n if (parent && parent instanceof Resource) {\n this.name = nameOrUrl;\n validateStr('name', this.name);\n this.constructChild(parent, options);\n } else {\n this.url = nameOrUrl || '';\n validateStr('url', this.url);\n this.constructRoot(options);\n }\n }\n\n Resource.prototype.constructRoot = function(options) {\n this.opts = inheritExtend(defaultOpts, options);\n this.root = this;\n this.expectedIds = 0;\n this.urlNoId = this.url;\n this.cache = new Cache(this);\n this.parent = null;\n return this.name = this.opts.name || 'ROOT';\n };\n\n Resource.prototype.constructChild = function(parent1, options) {\n this.parent = parent1;\n validateStr('name', this.name);\n if (!(this.parent instanceof Resource)) {\n this.error(\"Invalid parent\");\n }\n if (this.parent[this.name]) {\n this.error(\"'\" + name + \"' already exists\");\n }\n if (!options.url) {\n options.url = '';\n }\n this.opts = inheritExtend(this.parent.opts, options);\n this.opts.isSingle = 'isSingle' in options && options.isSingle;\n this.root = this.parent.root;\n this.urlNoId = this.parent.url + ((this.opts.url || this.name) + \"/\");\n this.url = this.urlNoId;\n this.expectedIds = this.parent.expectedIds;\n if (!this.opts.isSingle) {\n this.expectedIds += 1;\n this.url += \":ID_\" + this.expectedIds + \"/\";\n }\n $.each(this.opts.verbs, $.proxy(this.addVerb, this));\n if (this.destroy) {\n this.del = this.destroy;\n return this[\"delete\"] = deleteWarning;\n }\n };\n\n Resource.prototype.error = function(msg) {\n return error(\"Cannot add Resource: \" + msg);\n };\n\n Resource.prototype.add = function(name, options) {\n return this[name] = new Resource(name, options, this);\n };\n\n Resource.prototype.addVerb = function(name, method, options) {\n return this[name] = new Verb(name, method, options, this).call;\n };\n\n Resource.prototype.show = function(d) {\n if (d == null) {\n d = 0;\n }\n if (d > 25) {\n error(\"Plugin Bug! Recursion Fail\");\n }\n if (this.name) {\n console.log(s(d) + this.name + \": \" + this.url);\n }\n $.each(this, function(name, fn) {\n if ($.type(fn) === 'function' && fn.instance instanceof Verb && name !== 'del') {\n return fn.instance.show(d + 1);\n }\n });\n $.each(this, function(name, res) {\n if (name !== \"parent\" && name !== \"root\" && res instanceof Resource) {\n return res.show(d + 1);\n }\n });\n return null;\n };\n\n Resource.prototype.toString = function() {\n return this.name;\n };\n\n Resource.prototype.extractUrlData = function(name, args) {\n var arg, canUrl, canUrlNoId, data, i, id, ids, j, l, len, len1, msg, params, providedIds, t, url;\n ids = [];\n data = null;\n params = null;\n for (j = 0, len = args.length; j < len; j++) {\n arg = args[j];\n t = $.type(arg);\n if (t === 'string' || t === 'number') {\n ids.push(arg);\n } else if (t === 'object' && data === null) {\n data = arg;\n } else if (t === 'object' && params === null) {\n params = arg;\n } else {\n error((\"Invalid argument: \" + arg + \" (\") + this[name] + (\": \" + t + \").\") + \" Must be strings or ints (IDs) followed by one optional object and one optional query params object.\");\n }\n }\n providedIds = ids.length;\n canUrl = name !== 'create';\n canUrlNoId = name !== 'update' && name !== 'delete';\n url = null;\n if (canUrl && providedIds === this.expectedIds) {\n url = this.url;\n }\n if (canUrlNoId && providedIds === this.expectedIds - 1) {\n url = this.urlNoId;\n }\n if (url === null) {\n if (canUrlNoId) {\n msg = this.expectedIds - 1;\n }\n if (canUrl) {\n msg = (msg ? msg + ' or ' : '') + this.expectedIds;\n }\n error(\"Invalid number of ID arguments, required \" + msg + \", provided \" + providedIds);\n }\n for (i = l = 0, len1 = ids.length; l < len1; i = ++l) {\n id = ids[i];\n url = url.replace(new RegExp(\"\\/:ID_\" + (i + 1) + \"\\/\"), \"/\" + id + \"/\");\n }\n if (params) {\n url += \"?\" + ($.param(params));\n }\n return {\n url: url,\n data: data\n };\n };\n\n Resource.prototype.ajax = function(method, url, data) {\n var ajaxOpts, encoded, escapedUrl, headers, key, req, useCache;\n if (!method) {\n error(\"method missing\");\n }\n if (!url) {\n error(\"url missing\");\n }\n headers = {};\n if (this.opts.username && this.opts.password) {\n encoded = encode64(this.opts.username + \":\" + this.opts.password);\n headers.Authorization = \"Basic \" + encoded;\n }\n if (data && this.opts.stringifyData && (method !== 'GET' && method !== 'HEAD')) {\n data = stringify(data);\n headers['Content-Type'] = \"application/json\";\n }\n if (this.opts.methodOverride && (method !== 'GET' && method !== 'HEAD' && method !== 'POST')) {\n headers['X-HTTP-Method-Override'] = method;\n method = 'POST';\n }\n if (this.opts.stripTrailingSlash) {\n url = url.replace(/\\/$/, \"\");\n }\n ajaxOpts = {\n url: url,\n type: method,\n headers: headers\n };\n if (data) {\n ajaxOpts.data = data;\n }\n ajaxOpts = $.extend(true, {}, this.opts.ajax, ajaxOpts);\n useCache = this.opts.cache && $.inArray(method, this.opts.cachableMethods) >= 0;\n if (useCache) {\n key = this.root.cache.key(ajaxOpts);\n req = this.root.cache.get(key);\n if (req) {\n return req;\n }\n }\n if (this.opts.cache && this.opts.autoClearCache && $.inArray(method, this.opts.cachableMethods) === -1) {\n escapedUrl = url.replace(/([.?*+^$[\\]\\\\(){}|-])/g, \"\\\\$1\");\n this.root.cache.clear(new RegExp(escapedUrl));\n }\n req = this.opts.request(this.parent, ajaxOpts);\n if (useCache) {\n req.done((function(_this) {\n return function() {\n return _this.root.cache.put(key, req);\n };\n })(this));\n }\n return req;\n };\n\n return Resource;\n\n })();\n\n Resource.defaults = defaultOpts;\n\n $.RestClient = Resource;\n\n}).call(this);\n\n//# sourceMappingURL=jquery.js.map\n"]} \ No newline at end of file diff --git a/dist/jquery.rest/jquery.js b/dist/jquery.rest/jquery.js new file mode 100644 index 0000000..20cddbc --- /dev/null +++ b/dist/jquery.rest/jquery.js @@ -0,0 +1,399 @@ +(function() { + 'use strict'; + var Cache, Resource, Verb, defaultOpts, deleteWarning, encode64, error, inheritExtend, s, stringify, validateOpts, validateStr; + + error = function(msg) { + throw new Error("ERROR: jquery.rest: " + msg); + }; + + s = function(n) { + var t; + t = ""; + while (n-- > 0) { + t += " "; + } + return t; + }; + + encode64 = function(s) { + if (!window.btoa) { + error("You need a polyfill for 'btoa' to use basic auth."); + } + return window.btoa(s); + }; + + stringify = function(obj) { + if (!window.JSON) { + error("You need a polyfill for 'JSON' to use stringify."); + } + return window.JSON.stringify(obj); + }; + + inheritExtend = function(a, b) { + var F; + F = function() {}; + F.prototype = a; + return $.extend(true, new F(), b); + }; + + validateOpts = function(options) { + if (!(options && $.isPlainObject(options))) { + return false; + } + $.each(options, function(name) { + if (defaultOpts[name] === undefined) { + return error("Unknown option: '" + name + "'"); + } + }); + return null; + }; + + validateStr = function(name, str) { + if ('string' !== $.type(str)) { + return error("'" + name + "' must be a string"); + } + }; + + deleteWarning = function() { + return alert('"delete()" has been deprecated. Please use "destroy()" or "del()" instead.'); + }; + + defaultOpts = { + url: '', + cache: 0, + request: function(resource, options) { + return $.ajax(options); + }, + isSingle: false, + autoClearCache: true, + cachableMethods: ['GET'], + methodOverride: false, + stringifyData: false, + stripTrailingSlash: false, + password: null, + username: null, + verbs: { + 'create': 'POST', + 'read': 'GET', + 'update': 'PUT', + 'destroy': 'DELETE' + }, + ajax: { + dataType: 'json' + } + }; + + Cache = (function() { + function Cache(parent1) { + this.parent = parent1; + this.c = {}; + } + + Cache.prototype.valid = function(date) { + var diff; + diff = new Date().getTime() - date.getTime(); + return diff <= this.parent.opts.cache * 1000; + }; + + Cache.prototype.key = function(obj) { + var key; + key = ""; + $.each(obj, (function(_this) { + return function(k, v) { + return key += k + "=" + ($.isPlainObject(v) ? "{" + _this.key(v) + "}" : v) + "|"; + }; + })(this)); + return key; + }; + + Cache.prototype.get = function(key) { + var result; + result = this.c[key]; + if (!result) { + return; + } + if (this.valid(result.created)) { + return $.when(JSON.parse(JSON.stringify(result.data))); + } + }; + + Cache.prototype.put = function(key, data) { + data = JSON.parse(JSON.stringify(data.responseJSON)); + return this.c[key] = { + created: new Date(), + data: data + }; + }; + + Cache.prototype.clear = function(regexp) { + if (regexp) { + return $.each(this.c, (function(_this) { + return function(k) { + if (k.match(regexp)) { + return delete _this.c[k]; + } + }; + })(this)); + } else { + return this.c = {}; + } + }; + + return Cache; + + })(); + + Verb = (function() { + function Verb(name1, method1, options, parent1) { + this.name = name1; + this.method = method1; + if (options == null) { + options = {}; + } + this.parent = parent1; + validateStr('name', this.name); + validateStr('method', this.method); + validateOpts(options); + if (this.parent[this.name]) { + error("Cannot add Verb: '" + name + "' already exists"); + } + this.method = this.method.toUpperCase(); + if (!options.url) { + options.url = ''; + } + this.opts = inheritExtend(this.parent.opts, options); + this.root = this.parent.root; + this.custom = !defaultOpts.verbs[this.name]; + this.call = $.proxy(this.call, this); + this.call.instance = this; + } + + Verb.prototype.call = function() { + var data, ref, url; + ref = this.parent.extractUrlData(this.method, arguments), url = ref.url, data = ref.data; + if (this.custom) { + url += this.opts.url || this.name; + } + return this.parent.ajax.call(this, this.method, url, data); + }; + + Verb.prototype.show = function(d) { + return console.log(s(d) + this.name + ": " + this.method); + }; + + return Verb; + + })(); + + Resource = (function() { + function Resource(nameOrUrl, options, parent) { + if (options == null) { + options = {}; + } + validateOpts(options); + if (parent && parent instanceof Resource) { + this.name = nameOrUrl; + validateStr('name', this.name); + this.constructChild(parent, options); + } else { + this.url = nameOrUrl || ''; + validateStr('url', this.url); + this.constructRoot(options); + } + } + + Resource.prototype.constructRoot = function(options) { + this.opts = inheritExtend(defaultOpts, options); + this.root = this; + this.expectedIds = 0; + this.urlNoId = this.url; + this.cache = new Cache(this); + this.parent = null; + return this.name = this.opts.name || 'ROOT'; + }; + + Resource.prototype.constructChild = function(parent1, options) { + this.parent = parent1; + validateStr('name', this.name); + if (!(this.parent instanceof Resource)) { + this.error("Invalid parent"); + } + if (this.parent[this.name]) { + this.error("'" + name + "' already exists"); + } + if (!options.url) { + options.url = ''; + } + this.opts = inheritExtend(this.parent.opts, options); + this.opts.isSingle = 'isSingle' in options && options.isSingle; + this.root = this.parent.root; + this.urlNoId = this.parent.url + ((this.opts.url || this.name) + "/"); + this.url = this.urlNoId; + this.expectedIds = this.parent.expectedIds; + if (!this.opts.isSingle) { + this.expectedIds += 1; + this.url += ":ID_" + this.expectedIds + "/"; + } + $.each(this.opts.verbs, $.proxy(this.addVerb, this)); + if (this.destroy) { + this.del = this.destroy; + return this["delete"] = deleteWarning; + } + }; + + Resource.prototype.error = function(msg) { + return error("Cannot add Resource: " + msg); + }; + + Resource.prototype.add = function(name, options) { + return this[name] = new Resource(name, options, this); + }; + + Resource.prototype.addVerb = function(name, method, options) { + return this[name] = new Verb(name, method, options, this).call; + }; + + Resource.prototype.show = function(d) { + if (d == null) { + d = 0; + } + if (d > 25) { + error("Plugin Bug! Recursion Fail"); + } + if (this.name) { + console.log(s(d) + this.name + ": " + this.url); + } + $.each(this, function(name, fn) { + if ($.type(fn) === 'function' && fn.instance instanceof Verb && name !== 'del') { + return fn.instance.show(d + 1); + } + }); + $.each(this, function(name, res) { + if (name !== "parent" && name !== "root" && res instanceof Resource) { + return res.show(d + 1); + } + }); + return null; + }; + + Resource.prototype.toString = function() { + return this.name; + }; + + Resource.prototype.extractUrlData = function(name, args) { + var arg, canUrl, canUrlNoId, data, i, id, ids, j, l, len, len1, msg, params, providedIds, t, url; + ids = []; + data = null; + params = null; + for (j = 0, len = args.length; j < len; j++) { + arg = args[j]; + t = $.type(arg); + if (t === 'string' || t === 'number') { + ids.push(arg); + } else if (t === 'object' && data === null) { + data = arg; + } else if (t === 'object' && params === null) { + params = arg; + } else { + error(("Invalid argument: " + arg + " (") + this[name] + (": " + t + ").") + " Must be strings or ints (IDs) followed by one optional object and one optional query params object."); + } + } + providedIds = ids.length; + canUrl = name !== 'create'; + canUrlNoId = name !== 'update' && name !== 'delete'; + url = null; + if (canUrl && providedIds === this.expectedIds) { + url = this.url; + } + if (canUrlNoId && providedIds === this.expectedIds - 1) { + url = this.urlNoId; + } + if (url === null) { + if (canUrlNoId) { + msg = this.expectedIds - 1; + } + if (canUrl) { + msg = (msg ? msg + ' or ' : '') + this.expectedIds; + } + error("Invalid number of ID arguments, required " + msg + ", provided " + providedIds); + } + for (i = l = 0, len1 = ids.length; l < len1; i = ++l) { + id = ids[i]; + url = url.replace(new RegExp("\/:ID_" + (i + 1) + "\/"), "/" + id + "/"); + } + if (params) { + url += "?" + ($.param(params)); + } + return { + url: url, + data: data + }; + }; + + Resource.prototype.ajax = function(method, url, data) { + var ajaxOpts, encoded, escapedUrl, headers, key, req, useCache; + if (!method) { + error("method missing"); + } + if (!url) { + error("url missing"); + } + headers = {}; + if (this.opts.username && this.opts.password) { + encoded = encode64(this.opts.username + ":" + this.opts.password); + headers.Authorization = "Basic " + encoded; + } + if (data && this.opts.stringifyData && (method !== 'GET' && method !== 'HEAD')) { + data = stringify(data); + headers['Content-Type'] = "application/json"; + } + if (this.opts.methodOverride && (method !== 'GET' && method !== 'HEAD' && method !== 'POST')) { + headers['X-HTTP-Method-Override'] = method; + method = 'POST'; + } + if (this.opts.stripTrailingSlash) { + url = url.replace(/\/$/, ""); + } + ajaxOpts = { + url: url, + type: method, + headers: headers + }; + if (data) { + ajaxOpts.data = data; + } + ajaxOpts = $.extend(true, {}, this.opts.ajax, ajaxOpts); + useCache = this.opts.cache && $.inArray(method, this.opts.cachableMethods) >= 0; + if (useCache) { + key = this.root.cache.key(ajaxOpts); + req = this.root.cache.get(key); + if (req) { + return req; + } + } + if (this.opts.cache && this.opts.autoClearCache && $.inArray(method, this.opts.cachableMethods) === -1) { + escapedUrl = url.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); + this.root.cache.clear(new RegExp(escapedUrl)); + } + req = this.opts.request(this.parent, ajaxOpts); + if (useCache) { + req.done((function(_this) { + return function() { + return _this.root.cache.put(key, req); + }; + })(this)); + } + return req; + }; + + return Resource; + + })(); + + Resource.defaults = defaultOpts; + + $.RestClient = Resource; + +}).call(this); + +//# sourceMappingURL=jquery.js.map diff --git a/dist/jquery.rest/jquery.js.map b/dist/jquery.rest/jquery.js.map new file mode 100644 index 0000000..9168359 --- /dev/null +++ b/dist/jquery.rest/jquery.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "jquery.js", + "sourceRoot": "../../src/", + "sources": [ + "jquery.rest.coffee" + ], + "names": [], + "mappings": "AAAA;EAAA;AAAA,MAAA;;EAGA,KAAA,GAAQ,SAAC,GAAD;AACN,UAAU,IAAA,KAAA,CAAM,sBAAA,GAAuB,GAA7B;EADJ;;EAGR,CAAA,GAAI,SAAC,CAAD;AAAO,QAAA;IAAA,CAAA,G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AC,KAAK,CAAC,GAAZ,CAAgB,GAAhB;QACN,IAAc,GAAd;AAAA,iBAAO,IAAP;SAHF;;MAMA,IAAG,IAAC,CAAA,IAAI,CAAC,KAAN,IAAgB,IAAC,CAAA,IAAI,CAAC,cAAtB,IAAyC,CAAC,CAAC,OAAF,CAAU,MAAV,EAAkB,IAAC,CAAA,IAAI,CAAC,eAAxB,CAAA,KAA4C,CAAC,CAAzF;QACE,UAAA,GAAa,GAAG,CAAC,OAAJ,CAAY,wBAAZ,EAAsC,MAAtC;QACb,IAAC,CAAA,IAAI,CAAC,KAAK,CAAC,KAAZ,CAAsB,IAAA,MAAA,CAAO,UAAP,CAAtB,EAFF;;MAIA,GAAA,GAAM,IAAC,CAAA,IAAI,CAAC,OAAN,CAAc,IAAC,CAAA,MAAf,EAAuB,QAAvB;MAEN,IAAG,QAAH;QACE,GAAG,CAAC,IAAJ,CAAS,CAAA,SAAA,KAAA;iBAAA,SAAA;mBAAG,KAAC,CAAA,IAAI,CAAC,KAAK,CAAC,GAAZ,CAAgB,GAAhB,EAAqB,GAArB;UAAH;QAAA,CAAA,CAAA,CAAA,IAAA,CAAT,EADF;;AAGA,aAAO;IA1CH;;;;;;EA6CR,QAAQ,CAAC,QAAT,GAAoB;;EAEpB,CAAC,CAAC,UAAF,GAAe;AA7Qf" +} \ No newline at end of file diff --git a/src/jquery.rest.coffee b/src/jquery.rest.coffee index fdc7eca..eef47cd 100644 --- a/src/jquery.rest.coffee +++ b/src/jquery.rest.coffee @@ -69,9 +69,10 @@ class Cache unless result return if @valid result.created - return result.data + return $.when JSON.parse(JSON.stringify(result.data)) return put: (key, data) -> + data = JSON.parse(JSON.stringify(data.responseJSON)) @c[key] = created: new Date() data: data @@ -89,7 +90,7 @@ class Verb validateStr 'method', @method validateOpts options error "Cannot add Verb: '#{name}' already exists" if @parent[@name] - @method = method.toUpperCase() + @method = @method.toUpperCase() #default url to blank options.url = '' unless options.url @@ -195,7 +196,7 @@ class Resource else if t is 'object' and params is null params = arg else - error "Invalid argument: #{arg} (#{t})." + + error "Invalid argument: #{arg} (" + @[name] + ": #{t})." + " Must be strings or ints (IDs) followed by one optional object and one optional query params object." providedIds = ids.length