-
Notifications
You must be signed in to change notification settings - Fork 1
WebSocket API
In order to read a vehicle, you use read, specifying the vehicle model and its id. The reponse stores the requested vehicle in the value field, here is how to read the vehicle from a socket
var vehicle;
socket.onmessage = function(msg){
var resp = msg.data;
vehicle = resp.model.value;
};
var msg = {
"read":{
"model":"Vehicle",
"id":4
}
};
socket.send(Json.stringify(msg));
For the request, you specify the Vehicle type and provide the id of the desired Vehicle
{
"read": {
"model":"Vehicle",
"id":4
}
}
The response has a model object that contains the vehicle as the value
{
"model":{
"model":"Vehicle",
"value":{
"id":4,
"longitude":2,
"latitude":7,
"capacity":6
}
}
}
A new vehicle requires a latitude, longitude, and capacity
{
"create":{
"model":"Vehicle",
"value":{
"latitude":0.123,
"longitude":0.456,
"capacity":4
}
}
}
The response is an object with created which has the vehicle as the value
{
"created":{
"model":"Vehicle",
"value":{
"id":20,
"latitude":0.123,
"longitude":0.456,
"capacitor":4
}
}
}
An update is similar to a create except you need so specify the id of the row that you are updating, for an update, no fields are required for a vehicle.
{
"update":{
"model":"Vehicle",
"id":6,
"value":{
"latitude":1.2,
"longitude":66
}
}
}
{
"updated":{
"model":"Vehicle",
"value":{
"id":6,
"latitude":0.123,
"longitude":0.456,
"capacitor":4
}
}
}
{
"delete":{
"model":"Vehicle",
"id":4
}
}
{
"deleted":{
"model":"Vehicle",
"value":{
"id":4,
"latitude":40,
"longitude":30,
"capacity": 10
}
}
}
Reading Commodities is similar to reading vehicles, you just use Commodity instead of Vehicle for the type field
{
"read": {
"model":"Commodity",
"id":4
}
}
The response has a model object that contains the commodity
{
"model":{
"model":"Commodity",
"value":{
"id":4,
"longitude":2,
"latitude":7,
"capacity":6
}
}
}
A new commodity requires a startLatitude, startLongitude, endLatitude, endLongitude, and a param
{
"create":{
"model":"Commodity",
"value":{
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":0.789,
"endLongitude":0.101
"param":4
}
}
}
The response is an object with created which has the Commodity
{
"created":{
"model":"Commodity",
"value":{
"id":20,
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":0.789,
"endLongitude":0.101
"param":4
}
}
}
An update is similar to a create except you need so specify the id of the row that you are updating, for an update, no fields are required for a commodity.
{
"update":{
"model":"Commodity",
"id":6,
"value":{
"endLatitude":1.2,
"endLongitude":66
}
}
}
{
"updated":{
"model":"Vehicle",
"value":{
"id":6
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":1.2,
"endLongitude":66
"param":4
}
}
}
Like a vehicle, you delete the commodity by specifying its id
{
"delete":{
"model":"Commodity",
"id":4
}
}
{
"deleted":{
"model":"Commodity",
"value":{
"id":6,
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":1.2,
"endLongitude":66,
"param":4
}{
"id":6,
"startLatitude":0.123,
"startLongitude":0.456,
"endLatitude":1.2,
"endLongitude":66,
"param":4
}
}
}
Clusters, like vehicles and commodities, can be updated, read, created and deleted
{
"read":{
"model":"Cluster",
"id":8
}
}
{
"model":{
"model":"Cluster",
"value":{
"id": 10,
"parent":8,
"vehicles":[
{ "id": 1, "latitude":19, "longitude":77, "capacity":3 },
{ "id": 2, "latitude":10, "longitude":22, "capacity":4 },
{ "id": 3, "latitude":21, "longitude":31, "capacity":2 }
],
"commodities":[
{ "id":6, "param":4,
"startLatitude":0.123, "startLongitude":0.456,
"endLatitude":1.2, "endLongitude":66 },
{ "id":8, "param":3,
"startLatitude":923, "startLongitude":5.756,
"endLatitude":77, "endLongitude":606 }
],
"subClusters":[15,18]
}
}
}
cluster creates a very similar the other kinds of creates, a cluster requires a parent id
{
"create": {
"model":"Cluster",
"value":{
"parent":100
}
}
}
{
"created": {
"model":"Cluster"
"value":{
"id":10,
"parent":100,
"subClusters":[],
"commodities":[],
"vehicles":[]
}
}
}
Cluster Updates can be used to add a bunch of vehicles or commodities to a cluster, like updates for commodities and reads, it uses the update message except the model is now Cluster
{
"update": {
"model": "Cluster"
"id": 13,
"value": {
"vehicles": [
{ "latitude":1, "longitude":2, "capacity":5 }
],
"commodities": [
{ "startLatitude":10, "endLatitude":11,
"startLongitude":11, "endLongitude":9,
"param":6 }
]
}
}
}
###Response
{
"update": {
"model": "Cluster"
"value": {
"id":12,
"vehicles": [
{ "id":2, "latitude":6, "longitude":3, "capacity":3 },
{ "id":30, "latitude":1, "longitude":2, "capacity":5 }
],
"commodities": [
{ "startLatitude":10, "endLatitude":11,
"startLongitude":11, "endLongitude":9,
"param":6 },
{ "startLatitude":12, "endLatitude":1,
"startLongitude":11, "endLongitude":0,
"param":6 "id":30},
{ "startLatitude":10, "endLatitude":11,
"startLongitude":11, "endLongitude":9,
"param":6 "id":100}
]
}
}
}