Created
June 3, 2013 21:54
-
-
Save robertz/5701788 to your computer and use it in GitHub Desktop.
Handler for the API endpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component | |
accessors=false | |
extends="coldbox.system.EventHandler" | |
{ | |
property name="Logger" inject="logbox:logger:{this}"; | |
property name="ChatService" inject="model"; | |
// Posts a message to the stack | |
public void function put(Event, RC, PRC){ | |
var message = { 'userid' = rc.userid, 'message' = rc.message }; | |
var result = { 'svrStatus' = 0, 'svrMessage' = 'OK'}; | |
variables.ChatService.putMessage(message); | |
Event.renderData(data = serializeJSON(result)); | |
return; | |
} | |
// Gets the current list of messages | |
public void function list(Event, RC, PRC){ | |
var start = structKeyExists(rc, 'startid') ? rc.startid : 0; | |
var result = { 'svrStatus' = 0, 'svrMessage' = 'OK'}; | |
structAppend(result, variables.ChatService.getMessages(startid = start)); | |
result['clients'] = variables.ChatService.getClients(); | |
Event.renderData(data = serializeJSON(result)); | |
return; | |
} | |
public void function setuser(Event, RC, PRC){ | |
Event.renderData(data = serializeJSON(variables.ChatService.addUser(rc.userid))); | |
return; | |
} | |
public void function index(Event, RC, PRC){ | |
setNextEvent('main.fourOhFour'); | |
return; | |
} | |
public void function clients(Event, RC, PRC){ | |
var result = { 'svrStatus' = 0, 'svrMessage' = 'OK', 'userInfo' = variables.ChatService.getClients() }; | |
Event.renderData(data = serializeJSON(result)); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment