From 096739e225b7077d86b29bb9fa2b909e0497ae5b Mon Sep 17 00:00:00 2001 From: vrde Date: Mon, 1 Jun 2015 16:45:09 +0200 Subject: [PATCH] Update post to work with new code --- js/utils/fetch.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/js/utils/fetch.js b/js/utils/fetch.js index 7ebf3d1c..50808e91 100644 --- a/js/utils/fetch.js +++ b/js/utils/fetch.js @@ -52,7 +52,7 @@ class Fetch { return url; } - prepareUrl(url, params) { + prepareUrl(url, params, attachParamsToQuery) { let newUrl = this.getUrl(url); let re = /\${(\w+)}/g; @@ -65,7 +65,7 @@ class Fetch { return val; }); - if (params && Object.keys(params).length > 0) { + if (attachParamsToQuery && params && Object.keys(params).length > 0) { newUrl += FetchApiUtils.argsToQueryParams(params); } @@ -76,22 +76,24 @@ class Fetch { options = options || {}; let merged = this._merge(this.httpOptions, options); merged['method'] = verb; - - let promise = _fetch(url, merged); - return promise.then(this.unpackResponse) - .then(JSON.parse) - .catch(this.handleFatalError.bind(this)) - .then(this.handleAPIError); + return _fetch(url, merged) + .then(this.unpackResponse) + .then(JSON.parse) + .catch(this.handleFatalError.bind(this)) + .then(this.handleAPIError); } - get(url, params, options) { + get(url, params) { + let paramsCopy = this._merge(params); let newUrl = this.prepareUrl(url, params); - return this.request('get', newUrl, options); + return this.request('get', newUrl, true); } - post(url, params, options) { - options = options || {}; - return this.request('post', url, options); + post(url, params) { + let paramsCopy = this._merge(params); + let newUrl = this.prepareUrl(url, params); + let body = JSON.stringify(params); + return this.request('post', url, { body }); } defaults(options) {