Skip to content

Commit

Permalink
Merge pull request #2898 from amiel/requestType-to-buildURL
Browse files Browse the repository at this point in the history
Pass requestType to buildURL
  • Loading branch information
bmac committed Mar 25, 2015
2 parents 9c26d02 + ff35ee7 commit e8ceeeb
Show file tree
Hide file tree
Showing 5 changed files with 498 additions and 256 deletions.
5 changes: 3 additions & 2 deletions packages/ember-data/lib/adapters/build-url-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var get = Ember.get;
```javascript
export default DS.Adapter.extend(BuildURLMixin, {
find: function(store, type, id, snapshot) {
var url = this.buildURL(type.typeKey, id, snapshot);
var url = this.buildURL(type.typeKey, id, snapshot, 'find');
return this.ajax(url, 'GET');
}
});
Expand Down Expand Up @@ -45,9 +45,10 @@ export default Ember.Mixin.create({
@param {String} type
@param {String|Array} id single id or array of ids
@param {DS.Snapshot|Array} snapshot single snapshot or array of snapshots
@param {String} requestType
@return {String} url
*/
buildURL: function(type, id, snapshot) {
buildURL: function(type, id, snapshot, requestType) {
var url = [];
var host = get(this, 'host');
var prefix = this.urlPrefix();
Expand Down
31 changes: 21 additions & 10 deletions packages/ember-data/lib/adapters/rest-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export default Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
find: function(store, type, id, snapshot) {
return this.ajax(this.buildURL(type.typeKey, id, snapshot), 'GET');
return this.ajax(this.buildURL(type.typeKey, id, snapshot, 'find'), 'GET');
},

/**
Expand All @@ -362,13 +362,15 @@ export default Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
findAll: function(store, type, sinceToken) {
var query;
var query, url;

if (sinceToken) {
query = { since: sinceToken };
}

return this.ajax(this.buildURL(type.typeKey), 'GET', { data: query });
url = this.buildURL(type.typeKey, null, null, 'findAll');

return this.ajax(url, 'GET', { data: query });
},

/**
Expand All @@ -389,10 +391,13 @@ export default Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
findQuery: function(store, type, query) {
var url = this.buildURL(type.typeKey, null, null, 'findQuery');

if (this.sortQueryParams) {
query = this.sortQueryParams(query);
}
return this.ajax(this.buildURL(type.typeKey), 'GET', { data: query });

return this.ajax(url, 'GET', { data: query });
},

/**
Expand Down Expand Up @@ -429,7 +434,8 @@ export default Adapter.extend(BuildURLMixin, {
@return {Promise} promise
*/
findMany: function(store, type, ids, snapshots) {
return this.ajax(this.buildURL(type.typeKey, ids, snapshots), 'GET', { data: { ids: ids } });
var url = this.buildURL(type.typeKey, ids, snapshots, 'findMany');
return this.ajax(url, 'GET', { data: { ids: ids } });
},

/**
Expand Down Expand Up @@ -470,7 +476,9 @@ export default Adapter.extend(BuildURLMixin, {
url = host + url;
}

return this.ajax(this.urlPrefix(url, this.buildURL(type, id)), 'GET');
url = this.urlPrefix(url, this.buildURL(type, id, null, 'findHasMany'));

return this.ajax(url, 'GET');
},

/**
Expand Down Expand Up @@ -504,7 +512,8 @@ export default Adapter.extend(BuildURLMixin, {
var id = snapshot.id;
var type = snapshot.typeKey;

return this.ajax(this.urlPrefix(url, this.buildURL(type, id)), 'GET');
url = this.urlPrefix(url, this.buildURL(type, id, null, 'findBelongsTo'));
return this.ajax(url, 'GET');
},

/**
Expand All @@ -526,10 +535,11 @@ export default Adapter.extend(BuildURLMixin, {
createRecord: function(store, type, snapshot) {
var data = {};
var serializer = store.serializerFor(type.typeKey);
var url = this.buildURL(type.typeKey, null, snapshot, 'createRecord');

serializer.serializeIntoHash(data, type, snapshot, { includeId: true });

return this.ajax(this.buildURL(type.typeKey, null, snapshot), "POST", { data: data });
return this.ajax(url, "POST", { data: data });
},

/**
Expand All @@ -555,8 +565,9 @@ export default Adapter.extend(BuildURLMixin, {
serializer.serializeIntoHash(data, type, snapshot);

var id = snapshot.id;
var url = this.buildURL(type.typeKey, id, snapshot, 'updateRecord');

return this.ajax(this.buildURL(type.typeKey, id, snapshot), "PUT", { data: data });
return this.ajax(url, "PUT", { data: data });
},

/**
Expand All @@ -573,7 +584,7 @@ export default Adapter.extend(BuildURLMixin, {
deleteRecord: function(store, type, snapshot) {
var id = snapshot.id;

return this.ajax(this.buildURL(type.typeKey, id, snapshot), "DELETE");
return this.ajax(this.buildURL(type.typeKey, id, snapshot, 'deleteRecord'), "DELETE");
},

_stripIDFromURL: function(store, snapshot) {
Expand Down
Loading

0 comments on commit e8ceeeb

Please sign in to comment.