Skip to content

Commit 4c4427f

Browse files
committed
Closes #20. Closes #26. Fixes #21. Fixes #22.
1 parent ffcb73d commit 4c4427f

File tree

5 files changed

+95
-56
lines changed

5 files changed

+95
-56
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
##### 2.1.0 - xx September 2015
2+
3+
###### Backwards compatible API changes
4+
- #20 - DSHttpAdapter.POST does not pick DSHttpAdapter.defaults.basePath
5+
- #26 - Add support for full url override
6+
7+
###### Backwards compatible bug fixes
8+
- #21 - Cannot read property 'method' of undefined
9+
- #22 - Fixing issue where logging responses cannot handle Error objects. PR by @RobertHerhold
10+
111
##### 2.0.0 - 02 July 2015
212

313
Stable Version 2.0.0

CONTRIBUTING.md

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
# Contributing Guide
22

3-
First, feel free to contact me with questions. [Mailing List](https://groups.io/org/groupsio/jsdata). [Issues](https://github.com/js-data/js-data-http/issues).
3+
First, support is handled via the [Gitter Channel](https://gitter.im/js-data/js-data) and the [Mailing List](https://groups.io/org/groupsio/jsdata). Ask your questions there.
44

5-
1. Contribute to the issue that is the reason you'll be developing in the first place
5+
When submitting issues on GitHub, please include as much detail as possible to make debugging quick and easy.
6+
7+
- good - Your versions of js-data, js-data-http, etc., relevant console logs/error, code examples that revealed the issue
8+
- better - A [plnkr](http://plnkr.co/), [fiddle](http://jsfiddle.net/), or [bin](http://jsbin.com/?html,output) that demonstrates the issue
9+
- best - A Pull Request that fixes the issue, including test coverage for the issue and the fix
10+
11+
[Github Issues](https://github.com/js-data/js-data-http/issues).
12+
13+
#### Submitting Pull Requests
14+
15+
1. Contribute to the issue/discussion that is the reason you'll be developing in the first place
616
1. Fork js-data-http
7-
1. `git clone https://github.com/<you>/js-data-http.git`
17+
1. `git clone git@github.com:<you>/js-data-http.git`
818
1. `cd js-data-http; npm install; bower install;`
9-
1. `grunt go` (builds and starts a watch)
10-
1. (in another terminal) `grunt karma:dev` (runs the tests)
1119
1. Write your code, including relevant documentation and tests
12-
1. Submit a PR and we'll review
20+
1. Run `grunt test` (build and test)
21+
1. Your code will be linted and checked for formatting, the tests will be run
22+
1. The `dist/` folder & files will be generated, do NOT commit `dist/*`! They will be committed when a release is cut.
23+
1. Submit your PR and we'll review!
24+
1. Thanks!

README.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ __Latest Release:__ [![Latest Release](https://img.shields.io/github/release/js-
1212

1313
__Status:__
1414

15-
[![Dependency Status](https://img.shields.io/gemnasium/js-data/js-data-http.svg?style=flat-square)](https://gemnasium.com/js-data/js-data-http) [![Coverage Status](https://img.shields.io/coveralls/js-data/js-data-http/master.svg?style=flat-square)](https://coveralls.io/r/js-data/js-data-http?branch=master) [![Codacity](https://img.shields.io/codacy/3931bbd8d838463297f70640aa78251b.svg?style=flat-square)](https://www.codacy.com/public/jasondobry/js-data-http/dashboard)
15+
[![Coverage Status](https://img.shields.io/coveralls/js-data/js-data-http/master.svg?style=flat-square)](https://coveralls.io/r/js-data/js-data-http?branch=master) [![Codacity](https://img.shields.io/codacy/3931bbd8d838463297f70640aa78251b.svg?style=flat-square)](https://www.codacy.com/public/jasondobry/js-data-http/dashboard)
1616

1717
__Supported Platforms:__
1818

@@ -45,16 +45,28 @@ store.registerAdapter('http', adapter, { default: true });
4545

4646
### Contributing
4747

48-
First, feel free to contact me with questions. [Mailing List](https://groups.io/org/groupsio/jsdata). [Issues](https://github.com/js-data/js-data-http/issues).
48+
First, support is handled via the [Gitter Channel](https://gitter.im/js-data/js-data) and the [Mailing List](https://groups.io/org/groupsio/jsdata). Ask your questions there.
4949

50-
1. Contribute to the issue that is the reason you'll be developing in the first place
50+
When submitting issues on GitHub, please include as much detail as possible to make debugging quick and easy.
51+
52+
- good - Your versions of js-data, js-data-http, etc., relevant console logs/error, code examples that revealed the issue
53+
- better - A [plnkr](http://plnkr.co/), [fiddle](http://jsfiddle.net/), or [bin](http://jsbin.com/?html,output) that demonstrates the issue
54+
- best - A Pull Request that fixes the issue, including test coverage for the issue and the fix
55+
56+
[Github Issues](https://github.com/js-data/js-data-http/issues).
57+
58+
#### Submitting Pull Requests
59+
60+
1. Contribute to the issue/discussion that is the reason you'll be developing in the first place
5161
1. Fork js-data-http
52-
1. `git clone https://github.com/<you>/js-data-http.git`
62+
1. `git clone git@github.com:<you>/js-data-http.git`
5363
1. `cd js-data-http; npm install; bower install;`
54-
1. `grunt go` (builds and starts a watch)
55-
1. (in another terminal) `grunt karma:dev` (runs the tests)
5664
1. Write your code, including relevant documentation and tests
57-
1. Submit a PR and we'll review
65+
1. Run `grunt test` (build and test)
66+
1. Your code will be linted and checked for formatting, the tests will be run
67+
1. The `dist/` folder & files will be generated, do NOT commit `dist/*`! They will be committed when a release is cut.
68+
1. Submit your PR and we'll review!
69+
1. Thanks!
5870

5971
### License
6072

package.json

+15-10
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,36 @@
2727
"http"
2828
],
2929
"devDependencies": {
30-
"babel-core": "5.6.15",
31-
"babel-loader": "5.2.2",
32-
"es6-promise": "2.3.0",
30+
"babel-core": "5.8.24",
31+
"babel-eslint": "^4.1.1",
32+
"babel-loader": "5.3.2",
33+
"es6-promise": "3.0.2",
3334
"grunt": "0.4.5",
3435
"grunt-contrib-clean": "0.6.0",
35-
"grunt-contrib-uglify": "0.9.1",
36+
"grunt-contrib-uglify": "0.9.2",
3637
"grunt-contrib-watch": "0.6.1",
37-
"grunt-karma": "0.11.2",
38-
"grunt-karma-coveralls": "2.5.3",
38+
"grunt-karma": "0.12.1",
39+
"grunt-karma-coveralls": "2.5.4",
3940
"grunt-webpack": "1.0.11",
4041
"jit-grunt": "0.9.1",
4142
"jshint-loader": "0.8.3",
42-
"karma": "0.12.37",
43+
"karma": "0.13.9",
4344
"karma-chai": "0.1.0",
4445
"karma-chrome-launcher": "0.2.0",
45-
"karma-coverage": "0.4.2",
46+
"karma-coverage": "0.5.2",
4647
"karma-firefox-launcher": "0.1.6",
4748
"karma-mocha": "0.2.0",
48-
"karma-phantomjs-launcher": "0.2.0",
49+
"karma-phantomjs-launcher": "0.2.1",
4950
"karma-script-launcher": "0.1.0",
5051
"karma-sinon": "1.0.4",
51-
"karma-spec-reporter": "0.0.19",
52+
"karma-spec-reporter": "0.0.20",
53+
"standard": "^5.2.2",
5254
"time-grunt": "1.2.1",
5355
"webpack-dev-server": "1.10.1"
5456
},
57+
"standard": {
58+
"parser": "babel-eslint"
59+
},
5560
"scripts": {
5661
"test": "grunt test"
5762
},

src/index.js

+33-33
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ defaultsPrototype.forceTrailingSlash = '';
3939

4040
defaultsPrototype.httpConfig = {};
4141

42+
defaultsPrototype.verbsUseBasePath = false;
43+
4244
class DSHttpAdapter {
4345
constructor(options) {
4446
this.defaults = new Defaults();
@@ -112,15 +114,21 @@ class DSHttpAdapter {
112114
let start = new Date();
113115
config = copy(config);
114116
config = deepMixIn(config, _this.defaults.httpConfig);
115-
if (_this.defaults.forceTrailingSlash && config.url[config.url.length - 1] !== '/') {
117+
if (!('verbsUseBasePath' in config)) {
118+
config.verbsUseBasePath = _this.defaults.verbsUseBasePath;
119+
}
120+
if (!config.urlOverride && config.verbsUseBasePath) {
121+
config.url = makePath(config.basePath || _this.defaults.basePath, config.url);
122+
}
123+
if (_this.defaults.forceTrailingSlash && config.url[config.url.length - 1] !== '/' && !config.urlOverride) {
116124
config.url += '/';
117125
}
118126
if (typeof config.data === 'object') {
119127
config.data = removeCircular(config.data);
120128
}
121129
config.method = config.method.toUpperCase();
122130
let suffix = config.suffix || _this.defaults.suffix;
123-
if (suffix && config.url.substr(config.url.length - suffix.length) !== suffix) {
131+
if (suffix && config.url.substr(config.url.length - suffix.length) !== suffix && !config.urlOverride) {
124132
config.url += suffix;
125133
}
126134

@@ -129,10 +137,10 @@ class DSHttpAdapter {
129137
// examine the data object
130138
if (data instanceof Error) {
131139
// log the Error object
132-
_this.defaults.error(`'FAILED: ${data.message || 'Unknown Error'}'`, data);
140+
_this.defaults.error(`FAILED: ${data.message || 'Unknown Error'}`, data);
133141
return DSUtils.Promise.reject(data);
134-
} else if (data instanceof Object) {
135-
let str = `${start.toUTCString()} - ${data.config.method.toUpperCase()} ${data.config.url} - ${data.status} ${(new Date().getTime() - start.getTime())}ms`;
142+
} else if (typeof data === 'object') {
143+
let str = `${start.toUTCString()} - ${config.method} ${config.url} - ${data.status} ${(new Date().getTime() - start.getTime())}ms`;
136144

137145
if (data.status >= 200 && data.status < 300) {
138146
if (_this.defaults.log) {
@@ -141,13 +149,13 @@ class DSHttpAdapter {
141149
return data;
142150
} else {
143151
if (_this.defaults.error) {
144-
_this.defaults.error(`'FAILED: ${str}'`, data);
152+
_this.defaults.error(`FAILED: ${str}`, data);
145153
}
146154
return DSUtils.Promise.reject(data);
147155
}
148156
} else {
149157
// unknown type for 'data' that is not an Object or Error
150-
_this.defaults.error(`'FAILED'`, data);
158+
_this.defaults.error(`FAILED`, data);
151159
return DSUtils.Promise.reject(data);
152160
}
153161
}
@@ -161,44 +169,36 @@ class DSHttpAdapter {
161169

162170
GET(url, config) {
163171
config = config || {};
164-
if (!('method' in config)) {
165-
config.method = 'get';
166-
}
167-
return this.HTTP(deepMixIn(config, {
168-
url
169-
}));
172+
config.method = config.method || 'get';
173+
config.urlOverride = !!config.url;
174+
config.url = config.url || url;
175+
return this.HTTP(config);
170176
}
171177

172178
POST(url, attrs, config) {
173179
config = config || {};
174-
if (!('method' in config)) {
175-
config.method = 'post';
176-
}
177-
return this.HTTP(deepMixIn(config, {
178-
url,
179-
data: attrs
180-
}));
180+
config.method = config.method || 'post';
181+
config.urlOverride = !!config.url;
182+
config.url = config.url || url;
183+
config.data = config.data || attrs;
184+
return this.HTTP(config);
181185
}
182186

183187
PUT(url, attrs, config) {
184188
config = config || {};
185-
if (!('method' in config)) {
186-
config.method = 'put';
187-
}
188-
return this.HTTP(deepMixIn(config, {
189-
url,
190-
data: attrs || {}
191-
}));
189+
config.method = config.method || 'put';
190+
config.urlOverride = !!config.url;
191+
config.url = config.url || url;
192+
config.data = config.data || attrs;
193+
return this.HTTP(config);
192194
}
193195

194196
DEL(url, config) {
195197
config = config || {};
196-
if (!('method' in config)) {
197-
config.method = 'delete';
198-
}
199-
return this.HTTP(deepMixIn(config, {
200-
url
201-
}));
198+
config.method = config.method || 'delete';
199+
config.urlOverride = !!config.url;
200+
config.url = config.url || url;
201+
return this.HTTP(config);
202202
}
203203

204204
find(resourceConfig, id, options) {

0 commit comments

Comments
 (0)