Skip to content

Instantly share code, notes, and snippets.

@pk11
Last active December 24, 2015 06:09
Show Gist options
  • Save pk11/6755555 to your computer and use it in GitHub Desktop.
Save pk11/6755555 to your computer and use it in GitHub Desktop.
var avatar = require("org/glassfish/avatar");
var getTime = function() {
var result = new Date();
return {
time: result.toISOString(),
h: result.getHours(),
m: result.getMinutes(),
s: result.getSeconds(),
d: result.getDate(),
M: result.getMonth()+1,//getMonth() returns 0-11
y: result.getFullYear()};
};
avatar.registerRestService({
url: "data/name",
methods: ["GET", "PUT"]},
function() {
this.$onGet = function(request, response) {
console.log("incoming data:"+JSON.stringify(avatar)) ;
return response.$send({name:"defaultABCXYYW"});
};
this.$onPut = function(request, response) {
var name = request.data.name;
return response.$send({name:name.toLowerCase()});
};
}
);
avatar.registerPushService({
url: "push/time"},
function() {
this.$onOpen = this.$onTimeout = function(context) {
context.$setTimeout(1000);
return context.$sendMessage(getTime());
};
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment