-
-
Save a-theriault/fa7f2e132758be6c7037 to your computer and use it in GitHub Desktop.
quick test of roomie agent api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Roomie API Tester</title> | |
<link rel="stylesheet" href="/css/main.css"> | |
</head> | |
<body> | |
<select id="activity-selector"></select> | |
<button id="go">go</button> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> | |
<script type="text/javascript"> | |
$(function() { | |
(function() { | |
// ADD THE IP OF YOUR ROOMIE AGENT HERE. | |
var config = { | |
BASEURL : "<your-ip>:3000/api/" | |
} | |
function sendRequest(request) { | |
// Overload the request here if need be. | |
return $.ajax(request); | |
} | |
function createActivityListDOM(activities) { | |
var activityListDOM = []; | |
$.each(activities.data, function(i, value) { | |
activityListDOM.push( | |
'<option value="'+value.uuid+'">'+value.name+'</option>' | |
); | |
}); | |
return activityListDOM.join(''); | |
} | |
function renderActivities(activities) { | |
$activitySelector = $('#activity-selector'); | |
var activityListDOM = createActivityListDOM(activities); | |
return $activitySelector.html(activityListDOM); | |
} | |
// auto-populate activities into dropdown. | |
function loadActivities() { | |
sendRequest({ | |
"url": [config.BASEURL,'activities'].join(""), | |
"method": "GET", | |
}) | |
.success(function(activities) { | |
activities = JSON.parse(activities); | |
renderActivities(activities); | |
}); | |
}; | |
// send selected activity to roomie agent | |
function doAction(activity) { | |
var payload = { | |
"activity_uuid": activity, | |
"toggle_state": "on", | |
"delay" : 1 | |
}; | |
return sendRequest({ | |
url: [config.BASEURL,'runactivity'].join(""), | |
method: 'POST', | |
dataType: 'json', | |
data: payload | |
}) | |
} | |
function getActivity() { | |
return $('#activity-selector').find(':selected').val(); | |
} | |
$('#go').on('click',function() { | |
var activity = getActivity(); | |
doAction(activity); | |
}); | |
loadActivities(); | |
})(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment