forked from davidespano/ideas-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
49 lines (36 loc) · 1.04 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import flask
from flask import request, jsonify
from test import *
from input_object import *
from output_object import *
from check_template import *
app = flask.Flask(__name__)
app.config["DEBUG"] = True
@app.route('/', methods=['GET'])
def home():
input_object = pupin_input()
res = validate_input(input_object)
return jsonify(res)
@app.route('/simulator', methods=['POST'])
def simulator():
content = request.json
res = validate_input(content)
if res['valid']:
val = pupin_output()
val['valid'] = True
val['description'] = 'Ok'
return jsonify(val)
else:
return jsonify(res)
@app.route('/output', methods=['GET'])
def test_output():
input_object = pupin_output()
res = validate_output(input_object)
return jsonify(res)
def validate_output(output_object):
template = template_output()
return check_field(output_object, template, "")
def validate_input(input_object):
template = template_input()
return check_field(input_object, template, "")
app.run()