API REST --------- In this part we are going to see examples of how to use Ewetasker application making API REST requests. This is the best way to integrate Ewetasker with other applications. To create a new rule ~~~~~~~~~~~~~~~~~~~~ .. code:: POST http://localhost:8080/api/mobile Example for the rule When users enters the office (< 2 meters) then switch on the light. The request parameters are: .. code:: { 'command': 'createRuleParams', 'rule_channel_one': 'presence', 'rule_title': 'light automation', 'rule_action_title': 'Turn on', 'rule_description': 'Presence Light', 'rule_channel_two': 'hueLight', 'rule_event_title': 'Presence Detected At Distance Less Than', 'event_param_1': '5544', 'event_param_2': 2, 'rule_creator': 'admin', 'rule_place': 'GSI Lab' } To get the channels available ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: POST http://localhost:8080/api/mobile The request parameter is: .. code:: {'command': 'getChannels'} The server response has this JSON structure: .. code:: [{ "title":"", "description":"", "events":[{ "title":"", "prefix":"", "rule":"", "numParameters":"" }], "actions":[{ "title":"", "prefix":"", "rule":"", "numParameters":"" }] }] To evaluate the rules created ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: POST http://localhost:8080/api/events Example to evaluate the rule When users enters office (< 2 meters) then switch on the light. The request parameters are: .. code:: { "user": "admin", "inputEvent":"@prefix rdf: . @prefix ewe: . @prefix ewe-presence: . ewe-presence:PresenceSensor rdf:type ewe-presence:PresenceDetectedAtDistance. ewe-presence:PresenceSensor ewe:sensorID '5544'. ewe-presence:PresenceSensor ewe:distance 0." } If the event accomplish the rule, the server response will contain all the actions that must be triggered: .. code:: { "success":"1", "actions": [{ "url":"", "channel":"", "action":"", "parameter":"" }] } However, if the event doesn't accomplish the rule, the server response will be this: .. code:: { 'actions': [], 'success': 1 }