{"action":"created","comment":{"url":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/comments/200850386","pull_request_review_id":135242482,"id":200850386,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMDg1MDM4Ng==","diff_hunk":"@@ -0,0 +1,272 @@\n+/*\n+Copyright 2018 Google LLC\n+\n+Licensed under the Apache License, Version 2.0 (the \"License\");\n+you may not use this file except in compliance with the License.\n+You may obtain a copy of the License at\n+\n+    http://www.apache.org/licenses/LICENSE-2.0\n+\n+Unless required by applicable law or agreed to in writing, software\n+distributed under the License is distributed on an \"AS IS\" BASIS,\n+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+See the License for the specific language governing permissions and\n+limitations under the License.\n+*/\n+\n+/** \n+ * Handles fetching data from Firestore. \n+ *\n+ * @constructor\n+ * @param {?string} email Optional service account email for auth.\n+ * @param {?string} key Optional private key for auth.\n+ */\n+function Firestore(email, key) {\n+  \n+  /** @const */\n+  this.PREDEFINED_FIELDS = [\n+    'name',\n+    'createTime',\n+    'updateTime'\n+  ];\n+  \n+  /** @const */\n+  this.PAGE_SIZE = 100;\n+  \n+  /** @const */\n+  this.RETRIES = 3;\n+  \n+  /** @const */\n+  this.CACHE_TTL = 20; // seconds\n+  \n+  /** @const */\n+  this.AUTH_URL = 'https://www.googleapis.com/oauth2/v4/token/';\n+  \n+  this.cache = CacheService.getScriptCache();\n+  \n+  this.authToken = null;\n+  if (email && key) {\n+    this.authToken = this.getAuthToken(email, key);\n+  }\n+}\n+\n+\n+// TODO: Add support for other field types and nested collections.\n+/**\n+ * Fetches documents from Firestore and parses fields based on schema.\n+ *\n+ * @param {string} project The Google Cloud project ID containing Firestore instance.\n+ * @param {string} collection The Firestore collection to use.\n+ * @param {Object} schema The set of fields for which to retrieve data.\n+ * @param {number} numResults Maximum documents to fetch.\n+ * @return {Array} Tabular data for fields matching schema.\n+ */\n+Firestore.prototype.getData = function(project, collection, schema, numResults) {\n+  const documents = this.fetchDocuments(project, collection, numResults);\n+    \n+  var data = [];\n+  const instance = this;\n+  documents.forEach(function(document) {\n+    var values = [];\n+    // Provide values in the order defined by the schema.\n+    schema.forEach(function(field) {\n+      if (instance.PREDEFINED_FIELDS.indexOf(field.name) >= 0) {\n+        var value = document[field.name];\n+        switch(field.name) {\n+          case 'createTime':\n+          case 'updateTime':\n+            values.push(instance.parseTimestamp(value));\n+            break;\n+          case 'name':\n+            values.push(instance.parseDocumentId(value));\n+            break;\n+          default:\n+            values.push(value);\n+        }\n+      } else {\n+        const valueWrapper = document.fields[field.name];\n+        if (valueWrapper) {\n+          switch(field.dataType) {\n+            case 'STRING':\n+              if (field.semantics && field.semantics.semanticGroup == 'DATE_AND_TIME') {\n+                values.push(instance.parseTimestamp(valueWrapper.timestampValue)); \n+              } else {\n+                values.push(valueWrapper.stringValue);\n+              }\n+              break;\n+            case 'NUMBER':\n+              if (valueWrapper.integerValue != null) {\n+                values.push(valueWrapper.integerValue);\n+              } else {\n+                values.push(valueWrapper.doubleValue);\n+              }\n+              break;\n+            case 'BOOLEAN':\n+              values.push(valueWrapper.booleanValue);\n+              break;\n+            default:\n+              throw 'Unsupported data type: ' + field.dataType;    \n+          }\n+        } else {\n+          values.push(null); \n+        }\n+      }\n+    });\n+    data.push({\n+      values: values\n+    });\n+  });\n+  \n+  return data;\n+}\n+\n+\n+/**\n+ * Fetches documents from Firestore or cache.\n+ *\n+ * @param {string} project The Google Cloud project ID containing Firestore instance.\n+ * @param {string} collection The Firestore collection to use.\n+ * @param {number} numResults Maximum documents to fetch.\n+ * @return {Array} Array of Firestore documents.\n+ */\n+Firestore.prototype.fetchDocuments = function(project, collection, numResults) {\n+  const urlComponents = [\n+    'https://firestore.googleapis.com/v1beta1/projects/',\n+    project,\n+    '/databases/(default)/documents/',\n+    collection,\n+    '?pageSize=',\n+    this.PAGE_SIZE];\n+  const url = urlComponents.join('');\n+  \n+  const cached = this.cache.get(url);\n+  if (cached) {\n+    return JSON.parse(cached); \n+  }\n+  \n+  var documents = [];\n+  var token = null;\n+  while (documents.length < numResults) {\n+    var response = this.fetchPage(url, token);\n+    if (response.documents && response.documents.length > 0) {\n+      Array.prototype.push.apply(documents, response.documents);\n+    }\n+    if (response.nextPageToken && token != response.nextPageToken) {","path":"firestore/src/Firestore.gs","position":null,"original_position":154,"commit_id":"9e1c6ba523f81cb4167feb3e9e8a44ccd5c634a2","original_commit_id":"f93da2db8c29fca1aceb61b62b1c26bf9dd37173","user":{"login":"andrewbrook","id":11356729,"node_id":"MDQ6VXNlcjExMzU2NzI5","avatar_url":"https://avatars0.githubusercontent.com/u/11356729?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewbrook","html_url":"https://github.com/andrewbrook","followers_url":"https://api.github.com/users/andrewbrook/followers","following_url":"https://api.github.com/users/andrewbrook/following{/other_user}","gists_url":"https://api.github.com/users/andrewbrook/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewbrook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewbrook/subscriptions","organizations_url":"https://api.github.com/users/andrewbrook/orgs","repos_url":"https://api.github.com/users/andrewbrook/repos","events_url":"https://api.github.com/users/andrewbrook/events{/privacy}","received_events_url":"https://api.github.com/users/andrewbrook/received_events","type":"User","site_admin":false},"body":"Fixed. The second part of condition is unnecessary.","created_at":"2018-07-08T19:14:57Z","updated_at":"2018-07-08T19:14:57Z","html_url":"https://github.com/googledatastudio/community-connectors/pull/31#discussion_r200850386","pull_request_url":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/31","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/comments/200850386"},"html":{"href":"https://github.com/googledatastudio/community-connectors/pull/31#discussion_r200850386"},"pull_request":{"href":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/31"}},"in_reply_to_id":197894300},"pull_request":{"url":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/31","id":194879408,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk0ODc5NDA4","html_url":"https://github.com/googledatastudio/community-connectors/pull/31","diff_url":"https://github.com/googledatastudio/community-connectors/pull/31.diff","patch_url":"https://github.com/googledatastudio/community-connectors/pull/31.patch","issue_url":"https://api.github.com/repos/googledatastudio/community-connectors/issues/31","number":31,"state":"open","locked":false,"title":"Firestore","user":{"login":"andrewbrook","id":11356729,"node_id":"MDQ6VXNlcjExMzU2NzI5","avatar_url":"https://avatars0.githubusercontent.com/u/11356729?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewbrook","html_url":"https://github.com/andrewbrook","followers_url":"https://api.github.com/users/andrewbrook/followers","following_url":"https://api.github.com/users/andrewbrook/following{/other_user}","gists_url":"https://api.github.com/users/andrewbrook/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewbrook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewbrook/subscriptions","organizations_url":"https://api.github.com/users/andrewbrook/orgs","repos_url":"https://api.github.com/users/andrewbrook/repos","events_url":"https://api.github.com/users/andrewbrook/events{/privacy}","received_events_url":"https://api.github.com/users/andrewbrook/received_events","type":"User","site_admin":false},"body":"Adding a community connector for Google Cloud Firestore. ","created_at":"2018-06-14T12:39:15Z","updated_at":"2018-07-08T19:14:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"df5c31901df4c086aafccfff3f914f91879118e7","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/31/commits","review_comments_url":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/31/comments","review_comment_url":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/comments{/number}","comments_url":"https://api.github.com/repos/googledatastudio/community-connectors/issues/31/comments","statuses_url":"https://api.github.com/repos/googledatastudio/community-connectors/statuses/9e1c6ba523f81cb4167feb3e9e8a44ccd5c634a2","head":{"label":"andrewbrook:firestore","ref":"firestore","sha":"9e1c6ba523f81cb4167feb3e9e8a44ccd5c634a2","user":{"login":"andrewbrook","id":11356729,"node_id":"MDQ6VXNlcjExMzU2NzI5","avatar_url":"https://avatars0.githubusercontent.com/u/11356729?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewbrook","html_url":"https://github.com/andrewbrook","followers_url":"https://api.github.com/users/andrewbrook/followers","following_url":"https://api.github.com/users/andrewbrook/following{/other_user}","gists_url":"https://api.github.com/users/andrewbrook/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewbrook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewbrook/subscriptions","organizations_url":"https://api.github.com/users/andrewbrook/orgs","repos_url":"https://api.github.com/users/andrewbrook/repos","events_url":"https://api.github.com/users/andrewbrook/events{/privacy}","received_events_url":"https://api.github.com/users/andrewbrook/received_events","type":"User","site_admin":false},"repo":{"id":136520261,"node_id":"MDEwOlJlcG9zaXRvcnkxMzY1MjAyNjE=","name":"community-connectors","full_name":"andrewbrook/community-connectors","owner":{"login":"andrewbrook","id":11356729,"node_id":"MDQ6VXNlcjExMzU2NzI5","avatar_url":"https://avatars0.githubusercontent.com/u/11356729?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewbrook","html_url":"https://github.com/andrewbrook","followers_url":"https://api.github.com/users/andrewbrook/followers","following_url":"https://api.github.com/users/andrewbrook/following{/other_user}","gists_url":"https://api.github.com/users/andrewbrook/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewbrook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewbrook/subscriptions","organizations_url":"https://api.github.com/users/andrewbrook/orgs","repos_url":"https://api.github.com/users/andrewbrook/repos","events_url":"https://api.github.com/users/andrewbrook/events{/privacy}","received_events_url":"https://api.github.com/users/andrewbrook/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andrewbrook/community-connectors","description":"This repository contains open source content for Google Data Studio.","fork":true,"url":"https://api.github.com/repos/andrewbrook/community-connectors","forks_url":"https://api.github.com/repos/andrewbrook/community-connectors/forks","keys_url":"https://api.github.com/repos/andrewbrook/community-connectors/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andrewbrook/community-connectors/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andrewbrook/community-connectors/teams","hooks_url":"https://api.github.com/repos/andrewbrook/community-connectors/hooks","issue_events_url":"https://api.github.com/repos/andrewbrook/community-connectors/issues/events{/number}","events_url":"https://api.github.com/repos/andrewbrook/community-connectors/events","assignees_url":"https://api.github.com/repos/andrewbrook/community-connectors/assignees{/user}","branches_url":"https://api.github.com/repos/andrewbrook/community-connectors/branches{/branch}","tags_url":"https://api.github.com/repos/andrewbrook/community-connectors/tags","blobs_url":"https://api.github.com/repos/andrewbrook/community-connectors/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andrewbrook/community-connectors/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andrewbrook/community-connectors/git/refs{/sha}","trees_url":"https://api.github.com/repos/andrewbrook/community-connectors/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andrewbrook/community-connectors/statuses/{sha}","languages_url":"https://api.github.com/repos/andrewbrook/community-connectors/languages","stargazers_url":"https://api.github.com/repos/andrewbrook/community-connectors/stargazers","contributors_url":"https://api.github.com/repos/andrewbrook/community-connectors/contributors","subscribers_url":"https://api.github.com/repos/andrewbrook/community-connectors/subscribers","subscription_url":"https://api.github.com/repos/andrewbrook/community-connectors/subscription","commits_url":"https://api.github.com/repos/andrewbrook/community-connectors/commits{/sha}","git_commits_url":"https://api.github.com/repos/andrewbrook/community-connectors/git/commits{/sha}","comments_url":"https://api.github.com/repos/andrewbrook/community-connectors/comments{/number}","issue_comment_url":"https://api.github.com/repos/andrewbrook/community-connectors/issues/comments{/number}","contents_url":"https://api.github.com/repos/andrewbrook/community-connectors/contents/{+path}","compare_url":"https://api.github.com/repos/andrewbrook/community-connectors/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andrewbrook/community-connectors/merges","archive_url":"https://api.github.com/repos/andrewbrook/community-connectors/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andrewbrook/community-connectors/downloads","issues_url":"https://api.github.com/repos/andrewbrook/community-connectors/issues{/number}","pulls_url":"https://api.github.com/repos/andrewbrook/community-connectors/pulls{/number}","milestones_url":"https://api.github.com/repos/andrewbrook/community-connectors/milestones{/number}","notifications_url":"https://api.github.com/repos/andrewbrook/community-connectors/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andrewbrook/community-connectors/labels{/name}","releases_url":"https://api.github.com/repos/andrewbrook/community-connectors/releases{/id}","deployments_url":"https://api.github.com/repos/andrewbrook/community-connectors/deployments","created_at":"2018-06-07T19:11:00Z","updated_at":"2018-06-07T19:11:02Z","pushed_at":"2018-07-08T19:13:23Z","git_url":"git://github.com/andrewbrook/community-connectors.git","ssh_url":"git@github.com:andrewbrook/community-connectors.git","clone_url":"https://github.com/andrewbrook/community-connectors.git","svn_url":"https://github.com/andrewbrook/community-connectors","homepage":"https://datastudio.google.com/","size":287,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"googledatastudio:master","ref":"master","sha":"ba476423d7fa2f1e36d35e3f7f5f5fdecd30162e","user":{"login":"googledatastudio","id":36164477,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2MTY0NDc3","avatar_url":"https://avatars2.githubusercontent.com/u/36164477?v=4","gravatar_id":"","url":"https://api.github.com/users/googledatastudio","html_url":"https://github.com/googledatastudio","followers_url":"https://api.github.com/users/googledatastudio/followers","following_url":"https://api.github.com/users/googledatastudio/following{/other_user}","gists_url":"https://api.github.com/users/googledatastudio/gists{/gist_id}","starred_url":"https://api.github.com/users/googledatastudio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/googledatastudio/subscriptions","organizations_url":"https://api.github.com/users/googledatastudio/orgs","repos_url":"https://api.github.com/users/googledatastudio/repos","events_url":"https://api.github.com/users/googledatastudio/events{/privacy}","received_events_url":"https://api.github.com/users/googledatastudio/received_events","type":"Organization","site_admin":false},"repo":{"id":106599370,"node_id":"MDEwOlJlcG9zaXRvcnkxMDY1OTkzNzA=","name":"community-connectors","full_name":"googledatastudio/community-connectors","owner":{"login":"googledatastudio","id":36164477,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2MTY0NDc3","avatar_url":"https://avatars2.githubusercontent.com/u/36164477?v=4","gravatar_id":"","url":"https://api.github.com/users/googledatastudio","html_url":"https://github.com/googledatastudio","followers_url":"https://api.github.com/users/googledatastudio/followers","following_url":"https://api.github.com/users/googledatastudio/following{/other_user}","gists_url":"https://api.github.com/users/googledatastudio/gists{/gist_id}","starred_url":"https://api.github.com/users/googledatastudio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/googledatastudio/subscriptions","organizations_url":"https://api.github.com/users/googledatastudio/orgs","repos_url":"https://api.github.com/users/googledatastudio/repos","events_url":"https://api.github.com/users/googledatastudio/events{/privacy}","received_events_url":"https://api.github.com/users/googledatastudio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/googledatastudio/community-connectors","description":"This repository contains open source content for Google Data Studio.","fork":false,"url":"https://api.github.com/repos/googledatastudio/community-connectors","forks_url":"https://api.github.com/repos/googledatastudio/community-connectors/forks","keys_url":"https://api.github.com/repos/googledatastudio/community-connectors/keys{/key_id}","collaborators_url":"https://api.github.com/repos/googledatastudio/community-connectors/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/googledatastudio/community-connectors/teams","hooks_url":"https://api.github.com/repos/googledatastudio/community-connectors/hooks","issue_events_url":"https://api.github.com/repos/googledatastudio/community-connectors/issues/events{/number}","events_url":"https://api.github.com/repos/googledatastudio/community-connectors/events","assignees_url":"https://api.github.com/repos/googledatastudio/community-connectors/assignees{/user}","branches_url":"https://api.github.com/repos/googledatastudio/community-connectors/branches{/branch}","tags_url":"https://api.github.com/repos/googledatastudio/community-connectors/tags","blobs_url":"https://api.github.com/repos/googledatastudio/community-connectors/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/googledatastudio/community-connectors/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/googledatastudio/community-connectors/git/refs{/sha}","trees_url":"https://api.github.com/repos/googledatastudio/community-connectors/git/trees{/sha}","statuses_url":"https://api.github.com/repos/googledatastudio/community-connectors/statuses/{sha}","languages_url":"https://api.github.com/repos/googledatastudio/community-connectors/languages","stargazers_url":"https://api.github.com/repos/googledatastudio/community-connectors/stargazers","contributors_url":"https://api.github.com/repos/googledatastudio/community-connectors/contributors","subscribers_url":"https://api.github.com/repos/googledatastudio/community-connectors/subscribers","subscription_url":"https://api.github.com/repos/googledatastudio/community-connectors/subscription","commits_url":"https://api.github.com/repos/googledatastudio/community-connectors/commits{/sha}","git_commits_url":"https://api.github.com/repos/googledatastudio/community-connectors/git/commits{/sha}","comments_url":"https://api.github.com/repos/googledatastudio/community-connectors/comments{/number}","issue_comment_url":"https://api.github.com/repos/googledatastudio/community-connectors/issues/comments{/number}","contents_url":"https://api.github.com/repos/googledatastudio/community-connectors/contents/{+path}","compare_url":"https://api.github.com/repos/googledatastudio/community-connectors/compare/{base}...{head}","merges_url":"https://api.github.com/repos/googledatastudio/community-connectors/merges","archive_url":"https://api.github.com/repos/googledatastudio/community-connectors/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/googledatastudio/community-connectors/downloads","issues_url":"https://api.github.com/repos/googledatastudio/community-connectors/issues{/number}","pulls_url":"https://api.github.com/repos/googledatastudio/community-connectors/pulls{/number}","milestones_url":"https://api.github.com/repos/googledatastudio/community-connectors/milestones{/number}","notifications_url":"https://api.github.com/repos/googledatastudio/community-connectors/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/googledatastudio/community-connectors/labels{/name}","releases_url":"https://api.github.com/repos/googledatastudio/community-connectors/releases{/id}","deployments_url":"https://api.github.com/repos/googledatastudio/community-connectors/deployments","created_at":"2017-10-11T19:24:04Z","updated_at":"2018-06-28T16:54:58Z","pushed_at":"2018-07-08T19:13:23Z","git_url":"git://github.com/googledatastudio/community-connectors.git","ssh_url":"git@github.com:googledatastudio/community-connectors.git","clone_url":"https://github.com/googledatastudio/community-connectors.git","svn_url":"https://github.com/googledatastudio/community-connectors","homepage":"https://datastudio.google.com/","size":1278,"stargazers_count":127,"watchers_count":127,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":35,"mirror_url":null,"archived":false,"open_issues_count":9,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":35,"open_issues":9,"watchers":127,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/31"},"html":{"href":"https://github.com/googledatastudio/community-connectors/pull/31"},"issue":{"href":"https://api.github.com/repos/googledatastudio/community-connectors/issues/31"},"comments":{"href":"https://api.github.com/repos/googledatastudio/community-connectors/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/googledatastudio/community-connectors/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/googledatastudio/community-connectors/statuses/9e1c6ba523f81cb4167feb3e9e8a44ccd5c634a2"}},"author_association":"NONE"}}
{"actor":{"display_login":"andrewbrook"}}