mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
Update post to work with new code
This commit is contained in:
parent
68827466ca
commit
096739e225
@ -52,7 +52,7 @@ class Fetch {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareUrl(url, params) {
|
prepareUrl(url, params, attachParamsToQuery) {
|
||||||
let newUrl = this.getUrl(url);
|
let newUrl = this.getUrl(url);
|
||||||
let re = /\${(\w+)}/g;
|
let re = /\${(\w+)}/g;
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ class Fetch {
|
|||||||
return val;
|
return val;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (params && Object.keys(params).length > 0) {
|
if (attachParamsToQuery && params && Object.keys(params).length > 0) {
|
||||||
newUrl += FetchApiUtils.argsToQueryParams(params);
|
newUrl += FetchApiUtils.argsToQueryParams(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,22 +76,24 @@ class Fetch {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
let merged = this._merge(this.httpOptions, options);
|
let merged = this._merge(this.httpOptions, options);
|
||||||
merged['method'] = verb;
|
merged['method'] = verb;
|
||||||
|
return _fetch(url, merged)
|
||||||
let promise = _fetch(url, merged);
|
.then(this.unpackResponse)
|
||||||
return promise.then(this.unpackResponse)
|
|
||||||
.then(JSON.parse)
|
.then(JSON.parse)
|
||||||
.catch(this.handleFatalError.bind(this))
|
.catch(this.handleFatalError.bind(this))
|
||||||
.then(this.handleAPIError);
|
.then(this.handleAPIError);
|
||||||
}
|
}
|
||||||
|
|
||||||
get(url, params, options) {
|
get(url, params) {
|
||||||
|
let paramsCopy = this._merge(params);
|
||||||
let newUrl = this.prepareUrl(url, params);
|
let newUrl = this.prepareUrl(url, params);
|
||||||
return this.request('get', newUrl, options);
|
return this.request('get', newUrl, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
post(url, params, options) {
|
post(url, params) {
|
||||||
options = options || {};
|
let paramsCopy = this._merge(params);
|
||||||
return this.request('post', url, options);
|
let newUrl = this.prepareUrl(url, params);
|
||||||
|
let body = JSON.stringify(params);
|
||||||
|
return this.request('post', url, { body });
|
||||||
}
|
}
|
||||||
|
|
||||||
defaults(options) {
|
defaults(options) {
|
||||||
|
Loading…
Reference in New Issue
Block a user