Class: Maze::Servlets::AllCommandsServlet

Inherits:
BaseServlet
  • Object
show all
Defined in:
lib/maze/servlets/all_commands_servlet.rb

Overview

Allows clients to queue up “commands”, in the form of Ruby hashes, using Maze::Server.commands.add. GET requests made to the /command endpoint will then respond with each queued command in turn.

Instance Method Summary collapse

Instance Method Details

#do_GET(request, response) ⇒ Object

Serves all commands held.

Parameters:

  • request (HTTPRequest)

    The incoming GET request

  • response (HTTPResponse)

    The response to return



15
16
17
18
19
20
21
22
23
# File 'lib/maze/servlets/all_commands_servlet.rb', line 15

def do_GET(request, response)
  commands = Maze::Server.commands.all

  command_json = JSON.pretty_generate(commands)
  response.body = command_json
  response.status = 200

  response.header['Access-Control-Allow-Origin'] = '*'
end

#do_OPTIONS(request, response) ⇒ Object

Logs and returns a set of valid headers for this servlet.

Parameters:

  • request (HTTPRequest)

    The incoming GET request

  • response (HTTPResponse)

    The response to return



29
30
31
32
33
34
# File 'lib/maze/servlets/all_commands_servlet.rb', line 29

def do_OPTIONS(request, response)
  super

  response.header['Access-Control-Allow-Methods'] = 'POST, OPTIONS'
  response.status = Server.status_code('OPTIONS')
end