webthing/server.py
def post(self, thing_id='0'):
        """
        Handle a POST request.

        thing_id -- ID of the thing this request is for
        """
        thing = self.get_thing(thing_id)
        if thing is None:
            self.set_status(404)
            return

        try:
            message = json.loads(self.request.body.decode())
        except ValueError:
            self.set_status(400)
            return

        response = {}
        for action_name, action_params in message.items():
            input_ = None
            if 'input' in action_params:
                input_ = action_params['input']

            action = thing.perform_action(action_name, input_)
            if action:
                response.update(action.as_action_description())

                # Start the action
                tornado.ioloop.IOLoop.current().spawn_callback(
                    perform_action,
                    action,
                )

        self.set_status(201)
        self.write(json.dumps(response))
def post(self, thing_id='0'):
        thing = self.get_thing(thing_id)
        if thing is None:
            self.set_status(404)
            return

        try:
            message = json.loads(self.request.body.decode())
        except ValueError:
            self.set_status(400)
            return

        response = {}
        for action_name, action_params in message.items():
            input_ = None
            if 'input' in action_params:
                input_ = action_params['input']

            action = thing.perform_action(action_name, input_)
            if action:
                response.update(action.as_action_description())

                # Start the action
                tornado.ioloop.IOLoop.current().spawn_callback(
                    perform_action,
                    action,
                )

        self.set_status(201)
        self.write(json.dumps(response))
def post ( self , thing_id = '0' ) : thing = self . get_thing ( thing_id ) if thing is None : self . set_status ( 404 ) return try : message = json . loads ( self . request . body . decode ( ) ) except ValueError : self . set_status ( 400 ) return response = { } for action_name , action_params in message . items ( ) : input_ = None if 'input' in action_params : input_ = action_params [ 'input' ] action = thing . perform_action ( action_name , input_ ) if action : response . update ( action . as_action_description ( ) ) # Start the action tornado . ioloop . IOLoop . current ( ) . spawn_callback ( perform_action , action , ) self . set_status ( 201 ) self . write ( json . dumps ( response ) )
Handle a POST request.

        thing_id -- ID of the thing this request is for
Handle a POST request .