Skip to content

Commit

Permalink
Stable Version 1.0.0-alpha.4.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Dec 1, 2014
1 parent fa6c996 commit b1fb4da
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
##### 1.0.0-alpha.4 - 01 December 2014

###### Backwards compatible API changes
- Added DSHttpAdapter.getPath

###### Backwards compatible bug fixes
- #8 - Fixed handling of `forceTrailingSlash` option

##### 1.0.0-alpha.3 - 19 November 2014

###### Breaking API changes
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js-data-http",
"description": "http adapter for js-data.",
"version": "1.0.0-alpha.3",
"version": "1.0.0-alpha.4",
"homepage": "http://www.js-data.io/docs/dshttpadapter",
"repository": {
"type": "git",
Expand Down
37 changes: 21 additions & 16 deletions dist/js-data-http.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @author Jason Dobry <[email protected]>
* @file js-data-http.js
* @version 1.0.0-alpha.3 - Homepage <http://www.js-data.io/docs/dshttpadapter>
* @version 1.0.0-alpha.4 - Homepage <http://www.js-data.io/docs/dshttpadapter>
* @copyright (c) 2014 Jason Dobry
* @license MIT <https://github.com/js-data/js-data-http/blob/master/LICENSE>
*
Expand Down Expand Up @@ -1398,7 +1398,7 @@ if (!JSData) {
throw new Error('js-data must be loaded!');
}

var makePath = JSData.DSUtils.makePath;
var DSUtils = JSData.DSUtils;
var deepMixIn = JSData.DSUtils.deepMixIn;
var http = require('axios');

Expand Down Expand Up @@ -1443,19 +1443,24 @@ function DSHttpAdapter(options) {

var dsHttpAdapterPrototype = DSHttpAdapter.prototype;

dsHttpAdapterPrototype.getIdPath = function (resourceConfig, options, id) {
return makePath(options.basePath || this.defaults.basePath || resourceConfig.basePath, resourceConfig.getEndpoint(id, options), id);
};

dsHttpAdapterPrototype.getAllPath = function (resourceConfig, options) {
return makePath(options.basePath || this.defaults.basePath || resourceConfig.basePath, resourceConfig.getEndpoint(null, options));
dsHttpAdapterPrototype.getPath = function (method, resourceConfig, id, options) {
var _this = this;
options = options || {};
var args = [
options.basePath || _this.defaults.basePath || resourceConfig.basePath,
resourceConfig.getEndpoint((DSUtils.isString(id) || DSUtils.isNumber(id) || method === 'create') ? id : null, options)
];
if (method === 'find' || method === 'update' || method === 'destroy') {
args.push(id);
}
return DSUtils.makePath.apply(DSUtils, args);
};

dsHttpAdapterPrototype.HTTP = function (config) {
var _this = this;
var start = new Date();
config = deepMixIn(config, _this.defaults.httpConfig);
if (_this.defaults.forceTrailingSlash && config.url[config.url.length] !== '/') {
if (_this.defaults.forceTrailingSlash && config.url[config.url.length - 1] !== '/') {
config.url += '/';
}

Expand Down Expand Up @@ -1523,7 +1528,7 @@ dsHttpAdapterPrototype.find = function (resourceConfig, id, options) {
var _this = this;
options = options || {};
return _this.GET(
_this.getIdPath(resourceConfig, options, id),
_this.getPath('find', resourceConfig, id, options),
options
).then(function (data) {
return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data);
Expand All @@ -1539,7 +1544,7 @@ dsHttpAdapterPrototype.findAll = function (resourceConfig, params, options) {
deepMixIn(options.params, params);
}
return _this.GET(
_this.getAllPath(resourceConfig, options),
_this.getPath('findAll', resourceConfig, params, options),
options
).then(function (data) {
return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data);
Expand All @@ -1550,7 +1555,7 @@ dsHttpAdapterPrototype.create = function (resourceConfig, attrs, options) {
var _this = this;
options = options || {};
return _this.POST(
makePath(options.basePath || this.defaults.basePath || resourceConfig.basePath, resourceConfig.getEndpoint(attrs, options)),
_this.getPath('create', resourceConfig, attrs, options),
options.serialize ? options.serialize(resourceConfig, attrs) : _this.defaults.serialize(resourceConfig, attrs),
options
).then(function (data) {
Expand All @@ -1562,7 +1567,7 @@ dsHttpAdapterPrototype.update = function (resourceConfig, id, attrs, options) {
var _this = this;
options = options || {};
return _this.PUT(
_this.getIdPath(resourceConfig, options, id),
_this.getPath('update', resourceConfig, id, options),
options.serialize ? options.serialize(resourceConfig, attrs) : _this.defaults.serialize(resourceConfig, attrs),
options
).then(function (data) {
Expand All @@ -1579,7 +1584,7 @@ dsHttpAdapterPrototype.updateAll = function (resourceConfig, attrs, params, opti
deepMixIn(options.params, params);
}
return this.PUT(
_this.getAllPath(resourceConfig, options),
_this.getPath('updateAll', resourceConfig, attrs, options),
options.serialize ? options.serialize(resourceConfig, attrs) : _this.defaults.serialize(resourceConfig, attrs),
options
).then(function (data) {
Expand All @@ -1591,7 +1596,7 @@ dsHttpAdapterPrototype.destroy = function (resourceConfig, id, options) {
var _this = this;
options = options || {};
return _this.DEL(
_this.getIdPath(resourceConfig, options, id),
_this.getPath('destroy', resourceConfig, id, options),
options
).then(function (data) {
return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data);
Expand All @@ -1607,7 +1612,7 @@ dsHttpAdapterPrototype.destroyAll = function (resourceConfig, params, options) {
deepMixIn(options.params, params);
}
return this.DEL(
_this.getAllPath(resourceConfig, options),
_this.getPath('destroyAll', resourceConfig, params, options),
options
).then(function (data) {
return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data);
Expand Down
Loading

0 comments on commit b1fb4da

Please sign in to comment.