Class: EnimoClient::API

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

Instance Method Summary collapse

Instance Method Details

#add_device(device_id) ⇒ Object



28
29
30
31
# File 'lib/enimo_client.rb', line 28

def add_device(device_id)
      response = HTTParty.get("http://#{@domain}/devices/#{device_id}/new")
  puts response.body, response.code, response.message, response.headers.inspect
end

#debug_alert(device_id) ⇒ Object



33
34
35
36
37
# File 'lib/enimo_client.rb', line 33

def debug_alert(device_id)
  HTTParty.get("http://#{@domain}/devices/#{device_id}/on")
      sleep 2
      HTTParty.get("http://#{@domain}/devices/#{device_id}/off")
end

#flash(device_id, alert_type) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/enimo_client.rb', line 65

def flash(device_id,alert_type)
  case alert_type
    when :debug
        debug_alert(device_id)
    when :important
        important_alert(device_id)
    when :simple 
    simple_alert(device_id)
when :phone_call
    phone_call_alert(device_id)
    when :turn_off
      turn_off(device_id)
    when :turn_on
        turn_on(device_id)
    end
end

#important_alert(device_id) ⇒ Object



39
40
41
42
43
# File 'lib/enimo_client.rb', line 39

def important_alert(device_id)
  HTTParty.get("http://#{@domain}/devices/#{device_id}/on")
      sleep 2
      HTTParty.get("http://#{@domain}/devices/#{device_id}/off")
end

#phone_call_alert(device_id) ⇒ Object



59
60
61
62
63
# File 'lib/enimo_client.rb', line 59

def phone_call_alert(device_id)
  HTTParty.get("http://#{@domain}/devices/#{device_id}/on")
      sleep 15
      HTTParty.get("http://#{@domain}/devices/#{device_id}/off")
end

#simple_alert(device_id) ⇒ Object



53
54
55
56
57
# File 'lib/enimo_client.rb', line 53

def simple_alert(device_id)
  HTTParty.get("http://#{@domain}/devices/#{device_id}/on")
      sleep 1.5 
      HTTParty.get("http://#{@domain}/devices/#{device_id}/off")
end

#start(session) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/enimo_client.rb', line 7

def start(session)
  prod = "ec2-54-186-158-25.us-west-2.compute.amazonaws.com"
  dev = "localhost:3000"
  @domain = prod
  if session[:device_id].nil? or session[:action].nil?
    return "You must include the session details. please read the documentation for more info."
  else
    case session[:action]
    
    when :add_device
      add_device(session[:device_id])
    when :flash
      if session[:alert_type].nil?
        return "Please include the alert type in seconds {:alert_type=>'alert type'}"
      else
        flash(session[:device_id],session[:alert_type]) 
      end
    end
  end
end

#turn_off(device_id) ⇒ Object



49
50
51
# File 'lib/enimo_client.rb', line 49

def turn_off(device_id)
  HTTParty.get("http://#{@domain}/devices/#{device_id}/off")
end

#turn_on(device_id) ⇒ Object



45
46
47
# File 'lib/enimo_client.rb', line 45

def turn_on(device_id)
  HTTParty.get("http://#{@domain}/devices/#{device_id}/on")
end