Skip to content

Commit b1fb4da

Browse files
committed
Stable Version 1.0.0-alpha.4.
1 parent fa6c996 commit b1fb4da

6 files changed

+52
-34
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
##### 1.0.0-alpha.4 - 01 December 2014
2+
3+
###### Backwards compatible API changes
4+
- Added DSHttpAdapter.getPath
5+
6+
###### Backwards compatible bug fixes
7+
- #8 - Fixed handling of `forceTrailingSlash` option
8+
19
##### 1.0.0-alpha.3 - 19 November 2014
210

311
###### Breaking API changes

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "js-data-http",
33
"description": "http adapter for js-data.",
4-
"version": "1.0.0-alpha.3",
4+
"version": "1.0.0-alpha.4",
55
"homepage": "http://www.js-data.io/docs/dshttpadapter",
66
"repository": {
77
"type": "git",

dist/js-data-http.js

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @author Jason Dobry <[email protected]>
33
* @file js-data-http.js
4-
* @version 1.0.0-alpha.3 - Homepage <http://www.js-data.io/docs/dshttpadapter>
4+
* @version 1.0.0-alpha.4 - Homepage <http://www.js-data.io/docs/dshttpadapter>
55
* @copyright (c) 2014 Jason Dobry
66
* @license MIT <https://github.com/js-data/js-data-http/blob/master/LICENSE>
77
*
@@ -1398,7 +1398,7 @@ if (!JSData) {
13981398
throw new Error('js-data must be loaded!');
13991399
}
14001400

1401-
var makePath = JSData.DSUtils.makePath;
1401+
var DSUtils = JSData.DSUtils;
14021402
var deepMixIn = JSData.DSUtils.deepMixIn;
14031403
var http = require('axios');
14041404

@@ -1443,19 +1443,24 @@ function DSHttpAdapter(options) {
14431443

14441444
var dsHttpAdapterPrototype = DSHttpAdapter.prototype;
14451445

1446-
dsHttpAdapterPrototype.getIdPath = function (resourceConfig, options, id) {
1447-
return makePath(options.basePath || this.defaults.basePath || resourceConfig.basePath, resourceConfig.getEndpoint(id, options), id);
1448-
};
1449-
1450-
dsHttpAdapterPrototype.getAllPath = function (resourceConfig, options) {
1451-
return makePath(options.basePath || this.defaults.basePath || resourceConfig.basePath, resourceConfig.getEndpoint(null, options));
1446+
dsHttpAdapterPrototype.getPath = function (method, resourceConfig, id, options) {
1447+
var _this = this;
1448+
options = options || {};
1449+
var args = [
1450+
options.basePath || _this.defaults.basePath || resourceConfig.basePath,
1451+
resourceConfig.getEndpoint((DSUtils.isString(id) || DSUtils.isNumber(id) || method === 'create') ? id : null, options)
1452+
];
1453+
if (method === 'find' || method === 'update' || method === 'destroy') {
1454+
args.push(id);
1455+
}
1456+
return DSUtils.makePath.apply(DSUtils, args);
14521457
};
14531458

14541459
dsHttpAdapterPrototype.HTTP = function (config) {
14551460
var _this = this;
14561461
var start = new Date();
14571462
config = deepMixIn(config, _this.defaults.httpConfig);
1458-
if (_this.defaults.forceTrailingSlash && config.url[config.url.length] !== '/') {
1463+
if (_this.defaults.forceTrailingSlash && config.url[config.url.length - 1] !== '/') {
14591464
config.url += '/';
14601465
}
14611466

@@ -1523,7 +1528,7 @@ dsHttpAdapterPrototype.find = function (resourceConfig, id, options) {
15231528
var _this = this;
15241529
options = options || {};
15251530
return _this.GET(
1526-
_this.getIdPath(resourceConfig, options, id),
1531+
_this.getPath('find', resourceConfig, id, options),
15271532
options
15281533
).then(function (data) {
15291534
return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data);
@@ -1539,7 +1544,7 @@ dsHttpAdapterPrototype.findAll = function (resourceConfig, params, options) {
15391544
deepMixIn(options.params, params);
15401545
}
15411546
return _this.GET(
1542-
_this.getAllPath(resourceConfig, options),
1547+
_this.getPath('findAll', resourceConfig, params, options),
15431548
options
15441549
).then(function (data) {
15451550
return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data);
@@ -1550,7 +1555,7 @@ dsHttpAdapterPrototype.create = function (resourceConfig, attrs, options) {
15501555
var _this = this;
15511556
options = options || {};
15521557
return _this.POST(
1553-
makePath(options.basePath || this.defaults.basePath || resourceConfig.basePath, resourceConfig.getEndpoint(attrs, options)),
1558+
_this.getPath('create', resourceConfig, attrs, options),
15541559
options.serialize ? options.serialize(resourceConfig, attrs) : _this.defaults.serialize(resourceConfig, attrs),
15551560
options
15561561
).then(function (data) {
@@ -1562,7 +1567,7 @@ dsHttpAdapterPrototype.update = function (resourceConfig, id, attrs, options) {
15621567
var _this = this;
15631568
options = options || {};
15641569
return _this.PUT(
1565-
_this.getIdPath(resourceConfig, options, id),
1570+
_this.getPath('update', resourceConfig, id, options),
15661571
options.serialize ? options.serialize(resourceConfig, attrs) : _this.defaults.serialize(resourceConfig, attrs),
15671572
options
15681573
).then(function (data) {
@@ -1579,7 +1584,7 @@ dsHttpAdapterPrototype.updateAll = function (resourceConfig, attrs, params, opti
15791584
deepMixIn(options.params, params);
15801585
}
15811586
return this.PUT(
1582-
_this.getAllPath(resourceConfig, options),
1587+
_this.getPath('updateAll', resourceConfig, attrs, options),
15831588
options.serialize ? options.serialize(resourceConfig, attrs) : _this.defaults.serialize(resourceConfig, attrs),
15841589
options
15851590
).then(function (data) {
@@ -1591,7 +1596,7 @@ dsHttpAdapterPrototype.destroy = function (resourceConfig, id, options) {
15911596
var _this = this;
15921597
options = options || {};
15931598
return _this.DEL(
1594-
_this.getIdPath(resourceConfig, options, id),
1599+
_this.getPath('destroy', resourceConfig, id, options),
15951600
options
15961601
).then(function (data) {
15971602
return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data);
@@ -1607,7 +1612,7 @@ dsHttpAdapterPrototype.destroyAll = function (resourceConfig, params, options) {
16071612
deepMixIn(options.params, params);
16081613
}
16091614
return this.DEL(
1610-
_this.getAllPath(resourceConfig, options),
1615+
_this.getPath('destroyAll', resourceConfig, params, options),
16111616
options
16121617
).then(function (data) {
16131618
return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data);

0 commit comments

Comments
 (0)