Class: Brazenhead::Device
- Inherits:
-
Object
- Object
- Brazenhead::Device
- Defined in:
- lib/brazenhead/device.rb
Instance Method Summary collapse
Instance Method Details
#last_json ⇒ Object
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_response ⇒ Object
25 26 27 |
# File 'lib/brazenhead/device.rb', line 25 def last_response @last_response end |
#send(message) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/brazenhead/device.rb', line 6 def send() retries = 0 begin @last_response = http.post '/', rescue retries += 1 sleep 0.5 retry unless retries == 20 $stderr.puts "Failed to send the command #{} #{retries} times..." raise end raise Exception, @last_response.body unless @last_response.code == "200" @last_response end |
#stop ⇒ Object
21 22 23 |
# File 'lib/brazenhead/device.rb', line 21 def stop http.post '/kill', '' end |