Added Apps: clock, moods.

This commit is contained in:
Olivier Bagot 2013-11-20 18:28:29 +01:00
parent 32d56a896c
commit 8cf45fac19
3 changed files with 58 additions and 1 deletions

View File

@ -8,7 +8,7 @@ Current version 0.1.0 is still in development but usable.
OpenKarotz can be found [here](http://openkarotz.filippi.org/).
The following APIs are currently available:
The following APIs are available:
- clear_cache
- clear_snapshots
- ears
@ -34,6 +34,10 @@ The following APIs are currently available:
- voice_list
- wakeup
The following Apps are available:
- clock
- moods
### Usage ###

View File

@ -91,6 +91,11 @@ function homepage(res, req) {
+ '<li><a target="results" href="/cgi-bin/snapshot_get">snapshot_get</a>, <a target="results" href="/cgi-bin/snapshot_get?filename=snapshot.thumb.gif">snapshot_get(thumbnail)</a></li>'
+ '<li><a target="results" href="/cgi-bin/clear_snapshots">clear_snapshots</a></li>'
+ '</ul>'
+ '<h2>Apps</h2>'
+ '<ul>'
+ '<li><a target="results" href="/cgi-bin/apps/clock">clock</a>, <a target="results" href="/cgi-bin/apps/clock?hour=12">clock(12)</a></li>'
+ '<li><a target="results" href="/cgi-bin/apps/moods">moods</a>, <a target="results" href="/cgi-bin/apps/moods?id=50">moods(50)</a></li>'
+ '</ul>'
+ '<hr/>'
+ '<p><small>'
+ '<a href="https://github.com/hobbe">Copyright &copy 2013</a> - '
@ -570,3 +575,46 @@ function clear_snapshots(res, req) {
}
exports.clear_snapshots = clear_snapshots;
function clock(res, req) {
log.trace('clock: begin');
var data = '';
if (karotz.isSleeping()) {
data = '{"return":"1","msg":"Unable to perform action, rabbit is sleeping."}';
} else {
var hour = getParameter(req, "hour");
if (hour === undefined) {
hour = new Date().getHours();
}
if (hour >= 0 && hour <= 23) {
data = '{"return":"0","hour":"' + hour + '"}';
} else {
data = '{"return":"1","hour":"' + hour + '"}';
}
}
sendResponse(res, data);
log.trace('clock: end');
}
exports.clock = clock;
function moods(res, req) {
log.trace('moods: begin');
var data = '';
if (karotz.isSleeping()) {
data = '{"return":"1","msg":"Unable to perform action, rabbit is sleeping."}';
} else {
var mood = getParameter(req, "id");
//var lang = getParameter(req, "lang"); // Unused
if (mood === undefined) {
mood = Math.floor((Math.random() * 300) + 1);
}
data = '{"moods":"' + mood + '","return":"0"}';
}
sendResponse(res, data);
log.trace('moods: end');
}
exports.moods = moods;

View File

@ -36,6 +36,7 @@ var handle = {};
handle['/'] = handlers.homepage;
handle['/cgi-bin'] = handlers.homepage;
// API
handle['/cgi-bin/clear_cache'] = handlers.clear_cache;
handle['/cgi-bin/clear_snapshots'] = handlers.clear_snapshots;
handle['/cgi-bin/ears'] = handlers.ears;
@ -61,5 +62,9 @@ handle['/cgi-bin/tts'] = handlers.tts;
handle['/cgi-bin/voice_list'] = handlers.voice_list;
handle['/cgi-bin/wakeup'] = handlers.wakeup;
// APPS
handle['/cgi-bin/apps/clock'] = handlers.clock;
handle['/cgi-bin/apps/moods'] = handlers.moods;
log.info('OpenKarotz Emulator');
server.start(router.route, handle);