Skip to content

Instantly share code, notes, and snippets.

@rbren
Last active October 26, 2018 20:09
Show Gist options
  • Save rbren/b962069ee7a5e79e26d04f85872393ae to your computer and use it in GitHub Desktop.
Save rbren/b962069ee7a5e79e26d04f85872393ae to your computer and use it in GitHub Desktop.
OneDB simple example
<html>
<head>
<script src="https://unpkg.com/onedb-client/dist/onedb-client.min.js"></script>
<script>
var onedb = new OneDBClient({
hosts: {
primary: {location: 'https://one-db.datafire.io'},
}
});
</script>
</head>
<body>
<h2>Latest status updates</h2>
<div id="Statuses"></div>
<script>
onedb.list('status', 'status', {sort: 'info.created:descending'})
.then(function(response) {
var el = document.getElementById('Statuses');
for (var i = 0; i < response.items.length; ++i) {
el.innerHTML += getHTMLForStatusUpdate(response.items[i])
}
})
function getHTMLForStatusUpdate(statusUpdate) {
var info = statusUpdate.$.info;
var html = '<h4>' + info.created_by + '</h4>';
html += '<i>wrote on ' + new Date(info.created).toDateString() + '</i>';
html += '<p>' + statusUpdate.status.replace(/</g,"&lt;").replace(/>/g,"&gt;") + '</p>';
return html;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment