@@ -0,0 +1,2075 @@
+#!/usr/bin/env python%0A# encoding=utf8%0A%0Aimport json%0Aimport requests%0Afrom flexbe_core import EventState, Logger%0A%0A%0Aclass Wonderland_Add_Room(EventState):%0A%09'''%0A%09Add an object to Wonderland.%0A%09For the room, enter only ID or Name, not both.%0A%09Return the ID of the added human.%0A%0A%09#%3E name         string  name of the room%0A%09#%3E x1           int     position of the room%0A%09#%3E x2           int     position of the room%0A%09#%3E x3           int     position of the room%0A%09#%3E x4           int     position of the room%0A%09#%3E y1           int     position of the room%0A%09#%3E y2           int     position of the room%0A%09#%3E y3           int     position of the room%0A%09#%3E y4           int     position of the room%0A%0A%09#%3E id           int     ID on the BDD of the room%0A%0A%09%3C= done                 data sent correctly%0A%09%3C= error                error while data is reading%0A%09%3C= already_registered%0A%09'''%0A%09%0A%09def __init__(self):%0A%09%09super(Wonderland_Add_Room, self).__init__(outcomes=%5B'done', 'already_registered', 'error'%5D,%0A%09%09%09%09%09%09%09%09%09%09%09%09%09output_keys=%5B'id'%5D,%0A%09%09%09%09%09%09%09%09%09%09%09%09%09input_keys=%5B'name', 'x1', 'x2', 'x3', 'x4', 'y1', 'y2', 'y3', 'y4'%5D)%0A%09%09# generate post key for authentication%0A%09%09self._header = %7B'api-key': 'asdf'%7D%0A%09%0A%09def execute(self, userdata):%0A%09%09# Generate URL to contact%0A%09%09dataPost = %7B'name': userdata.name, 'x1': userdata.x1, 'x2': userdata.x2, 'x3': userdata.x3,'x4': userdata.x4,%0A%09%09%09%09%09'y1': userdata.y1, 'y2': userdata.y2, 'y3': userdata.y3, 'y4': userdata.y4%7D%0A%09%09%0A%09%09# try the request%0A%09%09try:%0A%09%09%09response = requests.post(%22http://192.168.0.46:8000/api/rooms/%22, headers=self._header, data=dataPost)%0A%09%09except requests.exceptions.RequestException as e:%0A%09%09%09print e%0A%09%09%09return 'error'%0A%09%09%0A%09%09# read response%0A%09%09data_response = json.loads(response.content)%0A%09%09%0A%09%09# have a response%0A%09%09if not data_response:%0A%09%09%09return 'error'%0A%09%09%0A%09%09# have an a name ID to read%0A%09%09if 'id' not in data_response and 'name' not in data_response:%0A%09%09%09# continue to Error%0A%09%09%09return 'error'%0A%09%09%0A%09%09# have an ID to read%0A%09%09elif 'id' not in data_response:%0A%09%09%09return 'already_registered'%0A%09%09%0A%09%09# return the ID%0A%09%09userdata.id = data_response%5B'id'%5D%0A%09%09%0A%09%09return 'done'%0A

Add a state for add rooms