-
Notifications
You must be signed in to change notification settings - Fork 1
/
kazoo_webhooks.py
67 lines (49 loc) · 1.51 KB
/
kazoo_webhooks.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from flask import Flask
from flask import request
from flask import json
app = Flask(__name__)
def parse_request(req):
"""
Parses application/json request body data into a Python dictionary
"""
return json.dumps(req.json)
@app.route('/')
def api_root():
return 'Welcome guys'
@app.route('/test')
def test():
return "hello this is a test"
@app.route('/github', methods=['POST', 'GET'])
def api_gh_message():
with app.test_request_context('/github', method='POST'):
"""
now you can do something with the request until the
end of the with block, such as basic assertions:
TEST CASE
"""
assert request.path == '/github'
assert request.method == 'POST'
print('assertions passed')
payload = parse_request(request)
if payload == 'null':
return "Welcome to GitHub."
else:
if request.headers['Content-Type'] == 'application/json':
get_info = json.dumps(request.json)
print(get_info)
return get_info
@app.route('/kazoo', methods=['POST'])
def api_kz_hook():
with app.test_request_context('/kazoo', method='POST'):
"""
now you can do something with the request until the
end of the with block, such as basic assertions:
TEMPLATE
"""
assert request.path == '/kazoo'
assert request.method == 'POST'
print('assertions passed')
print(request.form)
return 'ok'
if __name__ == '__main__':
app.run(debug=True)