class EnimoClient::API

Public Instance Methods

add_device(device_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/enimo_client.rb, line 45
def turn_on(device_id)
    HTTParty.get("http://#{@domain}/devices/#{device_id}/on")
end