Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Build and upgrade version
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinBressan committed Jan 29, 2016
1 parent bd6b47e commit 2a11828
Show file tree
Hide file tree
Showing 9 changed files with 4,767 additions and 4,412 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "restful.js",
"version": "0.9.3",
"version": "0.9.4",
"homepage": "https://github.com/marmelab/restful.js",
"authors": [
"Robin Bressan <[email protected]>"
Expand Down
51 changes: 47 additions & 4 deletions dist/es5/http/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ var _qs = require('qs');

var _qs2 = _interopRequireDefault(_qs);

var _warning = require('warning');

var _warning2 = _interopRequireDefault(_warning);

function parseBody(response) {
return response.text().then(function (text) {
if (!text || !text.length) {
(0, _warning2['default'])(response.status === 204, 'You should return a 204 status code with an empty body.');
return null;
}

(0, _warning2['default'])(response.status !== 204, 'You should return an empty body with a 204 status code.');

try {
return JSON.parse(text);
} catch (error) {
return text;
}
});
}

exports['default'] = function (fetch) {
return function (config) {
var url = config.url;
Expand All @@ -24,16 +45,38 @@ exports['default'] = function (fetch) {
delete config.params;

return fetch(!queryString.length ? url : url + '?' + queryString, config).then(function (response) {
return (response.status === 204 ? Promise.resolve(null) : response.json()).then(function (json) {
return parseBody(response).then(function (json) {
var headers = {};
var keys = response.headers.keys();
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

response.headers.forEach(function (value, name) {
headers[name] = value;
});
try {
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var key = _step.value;

headers[key] = response.headers.get(key);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

var responsePayload = {
data: json,
headers: headers,
method: config.method ? config.method.toLowerCase() : 'get',
statusCode: response.status
};

Expand Down
3 changes: 0 additions & 3 deletions dist/es5/model/decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ function collection(endpoint) {
getAll: endpoint.get,
get: _bindHttpMethod('get'),
head: _bindHttpMethod('head'),
one: function one(name, id) {
return member(endpoint['new'](endpoint.url() + '/' + name + '/' + id));
}, // eslint-disable-line no-use-before-define
patch: _bindHttpMethod('patch'),
put: _bindHttpMethod('put')
});
Expand Down
12 changes: 6 additions & 6 deletions dist/es5/model/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ var _utilSerialize = require('../util/serialize');

var _utilSerialize2 = _interopRequireDefault(_utilSerialize);

var _warning = require('warning');

var _warning2 = _interopRequireDefault(_warning);

/* eslint-disable new-cap */

exports['default'] = function (response, decoratedEndpoint) {
Expand All @@ -35,19 +39,15 @@ exports['default'] = function (response, decoratedEndpoint) {
}

if (_immutable.List.isList(data)) {
if (decoratedEndpoint.all) {
throw new Error('Unexpected array as response, you should use all method for that');
}
(0, _warning2['default'])(response.get('method') !== 'get' || !decoratedEndpoint.all, 'Unexpected array as response, you should use all method for that');

return (0, _utilSerialize2['default'])(data.map(function (datum) {
var id = datum.get(identifier);
return (0, _entity2['default'])((0, _utilSerialize2['default'])(datum), decoratedEndpoint.custom('' + id));
}));
}

if (!decoratedEndpoint.all) {
throw new Error('Expected array as response, you should use one method for that');
}
(0, _warning2['default'])(response.get('method') !== 'get' || decoratedEndpoint.all, 'Expected array as response, you should use one method for that');

return (0, _entity2['default'])((0, _utilSerialize2['default'])(data), decoratedEndpoint);
},
Expand Down
Loading

0 comments on commit 2a11828

Please sign in to comment.