src/cm/media/js/lib/yui/yui_3.10.3/docs/yql/yql-requery.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>Example: Reusing a 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>
    

            <h1>Example: Reusing a YQL query</h1>
    <div class="yui3-g">
        <div class="yui3-u-3-4">
            <div id="main">
                <div class="content"><div class="intro">
<p>In this example, the Flickr Recent Photos YQL table is used to pull in a small set of recent Flickr images every 8 seconds.</p>
</div>

<div class="example">
    <style>
    #res {
        background-color: white;
        border: 1px solid black;
        padding: 2em;
    }
    #res h2 {
        color: black;
    }
    #res h2 em {
        font-size: 60%;
    }
    #res a {
        margin: .25em;
    }
    #res a img {
        border: 1px solid black;
    }
</style>

<div id="res"></div>

<script>
YUI().use('node', 'yql', function(Y) {
    
    var res = Y.one('#res'), count = 0,
        url = '<a href="http://flickr.com/photos/{owner}/{id}"><img src="http://static.flickr.com/{server}/{id}_{secret}_t.jpg"></a>';
    
    var q = Y.YQL('select * from flickr.photos.recent where (api_key = "1895311ec0d2e23431a6407f3e8dffcc")', {
        //Tell JSONP to not cache this request so we get new images on each request
        allowCache: false,
        on: {
            success: function(r) {
                if (r.query && r.query.results) {
                    count++;
                    res.setHTML('<h2>Recent Flickr Photos <em>(query #' + count + ')</em></h2>');
                    Y.each(r.query.results.photo, function(v) {
                        res.append(Y.Lang.sub(url, v));
                    });
                }
            }
        }
    });
    Y.later(8000, q, q.send, null, true);
});

</script>


</div>
<h3>Setting Up the Query</h3>
<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%20flickr.photos.recent">flickr.photos.recent</a></code> table. The <code>YQL</code> statement that we are using looks like this:</p>

<pre class="code prettyprint">select * from flickr.photos.recent where (api_key = &quot;1895311ec0d2e23431a6407f3e8dffcc&quot;)</pre>


<h3>Setting Up the YUI Instance</h3>
<p>Now we need to create our YUI instance and tell it to load the <code>yql</code> and <code>node</code> modules.</p>

<pre class="code prettyprint">YUI().use(&#x27;node&#x27;, &#x27;yql&#x27;);</pre>


<h3>Making the Query</h3>
<p>Now that we have a YUI instance with the <code>yql</code> module, we can now make a query.</p>

<pre class="code prettyprint">YUI().use(&#x27;node&#x27;, &#x27;yql&#x27;, function(Y) {
    
    var res = Y.one(&#x27;#res&#x27;), count = 0,
        url = &#x27;&lt;a href=&quot;http:&#x2F;&#x2F;flickr.com&#x2F;photos&#x2F;{owner}&#x2F;{id}&quot;&gt;&lt;img src=&quot;http:&#x2F;&#x2F;static.flickr.com&#x2F;{server}&#x2F;{id}_{secret}_t.jpg&quot;&gt;&lt;&#x2F;a&gt;&#x27;;
    
    var q = Y.YQL(&#x27;select * from flickr.photos.recent where (api_key = &quot;1895311ec0d2e23431a6407f3e8dffcc&quot;)&#x27;, {
        &#x2F;&#x2F;Tell JSONP to not cache this request so we get new images on each request
        allowCache: false,
        on: {
            success: function(r) {
                if (r.query &amp;&amp; r.query.results) {
                    count++;
                    res.setHTML(&#x27;&lt;h2&gt;Recent Flickr Photos &lt;em&gt;(query #&#x27; + count + &#x27;)&lt;&#x2F;em&gt;&lt;&#x2F;h2&gt;&#x27;);
                    Y.each(r.query.results.photo, function(v) {
                        res.append(Y.Lang.sub(url, v));
                    });
                }
            }
        }
    });
    Y.later(8000, q, q.send, null, true);
});</pre>

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

        <div class="yui3-u-1-4">
            <div class="sidebar">
                

                
                    <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-requery',
    title: 'Reusing a 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>