-
Notifications
You must be signed in to change notification settings - Fork 31
adds functionality for updating contacts on hubspot when their phase is changed #1099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
je-lopez
wants to merge
4
commits into
LearnersGuild:master
Choose a base branch
from
je-lopez:1070-update-hubspot
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d76b68a
moves getContactByEmail from index to its own file
je-lopez 22252d4
moves notifyContactSignedUp from index to its own file
je-lopez 40e2d69
extracts duplicate code from getContactByEmail and notifyContactSigne…
je-lopez 5b8e182
adds functionality for updating contact on hubspot when their phase c…
je-lopez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import {default as fetchCRM} from './util' | ||
|
|
||
| export default async function getContactByEmail(email) { | ||
| return fetchCRM(`/contacts/v1/contact/email/${encodeURIComponent(email)}/profile`) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import {default as fetchCRM} from './util' | ||
| import {default as getContactByEmail} from './getContactByEmail' | ||
|
|
||
| export default async function notifyContactSignedUp(email) { | ||
| const contact = await getContactByEmail(email) | ||
|
|
||
| await fetchCRM(`/contacts/v1/contact/vid/${contact.vid}/profile`, { | ||
| method: 'POST', | ||
| body: JSON.stringify({ | ||
| properties: [{ | ||
| property: 'signed_up_for_echo', | ||
| value: true, | ||
| }] | ||
| }) | ||
| }) | ||
|
|
||
| // API returns statusCode 204 with no body | ||
| return true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import {default as fetchCRM} from './util' | ||
| import {default as getContactByEmail} from './getContactByEmail' | ||
|
|
||
| export default async function updateContactProperties(email, properties) { | ||
| const contact = await getContactByEmail(email) | ||
|
|
||
| await fetchCRM(`/contacts/v1/contact/vid/${contact.vid}/profile`, { | ||
| method: 'POST', | ||
| body: JSON.stringify({properties}) | ||
| }) | ||
|
|
||
| // API returns statusCode 204 with no body | ||
| return true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import fetch from 'isomorphic-fetch' | ||
|
|
||
| import config from 'src/config' | ||
|
|
||
| export default async function fetchCRM(path, fetchOptions = {}) { | ||
| const url = _crmURL(path) | ||
|
|
||
| const options = { | ||
| headers: { | ||
| Accept: 'application/json', | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| ...fetchOptions | ||
| } | ||
|
|
||
| const resp = await fetch(url, options) | ||
|
|
||
| if (!resp.ok) { | ||
| throw new Error(`Couldn't fetch from CRM service: ${resp.statusText}`) | ||
| } | ||
|
|
||
| return resp.json() | ||
| } | ||
|
|
||
| function _crmURL(path) { | ||
| _assertEnvironment() | ||
| return `${config.server.crm.baseURL}${path}?hapikey=${config.server.crm.key}` | ||
| } | ||
|
|
||
| function _assertEnvironment() { | ||
| if (!config.server.crm.baseURL) { | ||
| throw new Error('CRM base URL must be configured') | ||
| } | ||
| if (!config.server.crm.key) { | ||
| throw new Error('CRM API key must be configured') | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a linter that prefers:
over:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we do. I think it's xo