Class: Gameworks::Servlet::GameView

Inherits:
Base
  • Object
show all
Defined in:
lib/gameworks/servlet/game_view.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #method_not_allowed, process

Constructor Details

This class inherits a constructor from Gameworks::Servlet::Base

Instance Method Details

#GET(request) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gameworks/servlet/game_view.rb', line 6

def GET(request)
  game_id = request[:path].split('/')[1]
  game = @server.game_registry.instance(game_id)
  return [404, {}, ["no such game"]] unless game

  snapshot = nil
  if request[:tokens][:observer]
    snapshot = game.snapshot_for_observer(request[:tokens][:observer])
  end

  if snapshot
    [ 200, { 'Content-Type' => 'application/json' }, [game.delta(snapshot).to_json] ]
  else
    [ 200, { 'Content-Type' => 'application/json' }, [game.to_json] ]
  end
end