| Total Complexity | 8 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | from flask import request, Flask |
||
| 6 | class EchoFlaskSensor(Sensor): |
||
| 7 | |||
| 8 | def __init__(self, sensor_service, config): |
||
| 9 | super(EchoFlaskSensor, self).__init__( |
||
| 10 | sensor_service=sensor_service, |
||
| 11 | config=config |
||
| 12 | ) |
||
| 13 | |||
| 14 | self._host = '127.0.0.1' |
||
| 15 | self._port = '5000' |
||
| 16 | self._path = '/echo' |
||
| 17 | |||
| 18 | self._log = self._sensor_service.get_logger(__name__) |
||
| 19 | self._app = Flask(__name__) |
||
| 20 | |||
| 21 | def setup(self): |
||
| 22 | pass |
||
| 23 | |||
| 24 | def run(self): |
||
| 25 | @self._app.route(self._path, methods=['POST']) |
||
| 26 | def echo(): |
||
| 27 | payload = request.get_json(force=True) |
||
| 28 | self._sensor_service.dispatch(trigger="examples.echo_flask", |
||
| 29 | payload=payload) |
||
| 30 | return request.data |
||
| 31 | |||
| 32 | self._log.info('Listening for payload on http://%s:%s%s' % |
||
| 33 | (self._host, self._port, self._path)) |
||
| 34 | self._app.run(host=self._host, port=self._port, threaded=True) |
||
| 35 | |||
| 36 | def cleanup(self): |
||
| 37 | pass |
||
| 38 | |||
| 39 | def add_trigger(self, trigger): |
||
| 40 | # This method is called when trigger is created |
||
| 41 | pass |
||
| 42 | |||
| 43 | def update_trigger(self, trigger): |
||
| 44 | # This method is called when trigger is updated |
||
| 45 | pass |
||
| 46 | |||
| 47 | def remove_trigger(self, trigger): |
||
| 48 | # This method is called when trigger is deleted |
||
| 49 | pass |
||
| 50 |