Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit of YQL Module

  • Loading branch information...
commit 6e6ae6f14d4b503da8cead0bda4a2780190cdec5 1 parent e9495df
@davglass davglass authored
View
133 build/yql/yql-debug.js
@@ -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
1  build/yql/yql-min.js
@@ -0,0 +1 @@
+YUI.add("yql",function(C){if(!YUI.yql){YUI.yql={};}var B="http:/"+"/query.yahooapis.com/v1/public/yql?",A=function(F,G,E,D){A.superclass.constructor.apply(this);this._query(F,G,E,D);};C.extend(A,C.EventTarget,{_cb:null,_stamp:null,_receiver:function(D){if(D.query){this.fire("query",D.query);}if(D.error){this.fire("error",D.error);}if(this._cb){this._cb(D);}delete YUI.yql[this._stamp];},_query:function(I,J,H,G){var F=C.stamp({}),D="",E;F=F.replace(/-/g,"_");this._stamp=F;this._cb=J;YUI.yql[F]=C.bind(this._receiver,this);if(!H){H={};}H.q=I;H.format="json";H.callback="YUI.yql."+F;if(!H.env){H.env="http:/"+"/datatables.org/alltables.env";}C.each(H,function(L,K){D+=K+"="+encodeURIComponent(L)+"&";});if(!G){G={};}G.autopurge=true;G.context=this;G.onTimeout=function(K){this.fire("timeout",K);if(this._cb){this._cb(K);this._cb=null;}};E=B+D;C.Get.script(E,G);return this;}});C.yql=A;},"@VERSION@",{requires:["get","event-custom"],supersedes:["get","event-custom"]});
View
133 build/yql/yql.js
@@ -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
30 sandbox/davglass/yql/LICENSE
@@ -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.
+
View
129 sandbox/davglass/yql/yql.js
@@ -0,0 +1,129 @@
+/*jslint predef: YUI */
+ //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;
+
View
25 src/yql/build.properties
@@ -0,0 +1,25 @@
+# YQL Query Build Properties
+
+# As long as the 'builder' project is cloned to the default folder
+# next to the 'yui3-gallery' project folder, the 'builddir' property does not
+# need to be changed
+#
+# If the 'builder' project is checked out to an alternate location, this
+# property should be updated to point to the checkout location.
+builddir=../../../builder/componentbuild
+
+# The name of the component. E.g. event, attribute, widget
+component=yql
+
+# The list of files which should be concatenated to create the component.
+# NOTE: For a css component (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead.
+component.jsfiles=yql.js
+
+# The list of modules this component requires. Used to setup the Y.add module call for YUI 3.
+# NOTE: For a css component, this property is not used/required.
+
+# component.use, component.supersedes, component.optional and component.skinnable are other properties which can be defined
+component.requires=get, event-custom
+component.supersedes=
+
+
View
7 src/yql/build.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- YUI 3 Gallery Component Build File -->
+<project name="YQL Query" default="local">
+ <description>YQL Query Build File</description>
+ <property file="build.properties" />
+ <import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" />
+</project>
View
128 src/yql/js/yql.js
@@ -0,0 +1,128 @@
+ //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;
+
Please sign in to comment.
Something went wrong with that request. Please try again.