-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
40 lines (34 loc) · 801 Bytes
/
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
import json
from bottle import HTTPResponse
def ping_response():
return HTTPResponse(
status=200
)
def start_response(color):
assert type(color) is str, \
"Color value must be string"
return HTTPResponse(
status=200,
headers={
"Content-Type": "application/json"
},
body=json.dumps({
"color": color
})
)
def move_response(move):
assert move in ['up', 'down', 'left', 'right'], \
"Move must be one of [up, down, left, right]"
return HTTPResponse(
status=200,
headers={
"Content-Type": "application/json"
},
body=json.dumps({
"move": move
})
)
def end_response():
return HTTPResponse(
status=200
)