Class: Lackie::RemoteControl

Inherits:
Object
  • Object
show all
Defined in:
lib/lackie/remote_control.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port, poller = Poller.new) ⇒ RemoteControl

Returns a new instance of RemoteControl.



7
8
9
# File 'lib/lackie/remote_control.rb', line 7

def initialize(host, port, poller=Poller.new)
  @host, @port, @poller = host, port, poller
end

Instance Method Details

#await(expression, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lackie/remote_control.rb', line 29

def await(expression, options={})
  result = nil
  begin
    @poller.await("result matching expression: #{expression}", options) do
      begin
        result = exec(expression)
      rescue TimeoutError => e
      end
      yield result
    end
  rescue TimeoutError => e
    raise AwaitError.new(expression, result)
  end
  result
end

#exec(command, options = {}) ⇒ Object



15
16
17
18
# File 'lib/lackie/remote_control.rb', line 15

def exec(command, options={})
  send_command(command)
  poll_for_result(command, options)
end

#log(message) ⇒ Object



11
12
13
# File 'lib/lackie/remote_control.rb', line 11

def log(message)
  exec("Lackie.log(#{message.to_json})")
end

#send_command(command) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/lackie/remote_control.rb', line 20

def send_command(command)
  url = "http://#{@host}:#{@port}/lackie/eval"
  begin
    RestClient.post(url, command)
  rescue => e
    raise ConnectionError.new(url, e) 
  end
end