The choices have two components: device and package metadata. Because Maybe choices are different for each device.
The package metadata is generated by rewriter. It has specific schema, it must contains such fields:
sha224_hash
with a string, pacakge
with a string, and statements
with a JSONArray.
The elements in statements
should have
content
with Java code snippet (string),line
with a number to indicate start number in source code,type
andlabel
with string separately,alternatives
with a JSONArray, each element should containsstart
,end
,value
with a number separately.
You can check from metadata JSONObject or below example:
{
"sha224_hash": "1aab3f28f3d0ead580c3c22b10fee7e81c75e6d1e8f957611aedf51e",
"package": "testing_inputs.maybe",
"statements": [
{
"content": "int i = maybe(\"simple test\") 1, 2;",
"alternatives": [
{
"start": 29,
"end": 30,
"value": 0
},
{
"start": 32,
"end": 33,
"value": 1
}
],
"line": 5,
"type": "assignment",
"label": "simple test"
},
{
"content": "public String test = maybe(\"another test\") \"one\",\"two\", \"three\";",
"alternatives": [
{
"start": 43,
"end": 48,
"value": 0
},
{
"start": 49,
"end": 54,
"value": 1
},
{
"start": 58,
"end": 65,
"value": 2
}
],
"line": 6,
"type": "assignment",
"label": "another test"
},
{
"content": "maybe (\"block test\") {\n if (\"true\") {\n i = 0;\n } else {\n j = 0;\n maybe (\"third block test\") {\n i = 1;\n } or {\n j = 2;\n } or {\n j = 3;\n }\n }\n} or {\n i = 1;\n} or {\n j = 2;\n maybe (\"another block test\") {\n j = 3;\n }\n}",
"alternatives": [
{
"start": 22,
"end": 177,
"value": 0
},
{
"start": 182,
"end": 193,
"value": 1
},
{
"start": 198,
"end": 257,
"value": 2
}
],
"line": 20,
"type": "block",
"label": "block test"
},
{
"content": " maybe (\"third block test\") {\n i = 1;\n } or {\n j = 2;\n } or {\n j = 3;\n }",
"alternatives": [
{
"start": 32,
"end": 51,
"value": 0
},
{
"start": 56,
"end": 75,
"value": 1
},
{
"start": 80,
"end": 99,
"value": 2
}
],
"line": 25,
"type": "block",
"label": "third block test"
},
{
"content": " maybe (\"another block test\") {\n j = 3;\n }",
"alternatives": [
{
"start": 32,
"end": 47,
"value": 0
}
],
"line": 37,
"type": "block",
"label": "another block test"
}
]
}
Create a new record for specific metadata
.
$ curl http://localhost:3000/maybe-api-v1/metadata -d 'you json object'
It will use package
as _id
in MongoDB:
If everything good, it will return a JSONObject with status code 201
.
With ?callback=0
, it will only return an empty JSONObjects:
{}
If the schema is invalid, its status code is 400
.
If something wrong, its status code is 409
, content like this:
{ "message": "Could not post that object." }
Get all of the metadata records:
$ curl http://localhost:3000/maybe-api-v1/metadata
Get a device record:
$ curl http://localhost:3000/maybe-api-v1/metadata/testing_inputs.maybe
If success, it will return an array of JSONObjects.
PUT
is not allowed. If you need to update a package, you must use POST
to upload all package information.
Delete a record:
$ curl http://localhost:3000/maybe-api-v1/metadata/testing_inputs.maybe -X DELETE
If success, it will return empty JSONObject with status code 200
. If the package name is invalid, it return a error message wit status code 404
:
{"error":"testing_inputs.maybe not found!"}
Otherwise, it return status code 500
with error message:
{ "error": "TypeError: Cannot read property '_id' of undefined" }
The devices API is designed for store choices of every device, so we use deviceid
as key.
Create a new record for specific ``deviceid```.
$ curl http://localhost:3000/maybe-api-v1/devices -d '{"deviceid": "001"}'
If everything good, it will return a JSONObject with status code 201
like this:
{
"deviceid": "001",
"choices": {
"testing_inputs.maybe": {
"packageName": "testing_inputs.maybe",
"labelJSON": {
"simple test": {
"label": "simple test",
"choice": 1
},
"another test": {
"label": "another test",
"choice": 2
},
"block test": {
"label": "block test",
"choice": 1
},
"third block test": {
"label": "third block test",
"choice": 1
},
"another block test": {
"label": "another block test",
"choice": 0
}
},
"version": 7
}
}
}
If the deviceid
is duplicated, its status code 500
, content like this:
{"error":"001 conflict!"}
If something wrong, its status code 409
, content like this:
{ "message": "Could not post that object." }
Get all of the devices:
$ curl http://localhost:3000/maybe-api-v1/devices
Get a device record:
$ curl http://localhost:3000/maybe-api-v1/devices/001
If success, it will return an array of JSONObjects.
Update a device:
$ curl http://localhost:3000/maybe-api-v1/devices/001 -X PUT -d '{"gcmid" : "ex5SKkjPzAM:APA91bE7olCAyx4H7RgTmLVFVPl-FoFPH6wRDo1FAyuWsb06HhsCrN4SwttLLR7q6goEjMxAOapNS--Cmt9H186z9PB5dD8BIEtcpdfBJpCILBBx4-eOcoQrvF7xyd76E7I6G49-NGZR"}'
If success, it will return status code 202, and a JSONObject of this device, same as return content of GET
request.
$ curl http://localhost:3000/maybe-api-v1/devices/001?callback=0 -X PUT -d '{"gcmid" : "ex5SKkjPzAM:APA91bE7olCAyx4H7RgTmLVFVPl-FoFPH6wRDo1FAyuWsb06HhsCrN4SwttLLR7q6goEjMxAOapNS--Cmt9H186z9PB5dD8BIEtcpdfBJpCILBBx4-eOcoQrvF7xyd76E7I6G49-NGZR"}}'
With ?callback=0
and PUT
request success, it will only return an empty JSONObject with status code 202:
{}
TODO: now only gcmid
is allowed in PUT
, we need add fields like: model
, android version
, capacity
, etc.
Delete a record:
$ curl http://localhost:3000/maybe-api-v1/devices/001 -X DELETE
If success, it will return empty JSONObject with status code 200
. If the deviceid
is invalid, it return a error message wit status code 404
:
{"error": "001 not found!"}
Otherwise, it return status code 500
with error message:
{ "error": "TypeError: Cannot read property '_id' of undefined" }