|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>YQL Query</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
<a href="#toc" class="jump">Jump to Table of Contents</a> |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
<h1>YQL Query</h1> |
|
|
27 |
<div class="yui3-g"> |
|
|
28 |
<div class="yui3-u-3-4"> |
|
|
29 |
<div id="main"> |
|
|
30 |
<div class="content"><div class="intro"> |
|
|
31 |
<img alt="" style="float: right; margin-left: 15px; border: 1px solid #D9D9D9;" src= |
|
|
32 |
"http://l.yimg.com/a/i/us/pps/yql128.gif"> |
|
|
33 |
|
|
|
34 |
<p><a href="http://developer.yahoo.com/yql/">The Yahoo! Query Language</a> (YQL) is an expressive SQL-like |
|
|
35 |
language that lets you query, filter, and join data across |
|
|
36 |
Web services. With YQL, <i>apps run faster with fewer lines |
|
|
37 |
of code and a smaller network footprint.</i></p> |
|
|
38 |
|
|
|
39 |
<p>Yahoo! and other websites across the Internet make much |
|
|
40 |
of their structured data available to developers, primarily |
|
|
41 |
through Web services. To access and query these services, |
|
|
42 |
developers traditionally endure the pain of locating the |
|
|
43 |
right URLs and documentation to access and query each Web |
|
|
44 |
service.</p> |
|
|
45 |
|
|
|
46 |
<p>With YQL, developers can access and shape data across |
|
|
47 |
the Internet through one simple language, eliminating the |
|
|
48 |
need to learn how to call different APIs.</p> |
|
|
49 |
</div> |
|
|
50 |
|
|
|
51 |
<h2 id="getting-started">Getting Started</h2> |
|
|
52 |
|
|
|
53 |
<p> |
|
|
54 |
To include the source files for YQL Query and its dependencies, first load |
|
|
55 |
the YUI seed file if you haven't already loaded it. |
|
|
56 |
</p> |
|
|
57 |
|
|
|
58 |
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script></pre> |
|
|
59 |
|
|
|
60 |
|
|
|
61 |
<p> |
|
|
62 |
Next, create a new YUI instance for your application and populate it with the |
|
|
63 |
modules you need by specifying them as arguments to the <code>YUI().use()</code> method. |
|
|
64 |
YUI will automatically load any dependencies required by the modules you |
|
|
65 |
specify. |
|
|
66 |
</p> |
|
|
67 |
|
|
|
68 |
<pre class="code prettyprint"><script> |
|
|
69 |
// Create a new YUI instance and populate it with the required modules. |
|
|
70 |
YUI().use('yql', function (Y) { |
|
|
71 |
// YQL Query is available and ready for use. Add implementation |
|
|
72 |
// code here. |
|
|
73 |
}); |
|
|
74 |
</script></pre> |
|
|
75 |
|
|
|
76 |
|
|
|
77 |
<p> |
|
|
78 |
For more information on creating YUI instances and on the |
|
|
79 |
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the |
|
|
80 |
documentation for the <a href="../yui/index.html">YUI Global Object</a>. |
|
|
81 |
</p> |
|
|
82 |
|
|
|
83 |
|
|
|
84 |
<h2 id="query">Making a Query</h2> |
|
|
85 |
<p>After you find the query you want to run in the Developer Console, just plug it in:</p> |
|
|
86 |
<p>The <a href="http://developer.yahoo.com/yql/console/">YQL Developer Console</a> is a nice place to start playing with YQL queries. You can test and inspect queries before you actually use them.</p> |
|
|
87 |
|
|
|
88 |
<pre class="code prettyprint">YUI().use('yql', function(Y) { |
|
|
89 |
|
|
|
90 |
Y.YQL('select * from weather.forecast where location=90210', function(r) { |
|
|
91 |
//r now contains the result of the YQL Query |
|
|
92 |
//use the YQL Developer console to learn |
|
|
93 |
//what data is coming back in this object |
|
|
94 |
//and how that data is structured. |
|
|
95 |
}); |
|
|
96 |
|
|
|
97 |
});</pre> |
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
<h2 id="query-reuse">Re-Using A Query</h2> |
|
|
102 |
<p>Modifying the example above to make it reusable is simple, just save the result of the query and call <code>send</code> on it to query for the results again.</p> |
|
|
103 |
|
|
|
104 |
<pre class="code prettyprint">YUI().use('yql', function(Y) { |
|
|
105 |
|
|
|
106 |
var q = Y.YQL('select * from weather.forecast where location=90210', function(r) { |
|
|
107 |
//r now contains the result of the YQL Query |
|
|
108 |
}); |
|
|
109 |
|
|
|
110 |
//Sometime later |
|
|
111 |
|
|
|
112 |
q.send(); |
|
|
113 |
|
|
|
114 |
});</pre> |
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
<h2 id="changing-a-re-used-query">Changing A Re-Used Query</h2> |
|
|
119 |
<p>Changing a query without creating a new instance can be beneficial for queries that involve the same request but different parameters (like an AutoComplete query).</p> |
|
|
120 |
<p>To do this, we need to modify the private param <code>q</code> on the YQL instance.</p> |
|
|
121 |
|
|
|
122 |
<pre class="code prettyprint">YUI().use('yql', function(Y) { |
|
|
123 |
|
|
|
124 |
var q = Y.YQL('select * from weather.forecast where location=90210', function(r) { |
|
|
125 |
//r now contains the result of the YQL Query |
|
|
126 |
}); |
|
|
127 |
|
|
|
128 |
//Sometime later |
|
|
129 |
q._params.q = 'select * from weather.forecast where location=62959'; |
|
|
130 |
q.send(); |
|
|
131 |
|
|
|
132 |
});</pre> |
|
|
133 |
|
|
|
134 |
|
|
|
135 |
<h2 id="tables">Open Data Tables</h2> |
|
|
136 |
<p>Open Data Tables enable developers to add tables for any data on the Web to YQL's stable of API-specific tables. Using Open Data Tables, anyone can make their data YQL-accessible. If you would like to create an Open Data Table, visit the community page at <a href="http://datatables.org">http://datatables.org</a>.</p> |
|
|
137 |
<p>By default, the <code>YQL</code> module will include the environment file needed to use all of the publicly available Open Data Tables.</p> |
|
|
138 |
|
|
|
139 |
<h2 id="advoptions">Advanced Options</h2> |
|
|
140 |
<p>The default configuration for the <code>YQL</code> module is designed for the most basic use cases. However, the <code>YQLRequest</code> class is designed to give the developer more control over the query, parameters and options used to make the YQL Request.</p> |
|
|
141 |
|
|
|
142 |
<pre class="code prettyprint">YUI().use('yql', function(Y) { |
|
|
143 |
|
|
|
144 |
var q = new Y.YQLRequest('select * from weather.forecast where location=90210', function(r) { |
|
|
145 |
//r now contains the result of the YQL Query |
|
|
146 |
}, { |
|
|
147 |
//Optional URL Parameters to add to the request |
|
|
148 |
foo: 'bar', |
|
|
149 |
another: 'option' |
|
|
150 |
}, { |
|
|
151 |
//Options |
|
|
152 |
base: '://query.yahooapis.com/v1/yql?', //Different base URL for private data |
|
|
153 |
proto: 'https' //Connect using SSL |
|
|
154 |
}); |
|
|
155 |
q.send(); |
|
|
156 |
|
|
|
157 |
});</pre> |
|
|
158 |
|
|
|
159 |
</div> |
|
|
160 |
</div> |
|
|
161 |
</div> |
|
|
162 |
|
|
|
163 |
<div class="yui3-u-1-4"> |
|
|
164 |
<div class="sidebar"> |
|
|
165 |
|
|
|
166 |
<div id="toc" class="sidebox"> |
|
|
167 |
<div class="hd"> |
|
|
168 |
<h2 class="no-toc">Table of Contents</h2> |
|
|
169 |
</div> |
|
|
170 |
|
|
|
171 |
<div class="bd"> |
|
|
172 |
<ul class="toc"> |
|
|
173 |
<li> |
|
|
174 |
<a href="#getting-started">Getting Started</a> |
|
|
175 |
</li> |
|
|
176 |
<li> |
|
|
177 |
<a href="#query">Making a Query</a> |
|
|
178 |
</li> |
|
|
179 |
<li> |
|
|
180 |
<a href="#query-reuse">Re-Using A Query</a> |
|
|
181 |
</li> |
|
|
182 |
<li> |
|
|
183 |
<a href="#changing-a-re-used-query">Changing A Re-Used Query</a> |
|
|
184 |
</li> |
|
|
185 |
<li> |
|
|
186 |
<a href="#tables">Open Data Tables</a> |
|
|
187 |
</li> |
|
|
188 |
<li> |
|
|
189 |
<a href="#advoptions">Advanced Options</a> |
|
|
190 |
</li> |
|
|
191 |
</ul> |
|
|
192 |
</div> |
|
|
193 |
</div> |
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
<div class="sidebox"> |
|
|
198 |
<div class="hd"> |
|
|
199 |
<h2 class="no-toc">Examples</h2> |
|
|
200 |
</div> |
|
|
201 |
|
|
|
202 |
<div class="bd"> |
|
|
203 |
<ul class="examples"> |
|
|
204 |
|
|
|
205 |
|
|
|
206 |
<li data-description="Create a simple YQL Query to retrieve data from the Yahoo! Weather YQL table."> |
|
|
207 |
<a href="simple-yql.html">Simple YQL Query</a> |
|
|
208 |
</li> |
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
<li data-description="Use the Flickr Recent Photos YQL table to pull in a small set of recent Flickr images every 8 seconds."> |
|
|
213 |
<a href="yql-requery.html">Reusing a YQL query</a> |
|
|
214 |
</li> |
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
</ul> |
|
|
222 |
</div> |
|
|
223 |
</div> |
|
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
<div class="sidebox"> |
|
|
228 |
<div class="hd"> |
|
|
229 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
230 |
</div> |
|
|
231 |
|
|
|
232 |
<div class="bd"> |
|
|
233 |
<ul class="examples"> |
|
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
<li data-description="Example Photo Browser application."> |
|
|
241 |
<a href="../dd/photo-browser.html">Photo Browser</a> |
|
|
242 |
</li> |
|
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
|
246 |
<li data-description="Portal style example using Drag & Drop Event Bubbling and Animation."> |
|
|
247 |
<a href="../dd/portal-drag.html">Portal Style Example</a> |
|
|
248 |
</li> |
|
|
249 |
|
|
|
250 |
|
|
|
251 |
</ul> |
|
|
252 |
</div> |
|
|
253 |
</div> |
|
|
254 |
|
|
|
255 |
</div> |
|
|
256 |
</div> |
|
|
257 |
</div> |
|
|
258 |
</div> |
|
|
259 |
|
|
|
260 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
261 |
<script>prettyPrint();</script> |
|
|
262 |
|
|
|
263 |
<script> |
|
|
264 |
YUI.Env.Tests = { |
|
|
265 |
examples: [], |
|
|
266 |
project: '../assets', |
|
|
267 |
assets: '../assets/yql', |
|
|
268 |
name: 'yql', |
|
|
269 |
title: 'YQL Query', |
|
|
270 |
newWindow: '', |
|
|
271 |
auto: false |
|
|
272 |
}; |
|
|
273 |
YUI.Env.Tests.examples.push('simple-yql'); |
|
|
274 |
YUI.Env.Tests.examples.push('yql-requery'); |
|
|
275 |
YUI.Env.Tests.examples.push('photo-browser'); |
|
|
276 |
YUI.Env.Tests.examples.push('portal-drag'); |
|
|
277 |
|
|
|
278 |
</script> |
|
|
279 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
280 |
|
|
|
281 |
|
|
|
282 |
|
|
|
283 |
</body> |
|
|
284 |
</html> |