Skip to content

Instantly share code, notes, and snippets.

@erzr
Created January 8, 2013 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erzr/4480660 to your computer and use it in GitHub Desktop.
Save erzr/4480660 to your computer and use it in GitHub Desktop.
Backbone Collection for YQL
var YqlCollection = Backbone.Collection.extend({
query: '',
url: 'http://query.yahooapis.com/v1/public/yql',
format: 'json',
timeout: 10000,
dataType: 'jsonp',
fetch: function (options) {
options = options ? _.clone(options) : {};
options.data = options.data ? _.clone(options.data) : {};
if (!options.data.q) {
options.data.q = _.result(this, 'query')
}
if (!options.data.format) {
options.data.format = _.result(this, 'format');
}
return Backbone.Collection.prototype.fetch.call(this, options);
},
sync: function(method, model, options){
options.timeout = _.result(this, 'timeout');
options.dataType = _.result(this, 'dataType');
return Backbone.sync(method, model, options);
},
parse: function(response) {
return response.query.results.json.json;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment