Class: Lita::Handlers::DebugApi

Inherits:
Object
  • Object
show all
Extended by:
Lita::Handler::HTTPRouter
Defined in:
lib/lita/handlers/debug_api.rb

Instance Method Summary collapse

Instance Method Details

#clear(request, response) ⇒ Object



37
38
39
40
41
42
# File 'lib/lita/handlers/debug_api.rb', line 37

def clear(request, response)
  return unless validate!(request, response)
  @room.clear!
  result = { queue: @room.queue, message: "So much for that. :control_knobs:" }
  response.write(MultiJson.dump(result))
end

#drop(request, response) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lita/handlers/debug_api.rb', line 44

def drop(request, response)
  return unless validate!(request, response)
  params = request.env["router.params"]
  student = request.params["student"]

  if @room.include?(student)
    @room.remove(student)
    result = { queue: @room.queue, message: "#{student} has been removed." }
  else
    result = { queue: @room.queue, message: "#{student} isn't in the queue!" }
  end
  response.write(MultiJson.dump(result))
end

#next(request, response) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lita/handlers/debug_api.rb', line 19

def next(request, response)
  return unless validate!(request, response)
  if @room.count.zero?
    result = {
      queue: @room.queue,
      message: "The queue is empty. :beer:?"
    }
  else
    student = @room.next
    send_message(student, "@#{student}: You're up. Let's debug :allthethings:!")
    result = {
      queue: @room.queue,
      message: "#{student} is up next and has been notified."
    }
  end
  response.write(MultiJson.dump(result))
end

#show(request, response) ⇒ Object



13
14
15
16
17
# File 'lib/lita/handlers/debug_api.rb', line 13

def show(request, response)
  return unless validate!(request, response)
  result = { queue: @room.queue }
  response.write(MultiJson.dump(result))
end