Skip to content

Instantly share code, notes, and snippets.

@bertspaan
Last active December 20, 2015 22:59
Show Gist options
  • Save bertspaan/6209114 to your computer and use it in GitHub Desktop.
Save bertspaan/6209114 to your computer and use it in GitHub Desktop.
CitySDK: HvA Waiting Time test
<!doctype html>
<head>
<meta charset="utf-8">
<title>HvA - Waiting Time</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<h1></h1>
<p>Add queue length to node <strong>w44508814</strong>:</p>
<table>
<tr>
<td>E-mail:</td>
<td>
<input type="text" id="email"></input>
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<input type="password" id="password"></input>
</td>
</tr>
<tr>
<td>Queue length:</td>
<td>
<input type="text" id="queue_length"></input>
</td>
</tr>
<tr>
<td>
<button id="submit">Submit!</button>
</td>
<td></td>
</tr>
</table>
<p>
<a href="http://api.citysdk.waag.org/w44508814?layer=*" target="_blank">View data on CitySDK API</a>
</p>
<script>
$(document).ready(function() {
$("#submit").on("click", function(event){
var email = $("#email").val();
var password = $("#password").val();
var queue_length = $("#queue_length").val();
var authUrl = "https://api.citysdk.waag.org/get_session?e=" + email + "&p=" + password;
var putUrl = "http://api.citysdk.waag.org/w44508814/hva.test_waitingtime";
var releaseUrl = "http://api.citysdk.waag.org/release_session";
$.getJSON(authUrl, function(data) {
var key = data.results[0];
var putRequest = $.ajax({
url: putUrl,
type: "PUT",
data: {
queue_length: queue_length
},
dataType: "json",
headers: {
"X-Auth": key
}
});
putRequest.done(function() {
var releaseRequest = $.ajax({
url: releaseUrl,
type: "GET",
headers: {
"X-Auth": key
}
});
releaseRequest.done(function() {
alert("Done!");
});
});
}
});
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment