Skip to content

Instantly share code, notes, and snippets.

@germanviscuso
Last active May 17, 2016 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save germanviscuso/b567173008d03e2a9d4a29c2e3d74fec to your computer and use it in GitHub Desktop.
Save germanviscuso/b567173008d03e2a9d4a29c2e3d74fec to your computer and use it in GitHub Desktop.
Functions to send a dweet.io via a Kii server extension (useful for connecting to Freeboard)
function createDweetFromKiiObject(thingid, kiiObject, dweetKey, workerCallback, doneCallback) {
var string = null;
$.each(kiiObject, function(key, val){
if(key == "_customInfo")
string = JSON.stringify(val);
});
if (string == null){
console.log("Error: can't retrieve thing custom data for dweeting");
if(doneCallback) doneCallback("Dweet error");
}
else
createDweet(thingid, string, dweetKey, workerCallback, doneCallback);
}
function createDweet(thingid, payload, dweetKey, workerCallback, doneCallback) {
var dweetSite = "https://dweet.io:443";
var dweetCreateAction = "/dweet/for/";
var url = dweetSite + dweetCreateAction + thingid;
if(dweetKey)
url = url + "?key=" + dweetKey;
console.log("Posting to " + url + "...");
// Send visualization data
$.ajax({
url: url,
type: "POST",
data: payload, //as json string
contentType:"application/json; charset=utf-8",
dataType:"json",
success: function(body) {
console.log("Dweet sent!");
if(workerCallback) workerCallback(body);
else if(doneCallback) doneCallback("SUCCESS!");
},
error: function(msg) {
console.log("Error Dweeting");
if(doneCallback) doneCallback(msg);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment