yql.js revision e185b559bf5512df7169f7901db9b2ec3771260b
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippYUI.add('yql', function(Y) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/).
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @module yql
828c58761d90445b8b9d20a82d85dc1479317f71Tripp */
828c58761d90445b8b9d20a82d85dc1479317f71Tripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Utility Class used under the hood my the YQL class
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @class YQLRequest
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @constructor
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @param {String} sql The SQL statement to execute
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Function/Object} callback The callback to execute after the query (Falls through to JSONP).
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Object} params An object literal of extra parameters to pass along (optional).
e7c7565d9550eaa87043aef0df77125ada996deaTripp * @param {Object} params An object literal of configuration options (optional): proto (http|https), base (url)
e7c7565d9550eaa87043aef0df77125ada996deaTripp */
e7c7565d9550eaa87043aef0df77125ada996deaTripp var YQLRequest = function (sql, callback, params, opts) {
e7c7565d9550eaa87043aef0df77125ada996deaTripp var qs = '', url = ((opts && opts.proto) ? opts.proto : Y.YQLRequest.PROTO);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (!params) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp params = {};
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp params.q = sql;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp params.format = 'json';
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (!params.env) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp params.env = Y.YQLRequest.ENV;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp Y.each(params, function(v, k) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp qs += k + '=' + encodeURIComponent(v) + '&';
828c58761d90445b8b9d20a82d85dc1479317f71Tripp });
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp url += ((opts && opts.base) ? opts.base : Y.YQLRequest.BASE_URL) + qs;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp Y.jsonp(url, callback);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp };
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp /**
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @static
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @property PROTO
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @description Default protocol to use: http
828c58761d90445b8b9d20a82d85dc1479317f71Tripp */
828c58761d90445b8b9d20a82d85dc1479317f71Tripp YQLRequest.PROTO = 'http';
828c58761d90445b8b9d20a82d85dc1479317f71Tripp /**
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @static
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @property BASE_URL
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @description The base URL to query: query.yahooapis.com/v1/public/yql?
828c58761d90445b8b9d20a82d85dc1479317f71Tripp */
828c58761d90445b8b9d20a82d85dc1479317f71Tripp YQLRequest.BASE_URL = ':/'+'/query.yahooapis.com/v1/public/yql?';
828c58761d90445b8b9d20a82d85dc1479317f71Tripp /**
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @static
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @property ENV
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @description The environment file to load: http://datatables.org/alltables.env
828c58761d90445b8b9d20a82d85dc1479317f71Tripp */
828c58761d90445b8b9d20a82d85dc1479317f71Tripp YQLRequest.ENV = 'http:/'+'/datatables.org/alltables.env';
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp Y.YQLRequest = YQLRequest;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp /**
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/).
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @class YQL
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @constructor
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @param {String} sql The SQL statement to execute
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @param {Function} callback The callback to execute after the query (optional).
828c58761d90445b8b9d20a82d85dc1479317f71Tripp * @param {Object} params An object literal of extra parameters to pass along (optional).
828c58761d90445b8b9d20a82d85dc1479317f71Tripp */
828c58761d90445b8b9d20a82d85dc1479317f71Tripp Y.YQL = function(sql, callback, params) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp return new Y.YQLRequest(sql, callback, params);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp };
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp}, '@@VERSION@@');
828c58761d90445b8b9d20a82d85dc1479317f71Tripp