Class: Botvac::Web

Inherits:
Object
  • Object
show all
Defined in:
lib/botvac/web.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/botvac/web.rb', line 5

def call(env)
  if supported_actions.include?(env["REQUEST_PATH"][1..-1])
    [200, {'Content-Type' => 'application/json'}, [robot.send(env["REQUEST_PATH"][1..-1])]]
  else
    [404, {'Content-Type' => 'application/json'}, ['{}']]
  end
end

#robotObject



17
18
19
# File 'lib/botvac/web.rb', line 17

def robot
  @robot ||= Botvac::Robot.new(ENV['SERIAL'], ENV['SECRET'])
end

#supported_actionsObject



13
14
15
# File 'lib/botvac/web.rb', line 13

def supported_actions
  %w(start_cleaning pause_cleaning stop_cleaning send_to_base get_robot_state disable_schedule enable_schedule get_schedule)
end