{"action":"created","comment":{"url":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/comments/31855996","id":31855996,"diff_hunk":"@@ -96,438 +90,395 @@ define(function(require) {\n             path: path,\n             created: resource['createdDate'],\n             last_modified: resource['modifiedDate'],\n-            content : model_content,\n-            writable : resource['editable']\n+            content: model_content,\n+            writable: resource['editable']\n         };\n     };\n-\n-    /**\n-     * Takes a contents model and converts it into metadata and bytes for\n-     * Google Drive upload.\n-     */\n-    var contents_model_to_metadata_and_bytes = function(model) {\n-        var content = model.content;\n-        var mimetype = model.mimetype;\n-        var format = model.format;\n-        if (model['type'] === 'notebook') {\n-            content = notebook_model.file_contents_from_notebook(content);\n-            format = 'json';\n-            mimetype = drive_utils.NOTEBOOK_MIMETYPE;\n-        } else if (model['type'] === 'file') {\n-            format = format || 'text/plain';\n-        } else if (model['type'] === 'directory') {\n-            format = 'json'\n-            mimetype = drive_utils.FOLDER_MIME_TYPE;\n-        } else {\n-            throw (\"Unrecognized type \" + model['type']);\n-        }\n-\n-        // Set mimetype according to format if it's not set\n-        if (format == 'json') {\n-            content = JSON.stringify(content);\n-            mimetype = mimetype || 'application/json';\n-        } else if (format == 'base64') {\n-            mimetype = mimetype || 'application/octet-stream';\n-        } else if (format == 'text') {\n-            mimetype = mimetype || 'text/plain';\n-        } else {\n-            throw (\"Unrecognized format \" + format)\n-        }\n-\n-        var metadata = {\n-            'title' : model['name'],\n-            'mimeType' : mimetype\n-        };\n-\n-        return [metadata, content];\n-    }\n-\n-    /**\n-     * Saves a version of an existing file on drive\n-     * @param {Object} resource The Drive resource representing the file\n-     * @param {Object} model The IPython model object to be saved\n-     * @return {Promise} A promise fullfilled with the resource of the saved file.\n-     */\n-    Contents.prototype.save_existing = function(resource, model) {\n-        var that = this;\n-        var converted = contents_model_to_metadata_and_bytes(model);\n-        var contents = converted[1];\n-        var save = function() {\n-            return drive_utils.upload_to_drive(contents, undefined, resource['id']);\n-        };\n-        if (resource['headRevisionId'] !=\n-            that.last_observed_revision[resource['id']]) {\n-            // The revision id of the files resource does not match the\n-            // cached revision id for this file.  This implies that the\n-            // file has been modified by another user/tab during this\n-            // session.  Before saving, the user must be warned that they\n-            // may be overwriting the work of another user.\n-            return new Promise(function(resolve, reject) {\n-                var options = {\n-                    title: 'File modified by other user',\n-                    body: ('Another user has modified this file.  Click'\n-                           + ' ok to overwrite this file with your'\n-                           + ' content.'),\n-                    buttons: {\n-                        'ok': { click : function() { resolve(save()); },\n-                              },\n-                        'cancel': { click : function() { reject(new Error('save cancelled')); } }\n-                    }\n-                };\n-                dialog.modal(options);\n-            });\n-        }\n-        return save();\n-    }\n-\n     /**\n-     * Uploads a model to drive\n-     * @param {string} folder_id The id of the folder to create the file in\n-     * @param {Object} model The IPython model object to be saved\n-     * @return {Promise} A promise fullfilled with the resource of the saved file.\n-     */\n-    Contents.prototype.upload_new = function(folder_id, model) {\n-        var that = this;\n-\n-        var converted = contents_model_to_metadata_and_bytes(model);\n-        var metadata = converted[0];\n-        var contents = converted[1];\n-        metadata['parents'] = [{'id' : folder_id}];\n-\n-        if (model['type'] === 'directory') {\n-            return gapi_utils.execute(gapi.client.drive.files.insert({'resource': metadata}));\n-        } else {\n-            return drive_utils.upload_to_drive(contents, metadata);\n-        }\n-    }\n-\n-    /**\n-     * Notebook Functions\n-     */\n-\n-    /**\n-     * Load a notebook.\n      *\n-     * Calls success_callback with notebook JSON object (as string), or\n-     * options.error with error.\n+     * Implement a contents manager that talks to Google Drive.  Expose itself also\n+     * as `Contents` to be able to by transparently dynamically loaded and replace\n+     * any other contents manager that expose the `IContents` interface.\n      *\n-     * @method load_notebook\n-     * @param {String} path\n-     * @param {String} name\n-     * @param {Object} options\n-     */\n-    Contents.prototype.get = function (path, options) {\n-        var that = this;\n-        var metadata_prm = gapi_utils.gapi_ready.then(\n-            $.proxy(drive_utils.get_resource_for_path, this, path, drive_utils.FileType.FILE));\n-        var contents_prm = metadata_prm.then(function(resource) {\n-            that.observe_file_resource(resource);\n-            return drive_utils.get_contents(resource, false);\n-        });\n-\n-        return Promise.all([metadata_prm, contents_prm]).then(function(values) {\n-            var metadata = values[0];\n-            var contents = values[1];\n-            var model = files_resource_to_contents_model(path, metadata, contents);\n-            return model;\n-        });\n-    };\n-\n-\n-    /**\n-     * Creates a new untitled file or directory in the specified directory path.\n+     * For a higher level description on how to use these interfaces, see the\n+     * `IContents` interface docs\n      *\n-     * @method new\n-     * @param {String} path: the directory in which to create the new file/directory\n-     * @param {Object} options:\n-     *      ext: file extension to use\n-     *      type: model type to create ('notebook', 'file', or 'directory')\n-     */\n-    Contents.prototype.new_untitled = function(path, options) {\n-        // Construct all data needed to upload file\n-        var default_ext = '';\n-        var base_name = '';\n-        var model = null;\n-        if (options['type'] === 'notebook') {\n-            default_ext = '.ipynb';\n-            base_name = 'Untitled'\n-            model = {\n-                'type': 'notebook',\n-                'content': notebook_model.new_notebook(),\n-                'mimetype': drive_utils.NOTEBOOK_MIMETYPE,\n-                'format': 'json'\n-            };\n-        } else if (options['type'] === 'file') {\n-            default_ext = '.txt';\n-            base_name = 'Untitled';\n-            model = {\n-                'type': 'file',\n-                'content': '',\n-                'mimetype': 'text/plain',\n-                'format': 'text'\n+     **/\n+    var GoogleDriveContents = (function () {\n+        /**\n+         *\n+         * A contentmanager handles passing file operations\n+         * to the back-end.  This includes checkpointing\n+         * with the normal file operations.\n+         *\n+         * Parameters:\n+         *  options: dictionary\n+         *      Dictionary of keyword arguments.\n+         *          base_url: string\n+         **/\n+        function GoogleDriveContents(options) {\n+            var _this = this;\n+            this._base_url = options.base_url;\n+            this._config = options.common_config;\n+            /**\n+             * Stores the revision id from the last save or load.  This is used\n+             * when checking if a file has been modified by another user.\n+             */\n+            this._last_observed_revision = {};\n+            var that = this;\n+            this._config.loaded.then(function (data) {\n+                gapiutils.config(_this._config);\n+                gapiutils.gapi_ready.then(driveutils.set_user_info);\n+            });\n+        }\n+        /**\n+         * Utility functions\n+         */\n+        /**","path":"jupyterdrive/gdrive/drive-contents.js","position":null,"original_position":359,"commit_id":"23d7915380950627ee9ad0ba40bb0194217e9a11","original_commit_id":"1fc8a10311b6d596791673f71b8651f896a49dcd","user":{"login":"Carreau","id":335567,"avatar_url":"https://avatars.githubusercontent.com/u/335567?v=3","gravatar_id":"","url":"https://api.github.com/users/Carreau","html_url":"https://github.com/Carreau","followers_url":"https://api.github.com/users/Carreau/followers","following_url":"https://api.github.com/users/Carreau/following{/other_user}","gists_url":"https://api.github.com/users/Carreau/gists{/gist_id}","starred_url":"https://api.github.com/users/Carreau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Carreau/subscriptions","organizations_url":"https://api.github.com/users/Carreau/orgs","repos_url":"https://api.github.com/users/Carreau/repos","events_url":"https://api.github.com/users/Carreau/events{/privacy}","received_events_url":"https://api.github.com/users/Carreau/received_events","type":"User","site_admin":false},"body":"Fixed though.","created_at":"2015-06-05T22:09:05Z","updated_at":"2015-06-05T22:09:05Z","html_url":"https://github.com/jupyter/jupyter-drive/pull/118#discussion_r31855996","pull_request_url":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/118","_links":{"self":{"href":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/comments/31855996"},"html":{"href":"https://github.com/jupyter/jupyter-drive/pull/118#discussion_r31855996"},"pull_request":{"href":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/118"}}},"pull_request":{"url":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/118","id":37070330,"html_url":"https://github.com/jupyter/jupyter-drive/pull/118","diff_url":"https://github.com/jupyter/jupyter-drive/pull/118.diff","patch_url":"https://github.com/jupyter/jupyter-drive/pull/118.patch","issue_url":"https://api.github.com/repos/jupyter/jupyter-drive/issues/118","number":118,"state":"open","locked":false,"title":"All in Typescript","user":{"login":"Carreau","id":335567,"avatar_url":"https://avatars.githubusercontent.com/u/335567?v=3","gravatar_id":"","url":"https://api.github.com/users/Carreau","html_url":"https://github.com/Carreau","followers_url":"https://api.github.com/users/Carreau/followers","following_url":"https://api.github.com/users/Carreau/following{/other_user}","gists_url":"https://api.github.com/users/Carreau/gists{/gist_id}","starred_url":"https://api.github.com/users/Carreau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Carreau/subscriptions","organizations_url":"https://api.github.com/users/Carreau/orgs","repos_url":"https://api.github.com/users/Carreau/repos","events_url":"https://api.github.com/users/Carreau/events{/privacy}","received_events_url":"https://api.github.com/users/Carreau/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-06-05T21:09:05Z","updated_at":"2015-06-05T22:09:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e484bc6f6d14981b7cad3643c8dd56724a51ca14","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/118/commits","review_comments_url":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/118/comments","review_comment_url":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jupyter/jupyter-drive/issues/118/comments","statuses_url":"https://api.github.com/repos/jupyter/jupyter-drive/statuses/23d7915380950627ee9ad0ba40bb0194217e9a11","head":{"label":"Carreau:typescript","ref":"typescript","sha":"23d7915380950627ee9ad0ba40bb0194217e9a11","user":{"login":"Carreau","id":335567,"avatar_url":"https://avatars.githubusercontent.com/u/335567?v=3","gravatar_id":"","url":"https://api.github.com/users/Carreau","html_url":"https://github.com/Carreau","followers_url":"https://api.github.com/users/Carreau/followers","following_url":"https://api.github.com/users/Carreau/following{/other_user}","gists_url":"https://api.github.com/users/Carreau/gists{/gist_id}","starred_url":"https://api.github.com/users/Carreau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Carreau/subscriptions","organizations_url":"https://api.github.com/users/Carreau/orgs","repos_url":"https://api.github.com/users/Carreau/repos","events_url":"https://api.github.com/users/Carreau/events{/privacy}","received_events_url":"https://api.github.com/users/Carreau/received_events","type":"User","site_admin":false},"repo":{"id":26858562,"name":"jupyter-drive","full_name":"Carreau/jupyter-drive","owner":{"login":"Carreau","id":335567,"avatar_url":"https://avatars.githubusercontent.com/u/335567?v=3","gravatar_id":"","url":"https://api.github.com/users/Carreau","html_url":"https://github.com/Carreau","followers_url":"https://api.github.com/users/Carreau/followers","following_url":"https://api.github.com/users/Carreau/following{/other_user}","gists_url":"https://api.github.com/users/Carreau/gists{/gist_id}","starred_url":"https://api.github.com/users/Carreau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Carreau/subscriptions","organizations_url":"https://api.github.com/users/Carreau/orgs","repos_url":"https://api.github.com/users/Carreau/repos","events_url":"https://api.github.com/users/Carreau/events{/privacy}","received_events_url":"https://api.github.com/users/Carreau/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Carreau/jupyter-drive","description":"Google drive for jupyter notebooks","fork":true,"url":"https://api.github.com/repos/Carreau/jupyter-drive","forks_url":"https://api.github.com/repos/Carreau/jupyter-drive/forks","keys_url":"https://api.github.com/repos/Carreau/jupyter-drive/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Carreau/jupyter-drive/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Carreau/jupyter-drive/teams","hooks_url":"https://api.github.com/repos/Carreau/jupyter-drive/hooks","issue_events_url":"https://api.github.com/repos/Carreau/jupyter-drive/issues/events{/number}","events_url":"https://api.github.com/repos/Carreau/jupyter-drive/events","assignees_url":"https://api.github.com/repos/Carreau/jupyter-drive/assignees{/user}","branches_url":"https://api.github.com/repos/Carreau/jupyter-drive/branches{/branch}","tags_url":"https://api.github.com/repos/Carreau/jupyter-drive/tags","blobs_url":"https://api.github.com/repos/Carreau/jupyter-drive/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Carreau/jupyter-drive/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Carreau/jupyter-drive/git/refs{/sha}","trees_url":"https://api.github.com/repos/Carreau/jupyter-drive/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Carreau/jupyter-drive/statuses/{sha}","languages_url":"https://api.github.com/repos/Carreau/jupyter-drive/languages","stargazers_url":"https://api.github.com/repos/Carreau/jupyter-drive/stargazers","contributors_url":"https://api.github.com/repos/Carreau/jupyter-drive/contributors","subscribers_url":"https://api.github.com/repos/Carreau/jupyter-drive/subscribers","subscription_url":"https://api.github.com/repos/Carreau/jupyter-drive/subscription","commits_url":"https://api.github.com/repos/Carreau/jupyter-drive/commits{/sha}","git_commits_url":"https://api.github.com/repos/Carreau/jupyter-drive/git/commits{/sha}","comments_url":"https://api.github.com/repos/Carreau/jupyter-drive/comments{/number}","issue_comment_url":"https://api.github.com/repos/Carreau/jupyter-drive/issues/comments{/number}","contents_url":"https://api.github.com/repos/Carreau/jupyter-drive/contents/{+path}","compare_url":"https://api.github.com/repos/Carreau/jupyter-drive/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Carreau/jupyter-drive/merges","archive_url":"https://api.github.com/repos/Carreau/jupyter-drive/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Carreau/jupyter-drive/downloads","issues_url":"https://api.github.com/repos/Carreau/jupyter-drive/issues{/number}","pulls_url":"https://api.github.com/repos/Carreau/jupyter-drive/pulls{/number}","milestones_url":"https://api.github.com/repos/Carreau/jupyter-drive/milestones{/number}","notifications_url":"https://api.github.com/repos/Carreau/jupyter-drive/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Carreau/jupyter-drive/labels{/name}","releases_url":"https://api.github.com/repos/Carreau/jupyter-drive/releases{/id}","created_at":"2014-11-19T11:35:31Z","updated_at":"2015-04-28T17:39:23Z","pushed_at":"2015-06-05T22:07:49Z","git_url":"git://github.com/Carreau/jupyter-drive.git","ssh_url":"git@github.com:Carreau/jupyter-drive.git","clone_url":"https://github.com/Carreau/jupyter-drive.git","svn_url":"https://github.com/Carreau/jupyter-drive","homepage":null,"size":1093,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jupyter:master","ref":"master","sha":"6773c08403a65bae032bd4ba15235184742144fb","user":{"login":"jupyter","id":7388996,"avatar_url":"https://avatars.githubusercontent.com/u/7388996?v=3","gravatar_id":"","url":"https://api.github.com/users/jupyter","html_url":"https://github.com/jupyter","followers_url":"https://api.github.com/users/jupyter/followers","following_url":"https://api.github.com/users/jupyter/following{/other_user}","gists_url":"https://api.github.com/users/jupyter/gists{/gist_id}","starred_url":"https://api.github.com/users/jupyter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jupyter/subscriptions","organizations_url":"https://api.github.com/users/jupyter/orgs","repos_url":"https://api.github.com/users/jupyter/repos","events_url":"https://api.github.com/users/jupyter/events{/privacy}","received_events_url":"https://api.github.com/users/jupyter/received_events","type":"Organization","site_admin":false},"repo":{"id":25882864,"name":"jupyter-drive","full_name":"jupyter/jupyter-drive","owner":{"login":"jupyter","id":7388996,"avatar_url":"https://avatars.githubusercontent.com/u/7388996?v=3","gravatar_id":"","url":"https://api.github.com/users/jupyter","html_url":"https://github.com/jupyter","followers_url":"https://api.github.com/users/jupyter/followers","following_url":"https://api.github.com/users/jupyter/following{/other_user}","gists_url":"https://api.github.com/users/jupyter/gists{/gist_id}","starred_url":"https://api.github.com/users/jupyter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jupyter/subscriptions","organizations_url":"https://api.github.com/users/jupyter/orgs","repos_url":"https://api.github.com/users/jupyter/repos","events_url":"https://api.github.com/users/jupyter/events{/privacy}","received_events_url":"https://api.github.com/users/jupyter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jupyter/jupyter-drive","description":"Google drive for jupyter notebooks","fork":false,"url":"https://api.github.com/repos/jupyter/jupyter-drive","forks_url":"https://api.github.com/repos/jupyter/jupyter-drive/forks","keys_url":"https://api.github.com/repos/jupyter/jupyter-drive/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jupyter/jupyter-drive/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jupyter/jupyter-drive/teams","hooks_url":"https://api.github.com/repos/jupyter/jupyter-drive/hooks","issue_events_url":"https://api.github.com/repos/jupyter/jupyter-drive/issues/events{/number}","events_url":"https://api.github.com/repos/jupyter/jupyter-drive/events","assignees_url":"https://api.github.com/repos/jupyter/jupyter-drive/assignees{/user}","branches_url":"https://api.github.com/repos/jupyter/jupyter-drive/branches{/branch}","tags_url":"https://api.github.com/repos/jupyter/jupyter-drive/tags","blobs_url":"https://api.github.com/repos/jupyter/jupyter-drive/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jupyter/jupyter-drive/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jupyter/jupyter-drive/git/refs{/sha}","trees_url":"https://api.github.com/repos/jupyter/jupyter-drive/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jupyter/jupyter-drive/statuses/{sha}","languages_url":"https://api.github.com/repos/jupyter/jupyter-drive/languages","stargazers_url":"https://api.github.com/repos/jupyter/jupyter-drive/stargazers","contributors_url":"https://api.github.com/repos/jupyter/jupyter-drive/contributors","subscribers_url":"https://api.github.com/repos/jupyter/jupyter-drive/subscribers","subscription_url":"https://api.github.com/repos/jupyter/jupyter-drive/subscription","commits_url":"https://api.github.com/repos/jupyter/jupyter-drive/commits{/sha}","git_commits_url":"https://api.github.com/repos/jupyter/jupyter-drive/git/commits{/sha}","comments_url":"https://api.github.com/repos/jupyter/jupyter-drive/comments{/number}","issue_comment_url":"https://api.github.com/repos/jupyter/jupyter-drive/issues/comments{/number}","contents_url":"https://api.github.com/repos/jupyter/jupyter-drive/contents/{+path}","compare_url":"https://api.github.com/repos/jupyter/jupyter-drive/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jupyter/jupyter-drive/merges","archive_url":"https://api.github.com/repos/jupyter/jupyter-drive/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jupyter/jupyter-drive/downloads","issues_url":"https://api.github.com/repos/jupyter/jupyter-drive/issues{/number}","pulls_url":"https://api.github.com/repos/jupyter/jupyter-drive/pulls{/number}","milestones_url":"https://api.github.com/repos/jupyter/jupyter-drive/milestones{/number}","notifications_url":"https://api.github.com/repos/jupyter/jupyter-drive/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jupyter/jupyter-drive/labels{/name}","releases_url":"https://api.github.com/repos/jupyter/jupyter-drive/releases{/id}","created_at":"2014-10-28T18:04:55Z","updated_at":"2015-05-29T20:01:50Z","pushed_at":"2015-06-05T22:07:49Z","git_url":"git://github.com/jupyter/jupyter-drive.git","ssh_url":"git@github.com:jupyter/jupyter-drive.git","clone_url":"https://github.com/jupyter/jupyter-drive.git","svn_url":"https://github.com/jupyter/jupyter-drive","homepage":null,"size":1924,"stargazers_count":62,"watchers_count":62,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":15,"forks":15,"open_issues":15,"watchers":62,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/118"},"html":{"href":"https://github.com/jupyter/jupyter-drive/pull/118"},"issue":{"href":"https://api.github.com/repos/jupyter/jupyter-drive/issues/118"},"comments":{"href":"https://api.github.com/repos/jupyter/jupyter-drive/issues/118/comments"},"review_comments":{"href":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/118/comments"},"review_comment":{"href":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jupyter/jupyter-drive/pulls/118/commits"},"statuses":{"href":"https://api.github.com/repos/jupyter/jupyter-drive/statuses/23d7915380950627ee9ad0ba40bb0194217e9a11"}}}}