class Gameworks::Servlet::AddObserver

Constants

AsyncResponse

Public Instance Methods

POST(request) click to toggle source
# File lib/gameworks/servlet/add_observer.rb, line 25
def POST(request)
  game_id = request[:path].split('/')[1]
  game = @server.game_registry.instance(game_id)
  return [404, {}, ["no such game"]] unless game
  wrapper = (request[:payload] || {})['wrapper']
  body = DeferrableBody.new(wrapper)
  token = game.register_observer(body)

  # application/x-multi-json if a format i just made up,
  # which is a series of json documents separated by newlines
  # (there will be no newlines within the json document)
  request[:async_cb].call [200,
    {'Content-Type' => 'application/x-multi-json',
     'X-Observer-Token' => token}, body]
  body.call(game.to_json)
  AsyncResponse
end