diff --git a/README b/README new file mode 100644 index 0000000..3efa13d --- /dev/null +++ b/README @@ -0,0 +1,26 @@ +About +===== +This is an dojo interface to Yahoo's [YQL][yql]. It's heavily based on Dav Glass's +[yui-yql][yui-yql]. + +To use it: + + dojo.yql.execute("SELECT * from friendfeed.feeds WHERE nickname = 'slackorama'", + { load: function( data ) { + console.dir( data ); + }, + error: function( e ) { + console.error( e ); + } + }); + + +TODO: +===== + + * Tests! + * Documentation! + * Profit! + +[yql]: http://developer.yahoo.com/yql/ +[yui-yql]: http://github.com/davglass/yui-yql/ diff --git a/dojox/yql.js b/dojox/yql.js new file mode 100644 index 0000000..dde3de0 --- /dev/null +++ b/dojox/yql.js @@ -0,0 +1,2 @@ +dojo.provide("dojox.yql"); +dojo.require("dojox.yql._base"); diff --git a/dojox/yql/_base.js b/dojox/yql/_base.js new file mode 100644 index 0000000..7c2d618 --- /dev/null +++ b/dojox/yql/_base.js @@ -0,0 +1,48 @@ +dojo.provide("dojox.yql._base"); + +dojo.require("dojo.io.script"); + +(function() { + var _d = dojo; + var _dxy = dojox.yql; + var URL = 'http:/' + '/query.yahooapis.com/v1/public/yql'; + _dxy.execute = function( qry, ioArgs ) { + + if (!ioArgs) { + ioArgs = { }; + } + var myArgs = dojo.mixin({},ioArgs ); + if (!myArgs.content) { + myArgs.content = { }; + } + myArgs.url = URL; + myArgs.callbackParamName = "callback"; + myArgs.content.q = qry; + myArgs.content.format = 'json'; + + if (myArgs.env) { + myArgs.content.env = myArgs.env; + } else { + if (!myArgs.content.env) { + myArgs.content.env = 'http:/' + '/datatables.org/alltables.env'; + } + } + + // to look into the data to see if there's an error + myArgs.load = function( data ) { + if (data.error) { + if (ioArgs.error) { + ioArgs.error( new Error( data.error.description ) ); + return; + } + } + if (data.query) { + if (ioArgs.load) { + ioArgs.load( data.query ); + return; + } + } + }; + return dojo.io.script.get( myArgs ); + }; + })();