Skip to content

Instantly share code, notes, and snippets.

@volpeo
Created February 6, 2019 18:06
Show Gist options
  • Save volpeo/1e6fadc271edd384621e1e2ce6ed612c to your computer and use it in GitHub Desktop.
Save volpeo/1e6fadc271edd384621e1e2ce6ed612c to your computer and use it in GitHub Desktop.
const writeData = (data, contentElt) => {
contentElt.innerHTML = `
<p>Name is ${data.person.name.fullName}</p>
<p>Company is ${data.company.name}</p>
`
};
const getInfoFromClearbit = (e) => {
const contentElt = document.getElementById('content');
e.preventDefault();
contentElt.innerHTML = '<img src="https://cdn-images-1.medium.com/max/1600/1*9EBHIOzhE1XfMYoKz1JcsQ.gif">'
const emailInput = document.getElementById('email');
fetch(`https://person.clearbit.com/v2/combined/find?email=${emailInput.value}`,{
headers: {
Authorization: 'Bearer sk_b10bbd8293e6313de0a9a589ed7f55f9'
}
})
.then(response => response.json())
.then((data) => writeData(data, contentElt));
}
const enrichWithClearbit = (e) => {
const form = document.getElementById('form');
form.addEventListener('submit', getInfoFromClearbit);
}
document.addEventListener('DOMContentLoaded', enrichWithClearbit);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src='app.js'></script>
</head>
<body>
<form id="form">
<input type="email" placeholder="Email" id="email">
<input type="submit">
</form>
<div id="content">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment