|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Simple 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 |
|
|
|
24 |
<h1>Example: Simple YQL Query</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><div class="intro"> |
|
|
29 |
<p>In this example, we make a simple YQL Query to retrieve data from the Yahoo! Weather YQL table.</p> |
|
|
30 |
</div> |
|
|
31 |
|
|
|
32 |
<div class="example"> |
|
|
33 |
<style> |
|
|
34 |
#res .mod { |
|
|
35 |
background-color:white; |
|
|
36 |
border:1px solid black; |
|
|
37 |
padding:1em; |
|
|
38 |
} |
|
|
39 |
#res h2 { |
|
|
40 |
color: black; |
|
|
41 |
} |
|
|
42 |
</style> |
|
|
43 |
|
|
|
44 |
|
|
|
45 |
<div id="res">Querying YQL..</div> |
|
|
46 |
|
|
|
47 |
|
|
|
48 |
<script> |
|
|
49 |
YUI().use('node', 'yql', function(Y) { |
|
|
50 |
|
|
|
51 |
var res = Y.one('#res'), |
|
|
52 |
zip = '90210'; |
|
|
53 |
|
|
|
54 |
Y.YQL('select * from weather.forecast where location=' + zip, function(r) { |
|
|
55 |
var el = Y.Node.create('<div class="mod"></div>'); |
|
|
56 |
|
|
|
57 |
el.set('innerHTML', '<h2>Weather for ' + zip + '</h2>' + r.query.results.channel.item.description); |
|
|
58 |
|
|
|
59 |
res.setHTML(el); |
|
|
60 |
|
|
|
61 |
}); |
|
|
62 |
}); |
|
|
63 |
|
|
|
64 |
|
|
|
65 |
</script> |
|
|
66 |
|
|
|
67 |
|
|
|
68 |
</div> |
|
|
69 |
|
|
|
70 |
<p>The easiest way to build a YQL query is by visiting the <a href="http://developer.yahoo.com/yql/console/">YQL Console</a>. In this example we will be using the <code><a href="http://developer.yahoo.com/yql/console/#h=select%20*%20from%20weather.forecast%20where%20location%3D90210">weather.forecast</a></code> table. The <code>YQL</code> statement that we are using looks like this:</p> |
|
|
71 |
|
|
|
72 |
<pre class="code prettyprint">select * from weather.forecast where location=90210</pre> |
|
|
73 |
|
|
|
74 |
|
|
|
75 |
<p>You can <a href="http://developer.yahoo.com/yql/console/?q=SELECT%20*%20FROM%20weather.forecast%20WHERE%20location%3D90210" title="YQL Console">preview this query in the YQL Console</a> to get a sense of the data it returns.</p> |
|
|
76 |
|
|
|
77 |
<h3>Setting Up the YUI Instance</h3> |
|
|
78 |
|
|
|
79 |
<p>Now we need to create our YUI instance and tell it to load the <code>yql</code> and <code>node</code> modules.</p> |
|
|
80 |
|
|
|
81 |
<pre class="code prettyprint">YUI().use('node', 'yql');</pre> |
|
|
82 |
|
|
|
83 |
|
|
|
84 |
<h3>Making the Query</h3> |
|
|
85 |
|
|
|
86 |
<p>We now have a YUI instance with the <code>yql</code> module (and its dependencies) attached, so we can proceed to make a query.</p> |
|
|
87 |
|
|
|
88 |
<pre class="code prettyprint">YUI().use('node', 'yql', function(Y) { |
|
|
89 |
|
|
|
90 |
var res = Y.one('#res'), |
|
|
91 |
zip = '90210'; |
|
|
92 |
|
|
|
93 |
Y.YQL('select * from weather.forecast where location=' + zip, function(r) { |
|
|
94 |
var el = Y.Node.create('<div class="mod"></div>'); |
|
|
95 |
|
|
|
96 |
el.set('innerHTML', '<h2>Weather for ' + zip + '</h2>' + r.query.results.channel.item.description); |
|
|
97 |
|
|
|
98 |
res.setHTML(el); |
|
|
99 |
|
|
|
100 |
}); |
|
|
101 |
});</pre> |
|
|
102 |
|
|
|
103 |
</div> |
|
|
104 |
</div> |
|
|
105 |
</div> |
|
|
106 |
|
|
|
107 |
<div class="yui3-u-1-4"> |
|
|
108 |
<div class="sidebar"> |
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
<div class="sidebox"> |
|
|
113 |
<div class="hd"> |
|
|
114 |
<h2 class="no-toc">Examples</h2> |
|
|
115 |
</div> |
|
|
116 |
|
|
|
117 |
<div class="bd"> |
|
|
118 |
<ul class="examples"> |
|
|
119 |
|
|
|
120 |
|
|
|
121 |
<li data-description="Create a simple YQL Query to retrieve data from the Yahoo! Weather YQL table."> |
|
|
122 |
<a href="simple-yql.html">Simple YQL Query</a> |
|
|
123 |
</li> |
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
<li data-description="Use the Flickr Recent Photos YQL table to pull in a small set of recent Flickr images every 8 seconds."> |
|
|
128 |
<a href="yql-requery.html">Reusing a YQL query</a> |
|
|
129 |
</li> |
|
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
</ul> |
|
|
137 |
</div> |
|
|
138 |
</div> |
|
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
<div class="sidebox"> |
|
|
143 |
<div class="hd"> |
|
|
144 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
145 |
</div> |
|
|
146 |
|
|
|
147 |
<div class="bd"> |
|
|
148 |
<ul class="examples"> |
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
<li data-description="Example Photo Browser application."> |
|
|
156 |
<a href="../dd/photo-browser.html">Photo Browser</a> |
|
|
157 |
</li> |
|
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
<li data-description="Portal style example using Drag & Drop Event Bubbling and Animation."> |
|
|
162 |
<a href="../dd/portal-drag.html">Portal Style Example</a> |
|
|
163 |
</li> |
|
|
164 |
|
|
|
165 |
|
|
|
166 |
</ul> |
|
|
167 |
</div> |
|
|
168 |
</div> |
|
|
169 |
|
|
|
170 |
</div> |
|
|
171 |
</div> |
|
|
172 |
</div> |
|
|
173 |
</div> |
|
|
174 |
|
|
|
175 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
176 |
<script>prettyPrint();</script> |
|
|
177 |
|
|
|
178 |
<script> |
|
|
179 |
YUI.Env.Tests = { |
|
|
180 |
examples: [], |
|
|
181 |
project: '../assets', |
|
|
182 |
assets: '../assets/yql', |
|
|
183 |
name: 'simple-yql', |
|
|
184 |
title: 'Simple YQL Query', |
|
|
185 |
newWindow: '', |
|
|
186 |
auto: false |
|
|
187 |
}; |
|
|
188 |
YUI.Env.Tests.examples.push('simple-yql'); |
|
|
189 |
YUI.Env.Tests.examples.push('yql-requery'); |
|
|
190 |
YUI.Env.Tests.examples.push('photo-browser'); |
|
|
191 |
YUI.Env.Tests.examples.push('portal-drag'); |
|
|
192 |
|
|
|
193 |
</script> |
|
|
194 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
</body> |
|
|
199 |
</html> |