Skip to content

Instantly share code, notes, and snippets.

@HodGreeley
Last active July 26, 2018 21:05
Show Gist options
  • Save HodGreeley/9e25f9072247e180ec5cd764d9048c3b to your computer and use it in GitHub Desktop.
Save HodGreeley/9e25f9072247e180ec5cd764d9048c3b to your computer and use it in GitHub Desktop.
Couchbase Points of Interest Eventing Service Functions Code
function OnUpdate(doc, meta) {
if (meta.id !== 'trigger') return;
let here = db['here'];
let url = "https://places.cit.api.here.com/places/v1/discover/around";
let data = `app_id=${here.id}&app_code=${here.code}&at=${doc.lat},${doc.lon}`;
let query = SELECT CURL($url, {
"request": "GET",
"header": [ "Content-Type: application/json", "accept: application/json" ],
"data": $data
}).results.items
AS poi;
let response = query.execQuery();
db['poi'] = response[0].poi;
url = "http://localhost:8080/events/poi";
data = JSON.stringify(response[0].poi);
query = SELECT CURL($url, {
"request": "POST",
"header": [ "Content-Type: application/json", "accept: application/json" ],
"data": $data
});
response = query.execQuery();
}
function OnDelete(meta) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment