-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,311 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
@module ember-data | ||
*/ | ||
|
||
import RESTAdapter from "ember-data/adapters/rest-adapter"; | ||
|
||
/** | ||
@class JSONAPIAdapter | ||
@constructor | ||
@namespace DS | ||
@extends DS.RESTAdapter | ||
*/ | ||
export default RESTAdapter.extend({ | ||
defaultSerializer: '-json-api', | ||
|
||
/** | ||
@method ajaxOptions | ||
@private | ||
@param {String} url | ||
@param {String} type The request type GET, POST, PUT, DELETE etc. | ||
@param {Object} options | ||
@return {Object} | ||
*/ | ||
ajaxOptions: function(url, type, options) { | ||
let hash = this._super(...arguments); | ||
|
||
if (hash.contentType) { | ||
hash.contentType = 'application/vnd.api+json'; | ||
} | ||
|
||
let beforeSend = hash.beforeSend; | ||
hash.beforeSend = function(xhr) { | ||
xhr.setRequestHeader('Accept', 'application/vnd.api+json'); | ||
if (beforeSend) { | ||
beforeSend(xhr); | ||
} | ||
}; | ||
|
||
return hash; | ||
}, | ||
|
||
/** | ||
@method findMany | ||
@param {DS.Store} store | ||
@param {DS.Model} type | ||
@param {Array} ids | ||
@param {Array} snapshots | ||
@return {Promise} promise | ||
*/ | ||
findMany: function(store, type, ids, snapshots) { | ||
var url = this.buildURL(type.modelName, ids, snapshots, 'findMany'); | ||
return this.ajax(url, 'GET', { data: { filter: { id: ids.join(',') } } }); | ||
}, | ||
|
||
/** | ||
@method pathForType | ||
@param {String} modelName | ||
@return {String} path | ||
**/ | ||
pathForType: function(modelName) { | ||
var dasherized = Ember.String.dasherize(modelName); | ||
return Ember.String.pluralize(dasherized); | ||
}, | ||
|
||
/** | ||
TODO: Remove this once we have a better way to override HTTP verbs. | ||
@method updateRecord | ||
@param {DS.Store} store | ||
@param {DS.Model} type | ||
@param {DS.Snapshot} snapshot | ||
@return {Promise} promise | ||
*/ | ||
updateRecord: function(store, type, snapshot) { | ||
var data = {}; | ||
var serializer = store.serializerFor(type.modelName); | ||
|
||
serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); | ||
|
||
var id = snapshot.id; | ||
var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord'); | ||
|
||
return this.ajax(url, 'PATCH', { data: data }); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
/** | ||
@module ember-data | ||
*/ | ||
|
||
import JSONAPISerializer from "ember-data/serializers/json-api-serializer"; | ||
import JSONSerializer from "ember-data/serializers/json-serializer"; | ||
import RESTSerializer from "ember-data/serializers/rest-serializer"; | ||
|
||
export { | ||
JSONAPISerializer, | ||
JSONSerializer, | ||
RESTSerializer | ||
}; |
Oops, something went wrong.