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



25
26
27
28
# File 'lib/enimo_client.rb', line 25

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

#debug_alert(device_id) ⇒ Object



30
31
32
33
34
# File 'lib/enimo_client.rb', line 30

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

#flash(device_id, alert_type) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/enimo_client.rb', line 62

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



36
37
38
39
40
# File 'lib/enimo_client.rb', line 36

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

#phone_call_alert(device_id) ⇒ Object



56
57
58
59
60
# File 'lib/enimo_client.rb', line 56

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

#simple_alert(device_id) ⇒ Object



50
51
52
53
54
# File 'lib/enimo_client.rb', line 50

def simple_alert(device_id)
	HTTParty.get("http://localhost:3000/devices/#{device_id}/on")
			sleep 1.5 
			HTTParty.get("http://localhost:3000/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
# File 'lib/enimo_client.rb', line 7

def start(session)
	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



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

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

#turn_on(device_id) ⇒ Object



42
43
44
# File 'lib/enimo_client.rb', line 42

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