src/cm/media/js/lib/yui/yui_3.10.3/docs/yql/index.html
author Yves-Marie Haussonne <ymh.work+github@gmail.com>
Fri, 09 May 2014 18:35:26 +0200
changeset 656 a84519031134
parent 525 89ef5ed3c48b
permissions -rw-r--r--
add link to "privacy policy" in the header test

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>YQL Query</title>
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
    <link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
    <script src="../../build/yui/yui-min.js"></script>
    
</head>
<body>
<!--
<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>
-->
<div id="doc">
    <div id="hd">
        <h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
    </div>
    
        <a href="#toc" class="jump">Jump to Table of Contents</a>
    

            <h1>YQL Query</h1>
    <div class="yui3-g">
        <div class="yui3-u-3-4">
            <div id="main">
                <div class="content"><div class="intro">
<img alt="" style="float: right; margin-left: 15px; border: 1px solid #D9D9D9;" src=
"http://l.yimg.com/a/i/us/pps/yql128.gif"> 
 
<p><a href="http://developer.yahoo.com/yql/">The Yahoo! Query Language</a> (YQL) is an expressive SQL-like
language that lets you query, filter, and join data across
Web services. With YQL, <i>apps run faster with fewer lines
of code and a smaller network footprint.</i></p> 
 
<p>Yahoo! and other websites across the Internet make much
of their structured data available to developers, primarily
through Web services. To access and query these services,
developers traditionally endure the pain of locating the
right URLs and documentation to access and query each Web
service.</p> 
 
<p>With YQL, developers can access and shape data across
the Internet through one simple language, eliminating the
need to learn how to call different APIs.</p> 
</div>

<h2 id="getting-started">Getting Started</h2>

<p>
To include the source files for YQL Query and its dependencies, first load
the YUI seed file if you haven't already loaded it.
</p>

<pre class="code prettyprint">&lt;script src=&quot;http:&#x2F;&#x2F;yui.yahooapis.com&#x2F;3.10.3&#x2F;build&#x2F;yui&#x2F;yui-min.js&quot;&gt;&lt;&#x2F;script&gt;</pre>


<p>
Next, create a new YUI instance for your application and populate it with the
modules you need by specifying them as arguments to the <code>YUI().use()</code> method.
YUI will automatically load any dependencies required by the modules you
specify.
</p>

<pre class="code prettyprint">&lt;script&gt;
&#x2F;&#x2F; Create a new YUI instance and populate it with the required modules.
YUI().use(&#x27;yql&#x27;, function (Y) {
    &#x2F;&#x2F; YQL Query is available and ready for use. Add implementation
    &#x2F;&#x2F; code here.
});
&lt;&#x2F;script&gt;</pre>


<p>
For more information on creating YUI instances and on the
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the
documentation for the <a href="../yui/index.html">YUI Global Object</a>.
</p>


<h2 id="query">Making a Query</h2>
<p>After you find the query you want to run in the Developer Console, just plug it in:</p>
<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>

<pre class="code prettyprint">YUI().use(&#x27;yql&#x27;, function(Y) {

    Y.YQL(&#x27;select * from weather.forecast where location=90210&#x27;, function(r) {
        &#x2F;&#x2F;r now contains the result of the YQL Query
		&#x2F;&#x2F;use the YQL Developer console to learn
		&#x2F;&#x2F;what data is coming back in this object
		&#x2F;&#x2F;and how that data is structured.
    });

});</pre>



<h2 id="query-reuse">Re-Using A Query</h2>
<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>

<pre class="code prettyprint">YUI().use(&#x27;yql&#x27;, function(Y) {

    var q = Y.YQL(&#x27;select * from weather.forecast where location=90210&#x27;, function(r) {
        &#x2F;&#x2F;r now contains the result of the YQL Query
    });

    &#x2F;&#x2F;Sometime later

    q.send();

});</pre>



<h2 id="changing-a-re-used-query">Changing A Re-Used Query</h2>
<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>
<p>To do this, we need to modify the private param <code>q</code> on the YQL instance.</p>

<pre class="code prettyprint">YUI().use(&#x27;yql&#x27;, function(Y) {

    var q = Y.YQL(&#x27;select * from weather.forecast where location=90210&#x27;, function(r) {
        &#x2F;&#x2F;r now contains the result of the YQL Query
    });

    &#x2F;&#x2F;Sometime later
    q._params.q = &#x27;select * from weather.forecast where location=62959&#x27;;
    q.send();

});</pre>


<h2 id="tables">Open Data Tables</h2>
<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>
<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>

<h2 id="advoptions">Advanced Options</h2>
<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>

<pre class="code prettyprint">YUI().use(&#x27;yql&#x27;, function(Y) {

    var q = new Y.YQLRequest(&#x27;select * from weather.forecast where location=90210&#x27;, function(r) {
        &#x2F;&#x2F;r now contains the result of the YQL Query
    }, {
        &#x2F;&#x2F;Optional URL Parameters to add to the request
        foo: &#x27;bar&#x27;,
        another: &#x27;option&#x27;
    }, {
        &#x2F;&#x2F;Options
        base: &#x27;:&#x2F;&#x2F;query.yahooapis.com&#x2F;v1&#x2F;yql?&#x27;, &#x2F;&#x2F;Different base URL for private data
        proto: &#x27;https&#x27; &#x2F;&#x2F;Connect using SSL
    });
    q.send();

});</pre>

</div>
            </div>
        </div>

        <div class="yui3-u-1-4">
            <div class="sidebar">
                
                    <div id="toc" class="sidebox">
                        <div class="hd">
                            <h2 class="no-toc">Table of Contents</h2>
                        </div>

                        <div class="bd">
                            <ul class="toc">
<li>
<a href="#getting-started">Getting Started</a>
</li>
<li>
<a href="#query">Making a Query</a>
</li>
<li>
<a href="#query-reuse">Re-Using A Query</a>
</li>
<li>
<a href="#changing-a-re-used-query">Changing A Re-Used Query</a>
</li>
<li>
<a href="#tables">Open Data Tables</a>
</li>
<li>
<a href="#advoptions">Advanced Options</a>
</li>
</ul>
                        </div>
                    </div>
                

                
                    <div class="sidebox">
                        <div class="hd">
                            <h2 class="no-toc">Examples</h2>
                        </div>

                        <div class="bd">
                            <ul class="examples">
                                
                                    
                                        <li data-description="Create a simple YQL Query to retrieve data from the Yahoo! Weather YQL table.">
                                            <a href="simple-yql.html">Simple YQL Query</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Use the Flickr Recent Photos YQL table to pull in a small set of recent Flickr images every 8 seconds.">
                                            <a href="yql-requery.html">Reusing a YQL query</a>
                                        </li>
                                    
                                
                                    
                                
                                    
                                
                            </ul>
                        </div>
                    </div>
                

                
                    <div class="sidebox">
                        <div class="hd">
                            <h2 class="no-toc">Examples That Use This Component</h2>
                        </div>

                        <div class="bd">
                            <ul class="examples">
                                
                                    
                                
                                    
                                
                                    
                                        <li data-description="Example Photo Browser application.">
                                            <a href="../dd/photo-browser.html">Photo Browser</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Portal style example using Drag &amp; Drop Event Bubbling and Animation.">
                                            <a href="../dd/portal-drag.html">Portal Style Example</a>
                                        </li>
                                    
                                
                            </ul>
                        </div>
                    </div>
                
            </div>
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

<script>
YUI.Env.Tests = {
    examples: [],
    project: '../assets',
    assets: '../assets/yql',
    name: 'yql',
    title: 'YQL Query',
    newWindow: '',
    auto:  false 
};
YUI.Env.Tests.examples.push('simple-yql');
YUI.Env.Tests.examples.push('yql-requery');
YUI.Env.Tests.examples.push('photo-browser');
YUI.Env.Tests.examples.push('portal-drag');

</script>
<script src="../assets/yui/test-runner.js"></script>



</body>
</html>