3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('yql', function(Y) {
10
* This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/).
14
* Utility Class used under the hood my the YQL class
17
* @param {String} sql The SQL statement to execute
18
* @param {Function/Object} callback The callback to execute after the query (Falls through to JSONP).
19
* @param {Object} params An object literal of extra parameters to pass along (optional).
20
* @param {Object} opts An object literal of configuration options (optional): proto (http|https), base (url)
22
var YQLRequest = function (sql, callback, params, opts) {
28
//Allow format override.. JSON-P-X
30
params.format = Y.YQLRequest.FORMAT;
33
params.env = Y.YQLRequest.ENV;
36
this._params = params;
38
this._callback = callback;
42
YQLRequest.prototype = {
46
* @description Reference to the JSONP instance used to make the queries
52
* @description Holder for the opts argument
58
* @description Holder for the callback argument
64
* @description Holder for the params argument
69
* @description The method that executes the YQL Request.
71
* @returns {YQLRequest}
74
var qs = [], url = ((this._opts && this._opts.proto) ? this._opts.proto : Y.YQLRequest.PROTO);
76
Y.each(this._params, function(v, k) {
77
qs.push(k + '=' + encodeURIComponent(v));
82
url += ((this._opts && this._opts.base) ? this._opts.base : Y.YQLRequest.BASE_URL) + qs;
84
var o = (!Y.Lang.isFunction(this._callback)) ? this._callback : { on: { success: this._callback } };
85
if (o.allowCache !== false) {
88
Y.log('URL: ' + url, 'info', 'yql');
91
this._jsonp = Y.jsonp(url, o);
93
this._jsonp.url = url;
94
if (o.on && o.on.success) {
95
this._jsonp._config.on.success = o.on.success;
106
* @description Default format to use: json
108
YQLRequest.FORMAT = 'json';
112
* @description Default protocol to use: http
114
YQLRequest.PROTO = 'http';
118
* @description The base URL to query: query.yahooapis.com/v1/public/yql?
120
YQLRequest.BASE_URL = ':/'+'/query.yahooapis.com/v1/public/yql?';
124
* @description The environment file to load: http://datatables.org/alltables.env
126
YQLRequest.ENV = 'http:/'+'/datatables.org/alltables.env';
128
Y.YQLRequest = YQLRequest;
131
* This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/).
134
* @param {String} sql The SQL statement to execute
135
* @param {Function} callback The callback to execute after the query (optional).
136
* @param {Object} params An object literal of extra parameters to pass along (optional).
137
* @param {Object} opts An object literal of configuration options (optional): proto (http|https), base (url)
139
Y.YQL = function(sql, callback, params, opts) {
140
return new Y.YQLRequest(sql, callback, params, opts).send();
145
}, '3.4.1' ,{requires:['jsonp', 'jsonp-url']});