2014-05-09 09:00:10 +04:00
|
|
|
import ghostPaths from 'ghost/utils/ghost-paths';
|
|
|
|
|
2014-06-09 15:02:51 +04:00
|
|
|
var ApplicationAdapter = DS.RESTAdapter.extend({
|
2014-05-09 09:00:10 +04:00
|
|
|
host: window.location.origin,
|
|
|
|
namespace: ghostPaths().apiRoot.slice(1),
|
|
|
|
|
2014-06-17 23:17:08 +04:00
|
|
|
findQuery: function (store, type, query) {
|
|
|
|
var id;
|
|
|
|
|
|
|
|
if (query.id) {
|
|
|
|
id = query.id;
|
|
|
|
delete query.id;
|
|
|
|
}
|
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
return this.ajax(this.buildURL(type.typeKey, id), 'GET', {data: query});
|
2014-06-17 23:17:08 +04:00
|
|
|
},
|
|
|
|
|
2014-05-09 09:00:10 +04:00
|
|
|
buildURL: function (type, id) {
|
|
|
|
// Ensure trailing slashes
|
|
|
|
var url = this._super(type, id);
|
|
|
|
|
|
|
|
if (url.slice(-1) !== '/') {
|
|
|
|
url += '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
2014-06-04 01:10:54 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// Override deleteRecord to disregard the response body on 2xx responses.
|
|
|
|
// This is currently needed because the API is returning status 200 along
|
|
|
|
// with the JSON object for the deleted entity and Ember expects an empty
|
|
|
|
// response body for successful DELETEs.
|
|
|
|
// Non-2xx (failure) responses will still work correctly as Ember will turn
|
|
|
|
// them into rejected promises.
|
|
|
|
deleteRecord: function () {
|
|
|
|
var response = this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
return response.then(function () {
|
|
|
|
return null;
|
|
|
|
});
|
2014-05-09 09:00:10 +04:00
|
|
|
}
|
2014-06-09 15:02:51 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default ApplicationAdapter;
|