Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created April 7, 2012 08:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/2326582 to your computer and use it in GitHub Desktop.
Save thinkphp/2326582 to your computer and use it in GitHub Desktop.
MooTools-YQL Plugin
Request.YQL = new Class({
Extends: Request.JSONP,
_endpoint: 'http://query.yahooapis.com/v1/public/yql',
_formats: ['json','xml'],
initialize: function(query, options, vars) {
if(typeof vars == 'object') {
query = this._prepareParams(query,vars)
}
var data = options.data || {}
data.format = this._formats.contains(options.format) ? options.format : 'json'
data.q = query
data.env = 'store://datatables.org/alltableswithkeys'
options.data = data
options.url = this._endpoint
this.parent(options)
},
_prepareParams: function(query, params) {
Object.each(params, function(value, key){
var name = "#{"+ key +"}",
value = value.trim()
if(!value.match(/^[0-9]+$/)) {
value = '"'+ value + '"'
}
if(query.contains(name)) {
query = query.replace(name,value)
}
var name = "@"+ key
if(query.contains(name)) {
query = query.replace(name,value)
}
});
return query;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment