{"action":"created","comment":{"url":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/comments/75692257","id":75692257,"diff_hunk":"@@ -0,0 +1,92 @@\n+## A button to \"Fetch all\" customers from Hubspot\n+\n+Will fetch all customers from Hubspot, using Batching if needed, and store their properties in Hull customers, upserting those that already exist (found by email)\n+\n+```javascript\n+\n+// deps:\n+// this.hull\n+// this.hubspot\n+// this.mapping\n+// this.queue\n+\n+function fetchAllAction() {\n+    return this.getContacts();\n+}\n+\n+/**\n+ * Get 100 hubspot contacts and queues their import\n+ * and getting another 100 - needs to be processed in one queue without\n+ * any concurrency\n+ * @see http://developers.hubspot.com/docs/methods/contacts/get_contacts\n+ * @param  {Number} [count=100]\n+ * @param  {Number} [offset=0]\n+ * @return {Promise}\n+ */\n+function getContacts(count = 100, offset = 0) {\n+\n+    if (count > 100) {\n+        return this.hull.logger.error(\"getContact gets maximum of 100 contacts at once\", count);\n+    }\n+\n+    const properties = this.mapping.getProperties();\n+\n+    hubspot.get(\"/contacts/v1/lists/all/contacts/all\", {\n+        count,\n+        vidOffset: offset,\n+        property: properties\n+    }, (res) => {\n+        if (res[\"has-more\"]) {\n+            this.queue(\"getContacts\", count, res[\"vid-offset\"]);\n+        }\n+\n+        if (res.body.contacts > 0) {\n+            this.queue(\"importContacts\", res.contacts);\n+        }\n+    });\n+}\n+\n+/**\n+ * creates or updates users\n+ * @see https://www.hull.io/docs/references/api/#endpoint-identities-create-a-user-with-email-and-password\n+ * @see https://www.hull.io/docs/references/api/#endpoint-traits\n+ * @param  {Array} Hubspot contacts\n+ * @return {Promise}\n+ */\n+function importContacts(contacts) {\n+    return contact.map((c) => {\n+        const email = _.find(c.identities, { type: \"EMAIL\" }).value;\n+        (function() {\n+            if (!c.properties.hull_id) {\n+                // create hull user\n+                return this.hull.api('/users', 'post', {\n+                  \"email\": email,\n+                  \"password\": \"s3cr3t\"\n+                });\n+            }\n+            return Promise.resolve(c);\n+        })().then(c => {\n+            const traits = this.mapping.getTraits(c);\n+            return this.hull.as({ email }).traits(traits, { source: \"hubspot \"});\n+        })\n+\n+    });\n+}\n+\n+/**\n+ * Hubspot properies names\n+ * @return {Array}\n+ */\n+function getProperties() {\n+    return [\"property_name\", \"property2_name\"];\n+}\n+\n+function getTraits(userData) {\n+    return {\n+        trait_name: userData.properties.property_name.value,\n+        trait2_name: userData.properties.property2_name.value,\n+        vid: userData.properties.vid.value,","path":"fetchAllSpecs.md","position":88,"original_position":88,"commit_id":"1fd21e909710ba0c70bb3b8c43516e11e7fa5df2","original_commit_id":"1fd21e909710ba0c70bb3b8c43516e11e7fa5df2","user":{"login":"unity","id":9458,"avatar_url":"https://avatars.githubusercontent.com/u/9458?v=3","gravatar_id":"","url":"https://api.github.com/users/unity","html_url":"https://github.com/unity","followers_url":"https://api.github.com/users/unity/followers","following_url":"https://api.github.com/users/unity/following{/other_user}","gists_url":"https://api.github.com/users/unity/gists{/gist_id}","starred_url":"https://api.github.com/users/unity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unity/subscriptions","organizations_url":"https://api.github.com/users/unity/orgs","repos_url":"https://api.github.com/users/unity/repos","events_url":"https://api.github.com/users/unity/events{/privacy}","received_events_url":"https://api.github.com/users/unity/received_events","type":"User","site_admin":false},"body":"If this maps to the main User ID in Hubspot, I recommend we map this to `hubspot/id` so we can standardize retreival of IDs later","created_at":"2016-08-22T14:52:46Z","updated_at":"2016-08-22T14:52:46Z","html_url":"https://github.com/hull-ships/hull-hubspot/pull/1#discussion_r75692257","pull_request_url":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/comments/75692257"},"html":{"href":"https://github.com/hull-ships/hull-hubspot/pull/1#discussion_r75692257"},"pull_request":{"href":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/1","id":82198852,"html_url":"https://github.com/hull-ships/hull-hubspot/pull/1","diff_url":"https://github.com/hull-ships/hull-hubspot/pull/1.diff","patch_url":"https://github.com/hull-ships/hull-hubspot/pull/1.patch","issue_url":"https://api.github.com/repos/hull-ships/hull-hubspot/issues/1","number":1,"state":"open","locked":false,"title":"Specs for the main syncing features","user":{"login":"michaloo","id":1029525,"avatar_url":"https://avatars.githubusercontent.com/u/1029525?v=3","gravatar_id":"","url":"https://api.github.com/users/michaloo","html_url":"https://github.com/michaloo","followers_url":"https://api.github.com/users/michaloo/followers","following_url":"https://api.github.com/users/michaloo/following{/other_user}","gists_url":"https://api.github.com/users/michaloo/gists{/gist_id}","starred_url":"https://api.github.com/users/michaloo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaloo/subscriptions","organizations_url":"https://api.github.com/users/michaloo/orgs","repos_url":"https://api.github.com/users/michaloo/repos","events_url":"https://api.github.com/users/michaloo/events{/privacy}","received_events_url":"https://api.github.com/users/michaloo/received_events","type":"User","site_admin":false},"body":"Includes pseudocode specs for:\r\n\r\n- fetchAll (full import from Hubspot to Hull)\r\n- batch (export from Hull to Hubsport)\r\n- sync (regular sync from Hubspot to Hull)","created_at":"2016-08-22T14:16:29Z","updated_at":"2016-08-22T14:52:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b3cd500183bfb0aa5820fd27c299273c2cc0da0f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/1/commits","review_comments_url":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/1/comments","review_comment_url":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hull-ships/hull-hubspot/issues/1/comments","statuses_url":"https://api.github.com/repos/hull-ships/hull-hubspot/statuses/1fd21e909710ba0c70bb3b8c43516e11e7fa5df2","head":{"label":"michaloo:master","ref":"master","sha":"1fd21e909710ba0c70bb3b8c43516e11e7fa5df2","user":{"login":"michaloo","id":1029525,"avatar_url":"https://avatars.githubusercontent.com/u/1029525?v=3","gravatar_id":"","url":"https://api.github.com/users/michaloo","html_url":"https://github.com/michaloo","followers_url":"https://api.github.com/users/michaloo/followers","following_url":"https://api.github.com/users/michaloo/following{/other_user}","gists_url":"https://api.github.com/users/michaloo/gists{/gist_id}","starred_url":"https://api.github.com/users/michaloo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaloo/subscriptions","organizations_url":"https://api.github.com/users/michaloo/orgs","repos_url":"https://api.github.com/users/michaloo/repos","events_url":"https://api.github.com/users/michaloo/events{/privacy}","received_events_url":"https://api.github.com/users/michaloo/received_events","type":"User","site_admin":false},"repo":{"id":66005240,"name":"hull-hubspot","full_name":"michaloo/hull-hubspot","owner":{"login":"michaloo","id":1029525,"avatar_url":"https://avatars.githubusercontent.com/u/1029525?v=3","gravatar_id":"","url":"https://api.github.com/users/michaloo","html_url":"https://github.com/michaloo","followers_url":"https://api.github.com/users/michaloo/followers","following_url":"https://api.github.com/users/michaloo/following{/other_user}","gists_url":"https://api.github.com/users/michaloo/gists{/gist_id}","starred_url":"https://api.github.com/users/michaloo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaloo/subscriptions","organizations_url":"https://api.github.com/users/michaloo/orgs","repos_url":"https://api.github.com/users/michaloo/repos","events_url":"https://api.github.com/users/michaloo/events{/privacy}","received_events_url":"https://api.github.com/users/michaloo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/michaloo/hull-hubspot","description":null,"fork":true,"url":"https://api.github.com/repos/michaloo/hull-hubspot","forks_url":"https://api.github.com/repos/michaloo/hull-hubspot/forks","keys_url":"https://api.github.com/repos/michaloo/hull-hubspot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/michaloo/hull-hubspot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/michaloo/hull-hubspot/teams","hooks_url":"https://api.github.com/repos/michaloo/hull-hubspot/hooks","issue_events_url":"https://api.github.com/repos/michaloo/hull-hubspot/issues/events{/number}","events_url":"https://api.github.com/repos/michaloo/hull-hubspot/events","assignees_url":"https://api.github.com/repos/michaloo/hull-hubspot/assignees{/user}","branches_url":"https://api.github.com/repos/michaloo/hull-hubspot/branches{/branch}","tags_url":"https://api.github.com/repos/michaloo/hull-hubspot/tags","blobs_url":"https://api.github.com/repos/michaloo/hull-hubspot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/michaloo/hull-hubspot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/michaloo/hull-hubspot/git/refs{/sha}","trees_url":"https://api.github.com/repos/michaloo/hull-hubspot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/michaloo/hull-hubspot/statuses/{sha}","languages_url":"https://api.github.com/repos/michaloo/hull-hubspot/languages","stargazers_url":"https://api.github.com/repos/michaloo/hull-hubspot/stargazers","contributors_url":"https://api.github.com/repos/michaloo/hull-hubspot/contributors","subscribers_url":"https://api.github.com/repos/michaloo/hull-hubspot/subscribers","subscription_url":"https://api.github.com/repos/michaloo/hull-hubspot/subscription","commits_url":"https://api.github.com/repos/michaloo/hull-hubspot/commits{/sha}","git_commits_url":"https://api.github.com/repos/michaloo/hull-hubspot/git/commits{/sha}","comments_url":"https://api.github.com/repos/michaloo/hull-hubspot/comments{/number}","issue_comment_url":"https://api.github.com/repos/michaloo/hull-hubspot/issues/comments{/number}","contents_url":"https://api.github.com/repos/michaloo/hull-hubspot/contents/{+path}","compare_url":"https://api.github.com/repos/michaloo/hull-hubspot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/michaloo/hull-hubspot/merges","archive_url":"https://api.github.com/repos/michaloo/hull-hubspot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/michaloo/hull-hubspot/downloads","issues_url":"https://api.github.com/repos/michaloo/hull-hubspot/issues{/number}","pulls_url":"https://api.github.com/repos/michaloo/hull-hubspot/pulls{/number}","milestones_url":"https://api.github.com/repos/michaloo/hull-hubspot/milestones{/number}","notifications_url":"https://api.github.com/repos/michaloo/hull-hubspot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/michaloo/hull-hubspot/labels{/name}","releases_url":"https://api.github.com/repos/michaloo/hull-hubspot/releases{/id}","deployments_url":"https://api.github.com/repos/michaloo/hull-hubspot/deployments","created_at":"2016-08-18T14:44:52Z","updated_at":"2016-08-18T14:44:53Z","pushed_at":"2016-08-22T14:13:22Z","git_url":"git://github.com/michaloo/hull-hubspot.git","ssh_url":"git@github.com:michaloo/hull-hubspot.git","clone_url":"https://github.com/michaloo/hull-hubspot.git","svn_url":"https://github.com/michaloo/hull-hubspot","homepage":null,"size":114,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"hull-ships:master","ref":"master","sha":"0fb38938169a2d9156fae4941547e268f6a4b8af","user":{"login":"hull-ships","id":8874713,"avatar_url":"https://avatars.githubusercontent.com/u/8874713?v=3","gravatar_id":"","url":"https://api.github.com/users/hull-ships","html_url":"https://github.com/hull-ships","followers_url":"https://api.github.com/users/hull-ships/followers","following_url":"https://api.github.com/users/hull-ships/following{/other_user}","gists_url":"https://api.github.com/users/hull-ships/gists{/gist_id}","starred_url":"https://api.github.com/users/hull-ships/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hull-ships/subscriptions","organizations_url":"https://api.github.com/users/hull-ships/orgs","repos_url":"https://api.github.com/users/hull-ships/repos","events_url":"https://api.github.com/users/hull-ships/events{/privacy}","received_events_url":"https://api.github.com/users/hull-ships/received_events","type":"Organization","site_admin":false},"repo":{"id":65308112,"name":"hull-hubspot","full_name":"hull-ships/hull-hubspot","owner":{"login":"hull-ships","id":8874713,"avatar_url":"https://avatars.githubusercontent.com/u/8874713?v=3","gravatar_id":"","url":"https://api.github.com/users/hull-ships","html_url":"https://github.com/hull-ships","followers_url":"https://api.github.com/users/hull-ships/followers","following_url":"https://api.github.com/users/hull-ships/following{/other_user}","gists_url":"https://api.github.com/users/hull-ships/gists{/gist_id}","starred_url":"https://api.github.com/users/hull-ships/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hull-ships/subscriptions","organizations_url":"https://api.github.com/users/hull-ships/orgs","repos_url":"https://api.github.com/users/hull-ships/repos","events_url":"https://api.github.com/users/hull-ships/events{/privacy}","received_events_url":"https://api.github.com/users/hull-ships/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hull-ships/hull-hubspot","description":null,"fork":false,"url":"https://api.github.com/repos/hull-ships/hull-hubspot","forks_url":"https://api.github.com/repos/hull-ships/hull-hubspot/forks","keys_url":"https://api.github.com/repos/hull-ships/hull-hubspot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hull-ships/hull-hubspot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hull-ships/hull-hubspot/teams","hooks_url":"https://api.github.com/repos/hull-ships/hull-hubspot/hooks","issue_events_url":"https://api.github.com/repos/hull-ships/hull-hubspot/issues/events{/number}","events_url":"https://api.github.com/repos/hull-ships/hull-hubspot/events","assignees_url":"https://api.github.com/repos/hull-ships/hull-hubspot/assignees{/user}","branches_url":"https://api.github.com/repos/hull-ships/hull-hubspot/branches{/branch}","tags_url":"https://api.github.com/repos/hull-ships/hull-hubspot/tags","blobs_url":"https://api.github.com/repos/hull-ships/hull-hubspot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hull-ships/hull-hubspot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hull-ships/hull-hubspot/git/refs{/sha}","trees_url":"https://api.github.com/repos/hull-ships/hull-hubspot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hull-ships/hull-hubspot/statuses/{sha}","languages_url":"https://api.github.com/repos/hull-ships/hull-hubspot/languages","stargazers_url":"https://api.github.com/repos/hull-ships/hull-hubspot/stargazers","contributors_url":"https://api.github.com/repos/hull-ships/hull-hubspot/contributors","subscribers_url":"https://api.github.com/repos/hull-ships/hull-hubspot/subscribers","subscription_url":"https://api.github.com/repos/hull-ships/hull-hubspot/subscription","commits_url":"https://api.github.com/repos/hull-ships/hull-hubspot/commits{/sha}","git_commits_url":"https://api.github.com/repos/hull-ships/hull-hubspot/git/commits{/sha}","comments_url":"https://api.github.com/repos/hull-ships/hull-hubspot/comments{/number}","issue_comment_url":"https://api.github.com/repos/hull-ships/hull-hubspot/issues/comments{/number}","contents_url":"https://api.github.com/repos/hull-ships/hull-hubspot/contents/{+path}","compare_url":"https://api.github.com/repos/hull-ships/hull-hubspot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hull-ships/hull-hubspot/merges","archive_url":"https://api.github.com/repos/hull-ships/hull-hubspot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hull-ships/hull-hubspot/downloads","issues_url":"https://api.github.com/repos/hull-ships/hull-hubspot/issues{/number}","pulls_url":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls{/number}","milestones_url":"https://api.github.com/repos/hull-ships/hull-hubspot/milestones{/number}","notifications_url":"https://api.github.com/repos/hull-ships/hull-hubspot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hull-ships/hull-hubspot/labels{/name}","releases_url":"https://api.github.com/repos/hull-ships/hull-hubspot/releases{/id}","deployments_url":"https://api.github.com/repos/hull-ships/hull-hubspot/deployments","created_at":"2016-08-09T15:51:55Z","updated_at":"2016-08-09T15:56:19Z","pushed_at":"2016-08-22T14:16:29Z","git_url":"git://github.com/hull-ships/hull-hubspot.git","ssh_url":"git@github.com:hull-ships/hull-hubspot.git","clone_url":"https://github.com/hull-ships/hull-hubspot.git","svn_url":"https://github.com/hull-ships/hull-hubspot","homepage":null,"size":114,"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":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/1"},"html":{"href":"https://github.com/hull-ships/hull-hubspot/pull/1"},"issue":{"href":"https://api.github.com/repos/hull-ships/hull-hubspot/issues/1"},"comments":{"href":"https://api.github.com/repos/hull-ships/hull-hubspot/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hull-ships/hull-hubspot/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/hull-ships/hull-hubspot/statuses/1fd21e909710ba0c70bb3b8c43516e11e7fa5df2"}}}}
{"actor":{"display_login":"unity"}}