Permalink
Browse files

Initial commit of YQL Module

  • Loading branch information...
1 parent e9495df commit 6e6ae6f14d4b503da8cead0bda4a2780190cdec5 @davglass davglass committed Oct 15, 2009
Showing with 586 additions and 0 deletions.
  1. +133 −0 build/yql/yql-debug.js
  2. +1 −0 build/yql/yql-min.js
  3. +133 −0 build/yql/yql.js
  4. +30 −0 sandbox/davglass/yql/LICENSE
  5. +129 −0 sandbox/davglass/yql/yql.js
  6. +25 −0 src/yql/build.properties
  7. +7 −0 src/yql/build.xml
  8. +128 −0 src/yql/js/yql.js
View
@@ -0,0 +1,133 @@
+YUI.add('yql', function(Y) {
+
+ //Global storage for the callbacks
+ if (!YUI.yql) {
+ YUI.yql = {};
+ }
+ /**
+ * This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/).
+ * @module yql
+ */
+ /**
+ * This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/).
+ * @class yql
+ * @extends Event.Target
+ * @constructor
+ * @param {String} sql The SQL statement to execute
+ * @param {Function} callback The callback to execute after the query (optional).
+ * @param {Object} params An object literal of extra parameters to pass along (optional).
+ * @param {Object} opts An object literal of extra options to pass along to the Get Utility (optional).
+ */
+ var BASE_URL = 'http:/'+'/query.yahooapis.com/v1/public/yql?',
+ yql = function (sql, callback, params, opts) {
+ yql.superclass.constructor.apply(this);
+ this._query(sql, callback, params, opts);
+ };
+
+ Y.extend(yql, Y.EventTarget, {
+ /**
+ * @private
+ * @property _cb
+ * @description The callback method
+ */
+ _cb: null,
+ /**
+ * @private
+ * @property _stamp
+ * @description The method name on the Global YUI object we use as the callback.
+ */
+ _stamp: null,
+ /**
+ * @private
+ * @method _receiver
+ * @description The global callback that get's called from Get.
+ * @param {Object} q The JSON object from YQL.
+ */
+ _receiver: function(q) {
+ if (q.query) {
+ this.fire('query', q.query);
+ }
+ if (q.error) {
+ this.fire('error', q.error);
+ }
+ if (this._cb) {
+ this._cb(q);
+ }
+ delete YUI.yql[this._stamp];
+ },
+ /**
+ * @private
+ * @method _query
+ * @description Builds the query and fire the Get call.
+ * @param {String} sql The SQL statement to execute
+ * @param {Function} callback The callback to execute after the query (optional).
+ * @param {Object} params An object literal of extra parameters to pass along (optional).
+ * @param {Object} opts An object literal of extra options to pass along to the Get Utility (optional).
+ * @return Self
+ */
+ _query: function(sql, callback, params, opts) {
+ var st = Y.stamp({}), qs = '', url;
+ //Must replace the dashes with underscrores
+ st = st.replace(/-/g, '_');
+
+ this._stamp = st;
+
+ this._cb = callback;
+
+ YUI.yql[st] = Y.bind(this._receiver, this);
+
+ if (!params) {
+ params = {};
+ }
+ params.q = sql;
+ params.format = 'json';
+ params.callback = "YUI.yql." + st;
+ if (!params.env) {
+ params.env = 'http:/'+'/datatables.org/alltables.env';
+ }
+
+ Y.each(params, function(v, k) {
+ qs += k + '=' + encodeURIComponent(v) + '&';
+ });
+
+ if (!opts) {
+ opts = {};
+ }
+ opts.autopurge = true;
+ opts.context = this;
+ opts.onTimeout = function(o){
+ this.fire('timeout', o);
+ if (this._cb) {
+ this._cb(o);
+ this._cb = null;
+ }
+ };
+
+ url = BASE_URL + qs;
+ Y.Get.script(url, opts);
+ return this;
+ }
+ });
+ /**
+ * @event query
+ * @description Fires when the Query returns.
+ * @type {Event.Custom}
+ */
+
+ /**
+ * @event error
+ * @description Fires when an error occurs.
+ * @type {Event.Custom}
+ */
+
+ /**
+ * @event timeout
+ * @description Fires when the request has timed-out.
+ * @type {Event.Custom}
+ */
+
+ Y.yql = yql;
+
+
+
+}, '@VERSION@' ,{requires:['get', 'event-custom'], supersedes:['get', 'event-custom']});
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,133 @@
+YUI.add('yql', function(Y) {
+
+ //Global storage for the callbacks
+ if (!YUI.yql) {
+ YUI.yql = {};
+ }
+ /**
+ * This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/).
+ * @module yql
+ */
+ /**
+ * This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/).
+ * @class yql
+ * @extends Event.Target
+ * @constructor
+ * @param {String} sql The SQL statement to execute
+ * @param {Function} callback The callback to execute after the query (optional).
+ * @param {Object} params An object literal of extra parameters to pass along (optional).
+ * @param {Object} opts An object literal of extra options to pass along to the Get Utility (optional).
+ */
+ var BASE_URL = 'http:/'+'/query.yahooapis.com/v1/public/yql?',
+ yql = function (sql, callback, params, opts) {
+ yql.superclass.constructor.apply(this);
+ this._query(sql, callback, params, opts);
+ };
+
+ Y.extend(yql, Y.EventTarget, {
+ /**
+ * @private
+ * @property _cb
+ * @description The callback method
+ */
+ _cb: null,
+ /**
+ * @private
+ * @property _stamp
+ * @description The method name on the Global YUI object we use as the callback.
+ */
+ _stamp: null,
+ /**
+ * @private
+ * @method _receiver
+ * @description The global callback that get's called from Get.
+ * @param {Object} q The JSON object from YQL.
+ */
+ _receiver: function(q) {
+ if (q.query) {
+ this.fire('query', q.query);
+ }
+ if (q.error) {
+ this.fire('error', q.error);
+ }
+ if (this._cb) {
+ this._cb(q);
+ }
+ delete YUI.yql[this._stamp];
+ },
+ /**
+ * @private
+ * @method _query
+ * @description Builds the query and fire the Get call.
+ * @param {String} sql The SQL statement to execute
+ * @param {Function} callback The callback to execute after the query (optional).
+ * @param {Object} params An object literal of extra parameters to pass along (optional).
+ * @param {Object} opts An object literal of extra options to pass along to the Get Utility (optional).
+ * @return Self
+ */
+ _query: function(sql, callback, params, opts) {
+ var st = Y.stamp({}), qs = '', url;
+ //Must replace the dashes with underscrores
+ st = st.replace(/-/g, '_');
+
+ this._stamp = st;
+
+ this._cb = callback;
+
+ YUI.yql[st] = Y.bind(this._receiver, this);
+
+ if (!params) {
+ params = {};
+ }
+ params.q = sql;
+ params.format = 'json';
+ params.callback = "YUI.yql." + st;
+ if (!params.env) {
+ params.env = 'http:/'+'/datatables.org/alltables.env';
+ }
+
+ Y.each(params, function(v, k) {
+ qs += k + '=' + encodeURIComponent(v) + '&';
+ });
+
+ if (!opts) {
+ opts = {};
+ }
+ opts.autopurge = true;
+ opts.context = this;
+ opts.onTimeout = function(o){
+ this.fire('timeout', o);
+ if (this._cb) {
+ this._cb(o);
+ this._cb = null;
+ }
+ };
+
+ url = BASE_URL + qs;
+ Y.Get.script(url, opts);
+ return this;
+ }
+ });
+ /**
+ * @event query
+ * @description Fires when the Query returns.
+ * @type {Event.Custom}
+ */
+
+ /**
+ * @event error
+ * @description Fires when an error occurs.
+ * @type {Event.Custom}
+ */
+
+ /**
+ * @event timeout
+ * @description Fires when the request has timed-out.
+ * @type {Event.Custom}
+ */
+
+ Y.yql = yql;
+
+
+
+}, '@VERSION@' ,{requires:['get', 'event-custom'], supersedes:['get', 'event-custom']});
@@ -0,0 +1,30 @@
+Software License Agreement (BSD License)
+
+Copyright (c) 2007, Dav Glass <dav.glass@yahoo.com>.
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms, with or without modification, are
+permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+* The name of Dav Glass may not be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of Dav Glass.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
Oops, something went wrong.

0 comments on commit 6e6ae6f

Please sign in to comment.