diff --git a/dist/simple-resource.js b/dist/simple-resource.js index 25fcfeb..494fdd3 100644 --- a/dist/simple-resource.js +++ b/dist/simple-resource.js @@ -91,11 +91,13 @@ 'SimplePaginator' ]) .provider('SimpleResourceSettings', function () { - this.apiUrl = undefined + this.apiUrl = this.transformResponse = this.transformRequest = undefined this.$get = function () { return { apiUrl: this.apiUrl, + transformResponse: this.transformResponse, + transformRequest: this.transformRequest } } @@ -132,7 +134,7 @@ var defaults = { query: { method: 'GET', isArray: true, transformResponse: transformResponse }, - get: { method: 'GET' }, + get: { method: 'GET', transformResponse: transformResponse }, create: { method: 'POST', transformRequest: transformRequest }, update: { method: 'PATCH', transformRequest: transformRequest }, destroy: { method: 'DELETE' } @@ -210,6 +212,30 @@ }]) })(); +(function () { + angular + .module('SimpleResource') + .service('SRHelper', SRHelper) + + function SRHelper () { + var service = { + isNumeric: isNumeric + } + + return service + + /** + * Check whether an object is a number. + * + * @param {Object} object - Object to check numericallity on. + * @return {Boolean} True if number, false otherwise. + */ + function isNumeric (object) { + return !isNaN(parseFloat(object)) && isFinite(object); + } + } +})(); + (function () { SRInterceptor.$inject = ["SimpleResourceSettings", "SimplePaginator"]; angular @@ -285,31 +311,6 @@ } })(); -(function () { - SRHelper.$inject = ["inflector"]; - angular - .module('SimpleResource') - .service('SRHelper', SRHelper) - - function SRHelper (inflector) { - var service = { - isNumeric: isNumeric - } - - return service - - /** - * Check whether an object is a number. - * - * @param {Object} object - Object to check numericallity on. - * @return {Boolean} True if number, false otherwise. - */ - function isNumeric (object) { - return !isNaN(parseFloat(object)) && isFinite(object); - } - } -})(); - (function () { SRParameters.$inject = ["inflector", "SimpleResourceSettings"]; angular diff --git a/dist/simple-resource.min.js b/dist/simple-resource.min.js index 44e2fc1..d3af2c0 100644 --- a/dist/simple-resource.min.js +++ b/dist/simple-resource.min.js @@ -1 +1 @@ -!function(){function e(e){function t(t,r){var i=Object.keys(e.mapping)[0];t[e.mapping[i]]?this.cache[r]=n(t):this.cache[r]={}}function r(e){var t=this.cache[e];if(t)return t}function n(t){var r={};return Object.keys(e.mapping).forEach(function(n){r[n]=parseInt(t[e.mapping[n]],10)}),r}return{cache:{},set:t,get:r}}e.$inject=["PaginatorSettings"],angular.module("SimplePaginator",[]).provider("PaginatorSettings",function(){this.mapping={perPage:"X-Pagination-Limit",current:"X-Pagination-Current-Page",total:"X-Pagination-Total-Count",totalPages:"X-Pagination-Total-Pages"},this.$get=function(){return{mapping:this.mapping}},this.configure=function(e){for(var t in e)this[t]=e[t]}}).service("SimplePaginator",e)}(),function(){angular.module("SimpleResource",["ngResource","platanus.inflector","SimplePaginator"]).provider("SimpleResourceSettings",function(){this.apiUrl=void 0,this.$get=function(){return{apiUrl:this.apiUrl}},this.configure=function(e){for(var t in e)this[t]=e[t]}}).factory("SimpleResource",["$resource","SRHelper","SRInterceptor","SRParameters",function(e,t,r,n){return function(i){var i=n.format(i),a=function(e,t){return r.response(i.namespace,e,t)},o=function(e){return r.request(i.namespace,e)},s={query:{method:"GET",isArray:!0,transformResponse:a},get:{method:"GET"},create:{method:"POST",transformRequest:o},update:{method:"PATCH",transformRequest:o},destroy:{method:"DELETE"}};angular.extend(s,i.methods);var u=i.baseUrl+i.url,c=e(u,i.params,s);return c.all=function(e){var t=e||{};return this.query(t)},c.find=function(e,r){var n=t.isNumeric(e)?{id:e}:e;return this.get(n,r)},c.instanceMethods=function(e){return angular.extend(this.prototype,e),this},c.prototype.save=function(){return this.id?this.$update({id:this.id}):this.$create()},c.prototype.delete=function(){if(!this.id)throw new Error("Object must have an id to be deleted.");return this.$destroy({id:this.id})},c}}])}(),function(){function e(e,t){function r(r,n,i){return t.set(i(),r),e.transformResponse&&(n=e.transformResponse(n,i)),angular.fromJson(n)}function n(t,r){var t=t,n=r;if(t){var i={};i[t]=r,n=i}return e.transformRequest&&(n=e.transformRequest(n)),JSON.stringify(n)}return{response:r,request:n}}e.$inject=["SimpleResourceSettings","SimplePaginator"],angular.module("SimpleResource").service("SRInterceptor",e)}(),function(){function e(e){function t(e){return!isNaN(parseFloat(e))&&isFinite(e)}return{isNumeric:t}}e.$inject=["inflector"],angular.module("SimpleResource").service("SRHelper",e)}(),function(){function e(e,t){function r(e){var e=n(e);return e.params=e.params||{},e.methods=e.methods||{},e.baseUrl=e.baseUrl||t.apiUrl,e}function n(t){if(null!==t&&"string"==typeof t){return{url:"/"+e.pluralize(t)+"/:id/:action",params:{id:"@id",action:"@action"},namespace:t}}if(null!==t&&"object"==typeof t)return t;throw new Error("Argument must be a string or a valid Javascript object.")}return{format:r}}e.$inject=["inflector","SimpleResourceSettings"],angular.module("SimpleResource").service("SRParameters",e)}(); \ No newline at end of file +!function(){function e(e){function t(t,r){var i=Object.keys(e.mapping)[0];t[e.mapping[i]]?this.cache[r]=n(t):this.cache[r]={}}function r(e){var t=this.cache[e];if(t)return t}function n(t){var r={};return Object.keys(e.mapping).forEach(function(n){r[n]=parseInt(t[e.mapping[n]],10)}),r}return{cache:{},set:t,get:r}}e.$inject=["PaginatorSettings"],angular.module("SimplePaginator",[]).provider("PaginatorSettings",function(){this.mapping={perPage:"X-Pagination-Limit",current:"X-Pagination-Current-Page",total:"X-Pagination-Total-Count",totalPages:"X-Pagination-Total-Pages"},this.$get=function(){return{mapping:this.mapping}},this.configure=function(e){for(var t in e)this[t]=e[t]}}).service("SimplePaginator",e)}(),function(){angular.module("SimpleResource",["ngResource","platanus.inflector","SimplePaginator"]).provider("SimpleResourceSettings",function(){this.apiUrl=this.transformResponse=this.transformRequest=void 0,this.$get=function(){return{apiUrl:this.apiUrl,transformResponse:this.transformResponse,transformRequest:this.transformRequest}},this.configure=function(e){for(var t in e)this[t]=e[t]}}).factory("SimpleResource",["$resource","SRHelper","SRInterceptor","SRParameters",function(e,t,r,n){return function(i){var i=n.format(i),a=function(e,t){return r.response(i.namespace,e,t)},o=function(e){return r.request(i.namespace,e)},s={query:{method:"GET",isArray:!0,transformResponse:a},get:{method:"GET",transformResponse:a},create:{method:"POST",transformRequest:o},update:{method:"PATCH",transformRequest:o},destroy:{method:"DELETE"}};angular.extend(s,i.methods);var u=i.baseUrl+i.url,c=e(u,i.params,s);return c.all=function(e){var t=e||{};return this.query(t)},c.find=function(e,r){var n=t.isNumeric(e)?{id:e}:e;return this.get(n,r)},c.instanceMethods=function(e){return angular.extend(this.prototype,e),this},c.prototype.save=function(){return this.id?this.$update({id:this.id}):this.$create()},c.prototype.delete=function(){if(!this.id)throw new Error("Object must have an id to be deleted.");return this.$destroy({id:this.id})},c}}])}(),function(){function e(){function e(e){return!isNaN(parseFloat(e))&&isFinite(e)}return{isNumeric:e}}angular.module("SimpleResource").service("SRHelper",e)}(),function(){function e(e,t){function r(r,n,i){return t.set(i(),r),e.transformResponse&&(n=e.transformResponse(n,i)),angular.fromJson(n)}function n(t,r){var t=t,n=r;if(t){var i={};i[t]=r,n=i}return e.transformRequest&&(n=e.transformRequest(n)),JSON.stringify(n)}return{response:r,request:n}}e.$inject=["SimpleResourceSettings","SimplePaginator"],angular.module("SimpleResource").service("SRInterceptor",e)}(),function(){function e(e,t){function r(e){var e=n(e);return e.params=e.params||{},e.methods=e.methods||{},e.baseUrl=e.baseUrl||t.apiUrl,e}function n(t){if(null!==t&&"string"==typeof t){return{url:"/"+e.pluralize(t)+"/:id/:action",params:{id:"@id",action:"@action"},namespace:t}}if(null!==t&&"object"==typeof t)return t;throw new Error("Argument must be a string or a valid Javascript object.")}return{format:r}}e.$inject=["inflector","SimpleResourceSettings"],angular.module("SimpleResource").service("SRParameters",e)}(); \ No newline at end of file diff --git a/lib/simple-resource/helpers/helper.js b/lib/simple-resource/helpers/helper.js index bec1c09..de16ff8 100644 --- a/lib/simple-resource/helpers/helper.js +++ b/lib/simple-resource/helpers/helper.js @@ -3,7 +3,7 @@ .module('SimpleResource') .service('SRHelper', SRHelper) - function SRHelper (inflector) { + function SRHelper () { var service = { isNumeric: isNumeric } diff --git a/lib/simple-resource/simple-resource.js b/lib/simple-resource/simple-resource.js index d0d2f50..467a535 100644 --- a/lib/simple-resource/simple-resource.js +++ b/lib/simple-resource/simple-resource.js @@ -6,11 +6,13 @@ 'SimplePaginator' ]) .provider('SimpleResourceSettings', function () { - this.apiUrl = undefined + this.apiUrl = this.transformResponse = this.transformRequest = undefined this.$get = function () { return { apiUrl: this.apiUrl, + transformResponse: this.transformResponse, + transformRequest: this.transformRequest } } @@ -47,7 +49,7 @@ var defaults = { query: { method: 'GET', isArray: true, transformResponse: transformResponse }, - get: { method: 'GET' }, + get: { method: 'GET', transformResponse: transformResponse }, create: { method: 'POST', transformRequest: transformRequest }, update: { method: 'PATCH', transformRequest: transformRequest }, destroy: { method: 'DELETE' }