{"action":"created","comment":{"url":"https://api.github.com/repos/caalberts/code-hangout/pulls/comments/49407604","id":49407604,"diff_hunk":"@@ -29,3 +27,79 @@ Meteor.publish('userData', function(){\n     return user\n   }\n })\n+\n+Meteor.methods({\n+  retrieveGistFiles: function (id) {\n+    // retrieve each gist\n+    const url = 'https://api.github.com/gists/' + id\n+    const opts = {\n+      headers: { Authorization: 'token ' + Meteor.user().services.github.accessToken }\n+    }\n+    console.log('fetching ', url, opts)\n+    fetch(url, opts)\n+      .then(res => res.json())\n+      .then(gist => {\n+        console.log('received gist')\n+        const obj = {\n+          gistId: gist.id,\n+          url: gist.url,\n+          description: gist.description,\n+          owner: gist.owner,\n+          ownerId: Meteor.userId(),\n+          files: Object.keys(gist.files),\n+          created_at: gist.created_at,\n+          updated_at: gist.updated_at\n+        }\n+        // save each gist into db\n+        Gists.upsert({ gistId: id }, obj)\n+        // save each file into db\n+        Object.keys(gist.files).forEach(file => {\n+          const fileObj = Object.assign(gist.files[file], { gistId: id })\n+          Files.upsert({\n+            $and: [\n+              { filename: file },\n+              { gistId: id }\n+            ]\n+          }, fileObj)\n+        })\n+      })\n+  },\n+\n+  updateGist: function (gistId, filename, updateContent) {\n+    const url = 'https://api.github.com/gists/' + gistId\n+    const opts = {\n+      method: 'PATCH',\n+      headers: { Authorization: 'token ' + Meteor.user().services.github.accessToken },\n+      body: JSON.stringify(updateContent)\n+    }\n+    Files.update(\n+      { filename: filename },\n+      { $set: { content: updateContent.files[filename].content } }\n+    )\n+    fetch(url, opts).then(res => console.log('success'))\n+      .catch(console.error)\n+  },\n+\n+  addEditingUser: function(){\n+    var doc, user, eusers\n+    doc = Documents.findOne()\n+    if (!doc){\n+      return\n+    }\n+    if (!this.userId){\n+      return\n+    }\n+    user = Meteor.user().profile\n+    eusers = EditingUsers.findOne({docid:doc._id})\n+    if (!eusers) {\n+      eusers = {","path":"server/server.js","position":101,"original_position":101,"commit_id":"d90e6b6765b7f7f3b312f8b8b29bb68fe39808a1","original_commit_id":"d90e6b6765b7f7f3b312f8b8b29bb68fe39808a1","user":{"login":"cbas","id":78718,"avatar_url":"https://avatars.githubusercontent.com/u/78718?v=3","gravatar_id":"","url":"https://api.github.com/users/cbas","html_url":"https://github.com/cbas","followers_url":"https://api.github.com/users/cbas/followers","following_url":"https://api.github.com/users/cbas/following{/other_user}","gists_url":"https://api.github.com/users/cbas/gists{/gist_id}","starred_url":"https://api.github.com/users/cbas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbas/subscriptions","organizations_url":"https://api.github.com/users/cbas/orgs","repos_url":"https://api.github.com/users/cbas/repos","events_url":"https://api.github.com/users/cbas/events{/privacy}","received_events_url":"https://api.github.com/users/cbas/received_events","type":"User","site_admin":false},"body":"Avoid variable re-assignment. Can use `||` instead?","created_at":"2016-01-12T02:02:16Z","updated_at":"2016-01-12T02:02:16Z","html_url":"https://github.com/caalberts/code-hangout/pull/5#discussion_r49407604","pull_request_url":"https://api.github.com/repos/caalberts/code-hangout/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/caalberts/code-hangout/pulls/comments/49407604"},"html":{"href":"https://github.com/caalberts/code-hangout/pull/5#discussion_r49407604"},"pull_request":{"href":"https://api.github.com/repos/caalberts/code-hangout/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/caalberts/code-hangout/pulls/5","id":55602937,"html_url":"https://github.com/caalberts/code-hangout/pull/5","diff_url":"https://github.com/caalberts/code-hangout/pull/5.diff","patch_url":"https://github.com/caalberts/code-hangout/pull/5.patch","issue_url":"https://api.github.com/repos/caalberts/code-hangout/issues/5","number":5,"state":"open","locked":false,"title":"PR for review","user":{"login":"caalberts","id":4749355,"avatar_url":"https://avatars.githubusercontent.com/u/4749355?v=3","gravatar_id":"","url":"https://api.github.com/users/caalberts","html_url":"https://github.com/caalberts","followers_url":"https://api.github.com/users/caalberts/followers","following_url":"https://api.github.com/users/caalberts/following{/other_user}","gists_url":"https://api.github.com/users/caalberts/gists{/gist_id}","starred_url":"https://api.github.com/users/caalberts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caalberts/subscriptions","organizations_url":"https://api.github.com/users/caalberts/orgs","repos_url":"https://api.github.com/users/caalberts/repos","events_url":"https://api.github.com/users/caalberts/events{/privacy}","received_events_url":"https://api.github.com/users/caalberts/received_events","type":"User","site_admin":false},"body":"@calvintan @cbas","created_at":"2016-01-11T09:58:42Z","updated_at":"2016-01-12T02:02:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c3510a86aa70ee11eb713dbeb0af640f9e974ba8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/caalberts/code-hangout/pulls/5/commits","review_comments_url":"https://api.github.com/repos/caalberts/code-hangout/pulls/5/comments","review_comment_url":"https://api.github.com/repos/caalberts/code-hangout/pulls/comments{/number}","comments_url":"https://api.github.com/repos/caalberts/code-hangout/issues/5/comments","statuses_url":"https://api.github.com/repos/caalberts/code-hangout/statuses/d90e6b6765b7f7f3b312f8b8b29bb68fe39808a1","head":{"label":"caalberts:dev","ref":"dev","sha":"d90e6b6765b7f7f3b312f8b8b29bb68fe39808a1","user":{"login":"caalberts","id":4749355,"avatar_url":"https://avatars.githubusercontent.com/u/4749355?v=3","gravatar_id":"","url":"https://api.github.com/users/caalberts","html_url":"https://github.com/caalberts","followers_url":"https://api.github.com/users/caalberts/followers","following_url":"https://api.github.com/users/caalberts/following{/other_user}","gists_url":"https://api.github.com/users/caalberts/gists{/gist_id}","starred_url":"https://api.github.com/users/caalberts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caalberts/subscriptions","organizations_url":"https://api.github.com/users/caalberts/orgs","repos_url":"https://api.github.com/users/caalberts/repos","events_url":"https://api.github.com/users/caalberts/events{/privacy}","received_events_url":"https://api.github.com/users/caalberts/received_events","type":"User","site_admin":false},"repo":{"id":49245317,"name":"code-hangout","full_name":"caalberts/code-hangout","owner":{"login":"caalberts","id":4749355,"avatar_url":"https://avatars.githubusercontent.com/u/4749355?v=3","gravatar_id":"","url":"https://api.github.com/users/caalberts","html_url":"https://github.com/caalberts","followers_url":"https://api.github.com/users/caalberts/followers","following_url":"https://api.github.com/users/caalberts/following{/other_user}","gists_url":"https://api.github.com/users/caalberts/gists{/gist_id}","starred_url":"https://api.github.com/users/caalberts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caalberts/subscriptions","organizations_url":"https://api.github.com/users/caalberts/orgs","repos_url":"https://api.github.com/users/caalberts/repos","events_url":"https://api.github.com/users/caalberts/events{/privacy}","received_events_url":"https://api.github.com/users/caalberts/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/caalberts/code-hangout","description":"","fork":false,"url":"https://api.github.com/repos/caalberts/code-hangout","forks_url":"https://api.github.com/repos/caalberts/code-hangout/forks","keys_url":"https://api.github.com/repos/caalberts/code-hangout/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caalberts/code-hangout/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caalberts/code-hangout/teams","hooks_url":"https://api.github.com/repos/caalberts/code-hangout/hooks","issue_events_url":"https://api.github.com/repos/caalberts/code-hangout/issues/events{/number}","events_url":"https://api.github.com/repos/caalberts/code-hangout/events","assignees_url":"https://api.github.com/repos/caalberts/code-hangout/assignees{/user}","branches_url":"https://api.github.com/repos/caalberts/code-hangout/branches{/branch}","tags_url":"https://api.github.com/repos/caalberts/code-hangout/tags","blobs_url":"https://api.github.com/repos/caalberts/code-hangout/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caalberts/code-hangout/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caalberts/code-hangout/git/refs{/sha}","trees_url":"https://api.github.com/repos/caalberts/code-hangout/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caalberts/code-hangout/statuses/{sha}","languages_url":"https://api.github.com/repos/caalberts/code-hangout/languages","stargazers_url":"https://api.github.com/repos/caalberts/code-hangout/stargazers","contributors_url":"https://api.github.com/repos/caalberts/code-hangout/contributors","subscribers_url":"https://api.github.com/repos/caalberts/code-hangout/subscribers","subscription_url":"https://api.github.com/repos/caalberts/code-hangout/subscription","commits_url":"https://api.github.com/repos/caalberts/code-hangout/commits{/sha}","git_commits_url":"https://api.github.com/repos/caalberts/code-hangout/git/commits{/sha}","comments_url":"https://api.github.com/repos/caalberts/code-hangout/comments{/number}","issue_comment_url":"https://api.github.com/repos/caalberts/code-hangout/issues/comments{/number}","contents_url":"https://api.github.com/repos/caalberts/code-hangout/contents/{+path}","compare_url":"https://api.github.com/repos/caalberts/code-hangout/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caalberts/code-hangout/merges","archive_url":"https://api.github.com/repos/caalberts/code-hangout/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caalberts/code-hangout/downloads","issues_url":"https://api.github.com/repos/caalberts/code-hangout/issues{/number}","pulls_url":"https://api.github.com/repos/caalberts/code-hangout/pulls{/number}","milestones_url":"https://api.github.com/repos/caalberts/code-hangout/milestones{/number}","notifications_url":"https://api.github.com/repos/caalberts/code-hangout/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caalberts/code-hangout/labels{/name}","releases_url":"https://api.github.com/repos/caalberts/code-hangout/releases{/id}","created_at":"2016-01-08T02:54:38Z","updated_at":"2016-01-11T07:05:00Z","pushed_at":"2016-01-11T21:51:12Z","git_url":"git://github.com/caalberts/code-hangout.git","ssh_url":"git@github.com:caalberts/code-hangout.git","clone_url":"https://github.com/caalberts/code-hangout.git","svn_url":"https://github.com/caalberts/code-hangout","homepage":null,"size":17,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":4,"forks":2,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"caalberts:master","ref":"master","sha":"9e8462111bbca4b1b450d9c38907bb3d50dd98e4","user":{"login":"caalberts","id":4749355,"avatar_url":"https://avatars.githubusercontent.com/u/4749355?v=3","gravatar_id":"","url":"https://api.github.com/users/caalberts","html_url":"https://github.com/caalberts","followers_url":"https://api.github.com/users/caalberts/followers","following_url":"https://api.github.com/users/caalberts/following{/other_user}","gists_url":"https://api.github.com/users/caalberts/gists{/gist_id}","starred_url":"https://api.github.com/users/caalberts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caalberts/subscriptions","organizations_url":"https://api.github.com/users/caalberts/orgs","repos_url":"https://api.github.com/users/caalberts/repos","events_url":"https://api.github.com/users/caalberts/events{/privacy}","received_events_url":"https://api.github.com/users/caalberts/received_events","type":"User","site_admin":false},"repo":{"id":49245317,"name":"code-hangout","full_name":"caalberts/code-hangout","owner":{"login":"caalberts","id":4749355,"avatar_url":"https://avatars.githubusercontent.com/u/4749355?v=3","gravatar_id":"","url":"https://api.github.com/users/caalberts","html_url":"https://github.com/caalberts","followers_url":"https://api.github.com/users/caalberts/followers","following_url":"https://api.github.com/users/caalberts/following{/other_user}","gists_url":"https://api.github.com/users/caalberts/gists{/gist_id}","starred_url":"https://api.github.com/users/caalberts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caalberts/subscriptions","organizations_url":"https://api.github.com/users/caalberts/orgs","repos_url":"https://api.github.com/users/caalberts/repos","events_url":"https://api.github.com/users/caalberts/events{/privacy}","received_events_url":"https://api.github.com/users/caalberts/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/caalberts/code-hangout","description":"","fork":false,"url":"https://api.github.com/repos/caalberts/code-hangout","forks_url":"https://api.github.com/repos/caalberts/code-hangout/forks","keys_url":"https://api.github.com/repos/caalberts/code-hangout/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caalberts/code-hangout/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caalberts/code-hangout/teams","hooks_url":"https://api.github.com/repos/caalberts/code-hangout/hooks","issue_events_url":"https://api.github.com/repos/caalberts/code-hangout/issues/events{/number}","events_url":"https://api.github.com/repos/caalberts/code-hangout/events","assignees_url":"https://api.github.com/repos/caalberts/code-hangout/assignees{/user}","branches_url":"https://api.github.com/repos/caalberts/code-hangout/branches{/branch}","tags_url":"https://api.github.com/repos/caalberts/code-hangout/tags","blobs_url":"https://api.github.com/repos/caalberts/code-hangout/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caalberts/code-hangout/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caalberts/code-hangout/git/refs{/sha}","trees_url":"https://api.github.com/repos/caalberts/code-hangout/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caalberts/code-hangout/statuses/{sha}","languages_url":"https://api.github.com/repos/caalberts/code-hangout/languages","stargazers_url":"https://api.github.com/repos/caalberts/code-hangout/stargazers","contributors_url":"https://api.github.com/repos/caalberts/code-hangout/contributors","subscribers_url":"https://api.github.com/repos/caalberts/code-hangout/subscribers","subscription_url":"https://api.github.com/repos/caalberts/code-hangout/subscription","commits_url":"https://api.github.com/repos/caalberts/code-hangout/commits{/sha}","git_commits_url":"https://api.github.com/repos/caalberts/code-hangout/git/commits{/sha}","comments_url":"https://api.github.com/repos/caalberts/code-hangout/comments{/number}","issue_comment_url":"https://api.github.com/repos/caalberts/code-hangout/issues/comments{/number}","contents_url":"https://api.github.com/repos/caalberts/code-hangout/contents/{+path}","compare_url":"https://api.github.com/repos/caalberts/code-hangout/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caalberts/code-hangout/merges","archive_url":"https://api.github.com/repos/caalberts/code-hangout/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caalberts/code-hangout/downloads","issues_url":"https://api.github.com/repos/caalberts/code-hangout/issues{/number}","pulls_url":"https://api.github.com/repos/caalberts/code-hangout/pulls{/number}","milestones_url":"https://api.github.com/repos/caalberts/code-hangout/milestones{/number}","notifications_url":"https://api.github.com/repos/caalberts/code-hangout/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caalberts/code-hangout/labels{/name}","releases_url":"https://api.github.com/repos/caalberts/code-hangout/releases{/id}","created_at":"2016-01-08T02:54:38Z","updated_at":"2016-01-11T07:05:00Z","pushed_at":"2016-01-11T21:51:12Z","git_url":"git://github.com/caalberts/code-hangout.git","ssh_url":"git@github.com:caalberts/code-hangout.git","clone_url":"https://github.com/caalberts/code-hangout.git","svn_url":"https://github.com/caalberts/code-hangout","homepage":null,"size":17,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":4,"forks":2,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/caalberts/code-hangout/pulls/5"},"html":{"href":"https://github.com/caalberts/code-hangout/pull/5"},"issue":{"href":"https://api.github.com/repos/caalberts/code-hangout/issues/5"},"comments":{"href":"https://api.github.com/repos/caalberts/code-hangout/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/caalberts/code-hangout/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/caalberts/code-hangout/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/caalberts/code-hangout/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/caalberts/code-hangout/statuses/d90e6b6765b7f7f3b312f8b8b29bb68fe39808a1"}}}}