Commits

Sean Wilkinson committed e50a20b

More code for using GFT

Comments (0)

Files changed (3)

src/browser-client/gft.html

   <body>
     <noscript>This page requires JavaScript.</noscript>
     <h1>QM: Google Fusion Tables container</h1>
+    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
     <script src="QM_WWW_URL/gft.js"></script>
   </body>
 </html>

src/browser-client/gft.js

 //  This is an OAuth 2.0 communications layer for QMachine that enables a user
 //  to use his or her own Google Fusion Tables as persistent storage.
 //
-//                                                      ~~ (c) SRW, 24 Apr 2013
+//                                                      ~~ (c) SRW, 21 Apr 2013
 //                                                  ~~ last updated 24 Apr 2013
 
 (function () {
 
  // Pragmas
 
-    /*jshint maxparams: 1, quotmark: single, strict: true */
+    /*jshint maxparams: 2, quotmark: single, strict: true */
 
     /*jslint browser: true, devel: true, indent: 4, maxlen: 80 */
 
+    /*properties
+        access_token, ajax, argv, async, audience, click, client_id, error,
+        getScript, hash, hasOwnProperty, hide, join, jQuery, length, location,
+        log, push, ready, redirect_uri, response_type, scope, slice, split,
+        success, type, url
+    */
+
  // Prerequisites
 
+    if (window.hasOwnProperty('jQuery') === false) {
+        throw new Error('jQuery is missing.');
+    }
+
  // Declarations
 
- // Definitions
+    var $, form2json, json2form, state, verify;
 
- // Prototype definitions
+ // Definitions
 
- // Out-of-scope definitions
+    $ = window.jQuery;
+
+    form2json = function (x) {
+     // This function needs documentation.
+        var key, i, n, temp, val, y;
+        temp = x.split('&');
+        y = {};
+        for (i = 0, n = temp.length; i < n; i += 1) {
+            key = temp[i].split('=')[0];
+            val = temp[i].split('=').slice(1).join('=');
+            y[key] = val;
+        }
+        return y;
+    };
+
+    json2form = function (obj) {
+     // This function needs documentation.
+        var key, y;
+        y = [];
+        for (key in obj) {
+            if (obj.hasOwnProperty(key)) {
+                y.push(key + '=' + obj[key]);
+            }
+        }
+        return y.join('&');
+    };
+
+    state = {
+        argv: {}
+    };
+
+    verify = function (client_id, callback) {
+     // This function needs documentation.
+        var verify_uri = 'https://www.googleapis.com/oauth2/v1/tokeninfo';
+        $.ajax({
+            error: function (code, message) {
+             // This function needs documentation.
+                callback(new Error(message));
+                return;
+            },
+            success: function (data) {
+             // This function needs documentation.
+                var err = null;
+                if (data.audience !== client_id) {
+                    err = new Error('Do not try to confuse the deputy!');
+                }
+                callback(err);
+                return;
+            },
+            type: 'GET',
+            url: verify_uri + '?' + location.hash.slice(1)
+        });
+        return;
+    };
 
  // Invocations
 
-    (function () {
+    $(document).ready(function () {
+     // This function needs documentation.
 
-     // (placeholder)
+        var client_id;
 
-        return;
+        client_id = '780123144915-9edrbl92r7c7of47f4umg7kkjbba3tu0.' +
+            'apps.googleusercontent.com';
+
+        console.log('Welcome to GFT Sandbox :-)');
+
+        state.argv = form2json(location.hash.slice(1));
 
-    }());
+        if (state.argv.hasOwnProperty('access_token')) {
+            verify(client_id, function (err) {
+             // This function needs documentation.
+                if (err !== null) {
+                    throw err;
+                }
+                return;
+            });
+            return;
+        }
+
+        return;
+    });
 
  // That's all, folks!
 

src/browser-client/qmachine.js

         XMLHttpRequest, '__defineGetter__', '__defineSetter__', a,
         addEventListener, adsafe, anon, appendChild, apply, atob, attachEvent,
         avar, b, bitwise, body, box, browser, btoa, by, call, can_run_remotely,
-        cap, charAt, charCodeAt, comm, configurable, console, constructor,
-        contentWindow, continue, createElement, css, data, debug, def,
-        defineProperty, detachEvent, devel, diagnostics, display, document,
-        done, enumerable, env, epitaph, eqeq, error, errors, es5, eval, evil,
-        exemptions, exit, f, fail, floor, forin, fragment, fromCharCode, get,
-        getElementsByTagName, global, hasOwnProperty, head, host, ignoreCase,
-        importScripts, indexOf, join, key, length, lib, load_data, load_script,
-        location, log, map, mapreduce, method, multiline, navigator, newcap,
-        node, nomen, now, on, onLine, onload, onreadystatechange, open,
-        parentElement, parse, passfail, plusplus, ply, postMessage, predef,
-        properties, protocol, prototype, push, puts, query, random, readyState,
-        reason, recent, reduce, regexp, removeChild, removeEventListener,
-        replace, responseText, result, results, revive, rhino, run_remotely,
-        safe, send, set, setTimeout, shelf, shift, slice, sloppy, source, src,
+        cap, charAt, charCodeAt, client_id, comm, configurable, console,
+        constructor, contentWindow, continue, createElement, css, data, debug,
+        def, defineProperty, detachEvent, devel, diagnostics, display,
+        document, done, enumerable, env, epitaph, eqeq, error, errors, es5,
+        eval, evil, exemptions, exit, f, fail, floor, forin, fragment,
+        fromCharCode, get, getElementsByTagName, global, hasOwnProperty, head,
+        host, ignoreCase, importScripts, indexOf, join, key, length, lib,
+        load_data, load_script, location, log, map, mapreduce, method,
+        multiline, navigator, newcap, node, nomen, now, on, onLine, onload,
+        onreadystatechange, open, parentElement, parse, passfail, plusplus,
+        ply, postMessage, predef, properties, protocol, prototype, push, puts,
+        query, random, readyState, reason, recent, redirect_uri, reduce,
+        regexp, removeChild, removeEventListener, replace, responseText,
+        response_type, result, results, revive, rhino, run_remotely, safe,
+        scope, send, set, setTimeout, shelf, shift, slice, sloppy, source, src,
         status, stay, stringify, stupid, style, sub, submit, test, time,
         toJSON, toSource, toString, todo, undef, unparam, url, val, value,
         valueOf, vars, via, visibility, volunteer, when, white, window,
  // Declarations
 
     var ajax, atob, AVar, avar, btoa, can_run_remotely, convert_to_js, copy,
-        deserialize, defineProperty, in_a_browser, in_a_WebWorker, is_closed,
-        is_Function, is_RegExp, is_String, jobs, lib, load_data, load_script,
-        map, mapreduce, ply, puts, read, recent, reduce, revive, run_remotely,
-        serialize, state, submit, update_local, update_remote, volunteer, when,
-        write;
+        create_iframe, deserialize, defineProperty, in_a_browser,
+        in_a_WebWorker, is_closed, is_Function, is_RegExp, is_String, jobs,
+        json2form, lib, load_data, load_script, map, mapreduce, ply, puts,
+        read, recent, reduce, revive, run_remotely, serialize, state, submit,
+        update_local, update_remote, volunteer, when, write;
 
  // Definitions
 
         return y;
     };
 
+    create_iframe = function (url) {
+     // This function needs documentation.
+        var y = avar();
+        // ...
+        return y;
+    };
+
     defineProperty = function (obj, name, params) {
      // This function wraps the ES5 `Object.defineProperty` function so that
      // it degrades gracefully in crusty old browsers. I would like to improve
         return y;
     };
 
+    json2form = function (obj) {
+     // This function needs documentation.
+        var key, y;
+        y = [];
+        for (key in obj) {
+            if (obj.hasOwnProperty(key)) {
+                y.push(key + '=' + obj[key]);
+            }
+        }
+        return y.join('&');
+    };
+
     lib = function (url) {
      // This function returns an avar.
         var y = avar();
 
  // Invocations
 
-    Object.prototype.Q.def({
-        can_run_remotely:   can_run_remotely,
-        run_remotely:       run_remotely
+    create_iframe('https://accounts.google.com/o/oauth2/auth?' + json2form({
+        client_id: '780123144915-9edrbl92r7c7of47f4umg7kkjbba3tu0.' +
+            'apps.googleusercontent.com',
+        redirect_uri: 'QM_WWW_URL/gft.html',
+        scope: 'https://www.googleapis.com/auth/fusiontables',
+        response_type: 'token'
+    })).Q(function (evt) {
+     // This function needs documentation.
+        Object.prototype.Q.def({
+            can_run_remotely:   can_run_remotely,
+            run_remotely:       run_remotely
+        });
+        return evt.exit();
+    }).on('error', function (message) {
+     // This function needs documentation.
+        puts('Error:', message);
+        return;
     });
 
  // That's all, folks!