2
YUI 3.13.0 (build 508226d)
3
Copyright 2013 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
8
YUI.add('yql', function (Y, NAME) {
11
* This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/).
15
* Utility Class used under the hood my the YQL class
18
* @param {String} sql The SQL statement to execute
19
* @param {Function/Object} callback The callback to execute after the query (Falls through to JSONP).
20
* @param {Object} params An object literal of extra parameters to pass along (optional).
21
* @param {Object} opts An object literal of configuration options (optional): proto (http|https), base (url)
23
var YQLRequest = function (sql, callback, params, opts) {
29
//Allow format override.. JSON-P-X
31
params.format = Y.YQLRequest.FORMAT;
34
params.env = Y.YQLRequest.ENV;
39
if (opts && opts.context) {
40
this._context = opts.context;
44
if (params && params.context) {
45
this._context = params.context;
46
delete params.context;
49
this._params = params;
51
this._callback = callback;
55
YQLRequest.prototype = {
59
* @description Reference to the JSONP instance used to make the queries
65
* @description Holder for the opts argument
71
* @description Holder for the callback argument
77
* @description Holder for the params argument
83
* @description The context to execute the callback in
89
* @description Internal Callback Handler
91
_internal: function () {
92
this._callback.apply(this._context, arguments);
96
* @description The method that executes the YQL Request.
98
* @return {YQLRequest}
101
var qs = [], url = ((this._opts && this._opts.proto) ? this._opts.proto : Y.YQLRequest.PROTO), o;
103
Y.Object.each(this._params, function (v, k) {
104
qs.push(k + '=' + encodeURIComponent(v));
109
url += ((this._opts && this._opts.base) ? this._opts.base : Y.YQLRequest.BASE_URL) + qs;
111
o = (!Y.Lang.isFunction(this._callback)) ? this._callback : { on: { success: this._callback } };
114
this._callback = o.on.success;
116
o.on.success = Y.bind(this._internal, this);
118
Y.log('URL: ' + url, 'info', 'yql');
123
* Private method to send the request, overwritten in plugins
126
* @param {String} url The URL to request
127
* @param {Object} o The config object
130
//Overwritten in plugins
137
* @description Default format to use: json
139
YQLRequest.FORMAT = 'json';
143
* @description Default protocol to use: http
145
YQLRequest.PROTO = 'http';
149
* @description The base URL to query: query.yahooapis.com/v1/public/yql?
151
YQLRequest.BASE_URL = ':/' + '/query.yahooapis.com/v1/public/yql?';
155
* @description The environment file to load: http://datatables.org/alltables.env
157
YQLRequest.ENV = 'http:/' + '/datatables.org/alltables.env';
159
Y.YQLRequest = YQLRequest;
162
* This class adds a sugar class to allow access to YQL (http://developer.yahoo.com/yql/).
165
* @param {String} sql The SQL statement to execute
166
* @param {Function} callback The callback to execute after the query (optional).
167
* @param {Object} params An object literal of extra parameters to pass along (optional).
168
* @param {Object} opts An object literal of configuration options (optional): proto (http|https), base (url)
170
Y.YQL = function (sql, callback, params, opts) {
171
return new Y.YQLRequest(sql, callback, params, opts).send();
175
}, '3.13.0', {"requires": ["oop"]});