Class: Brazenhead::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/brazenhead/device.rb

Instance Method Summary collapse

Instance Method Details

#last_jsonObject



29
30
31
32
33
34
35
36
# File 'lib/brazenhead/device.rb', line 29

def last_json
  body = last_response.body
  begin
    JSON.parse body
  rescue
    primitive_to_json body
  end
end

#last_responseObject



25
26
27
# File 'lib/brazenhead/device.rb', line 25

def last_response
  @last_response
end

#send(message) ⇒ Object

Raises:

  • (Exception)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/brazenhead/device.rb', line 6

def send(message)
  retries = 0
  begin
    @last_response = http.post '/', message
  rescue
    retries += 1
    sleep 0.5
    retry unless retries == 20
    $stderr.puts "Failed to send the command #{message} #{retries} times..."
    raise
  end
  raise Exception, @last_response.body unless @last_response.code == "200"
  @last_response
end

#stopObject



21
22
23
# File 'lib/brazenhead/device.rb', line 21

def stop
  http.post '/kill', ''
end