polyapi-python 0.2.0.dev9__py3-none-any.whl → 0.2.1.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- polyapi/webhook.py +51 -44
- {polyapi_python-0.2.0.dev9.dist-info → polyapi_python-0.2.1.dev1.dist-info}/METADATA +1 -1
- {polyapi_python-0.2.0.dev9.dist-info → polyapi_python-0.2.1.dev1.dist-info}/RECORD +6 -6
- {polyapi_python-0.2.0.dev9.dist-info → polyapi_python-0.2.1.dev1.dist-info}/LICENSE +0 -0
- {polyapi_python-0.2.0.dev9.dist-info → polyapi_python-0.2.1.dev1.dist-info}/WHEEL +0 -0
- {polyapi_python-0.2.0.dev9.dist-info → polyapi_python-0.2.1.dev1.dist-info}/top_level.txt +0 -0
polyapi/webhook.py
CHANGED
|
@@ -4,7 +4,10 @@ from typing import Any, Dict, List, Tuple
|
|
|
4
4
|
from polyapi.typedefs import PropertySpecification
|
|
5
5
|
|
|
6
6
|
WEBHOOK_TEMPLATE = """
|
|
7
|
-
|
|
7
|
+
import asyncio
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def {function_name}(callback, options=None):
|
|
8
11
|
\"""{description}
|
|
9
12
|
|
|
10
13
|
Function ID: {function_id}
|
|
@@ -14,56 +17,60 @@ async def {function_name}(callback, options=None):
|
|
|
14
17
|
function_id = "{function_id}"
|
|
15
18
|
|
|
16
19
|
api_key, base_url = get_api_key_and_url()
|
|
17
|
-
socket = socketio.AsyncClient()
|
|
18
|
-
await socket.connect(base_url, transports=['websocket'], namespaces=['/events'])
|
|
19
|
-
|
|
20
|
-
def registerCallback(registered: bool):
|
|
21
|
-
nonlocal socket
|
|
22
|
-
if registered:
|
|
23
|
-
socket.on('handleWebhookEvent:{function_id}', handleEvent, namespace="/events")
|
|
24
|
-
else:
|
|
25
|
-
print("Could not set register webhook event handler for {function_id}")
|
|
26
|
-
|
|
27
|
-
async def handleEvent(data):
|
|
28
|
-
nonlocal api_key
|
|
29
|
-
nonlocal options
|
|
30
|
-
polyCustom = {{}}
|
|
31
|
-
resp = await callback(data.get("body"), data.get("headers"), data.get("params"), polyCustom)
|
|
32
|
-
if resp and options.get("waitForResponse"):
|
|
33
|
-
await socket.emit('setWebhookListenerResponse', {{
|
|
34
|
-
"webhookHandleID": function_id,
|
|
35
|
-
"apiKey": api_key,
|
|
36
|
-
"clientID": eventsClientId,
|
|
37
|
-
"executionId": data.get("executionId"),
|
|
38
|
-
"response": {{
|
|
39
|
-
"data": resp,
|
|
40
|
-
"statusCode": polyCustom.get("responseStatusCode", 200),
|
|
41
|
-
"contentType": polyCustom.get("responseContentType", None),
|
|
42
|
-
}},
|
|
43
|
-
}}, namespace="/events")
|
|
44
20
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
21
|
+
async def _inner():
|
|
22
|
+
socket = socketio.AsyncClient()
|
|
23
|
+
await socket.connect(base_url, transports=['websocket'], namespaces=['/events'])
|
|
24
|
+
|
|
25
|
+
def registerCallback(registered: bool):
|
|
26
|
+
nonlocal socket
|
|
27
|
+
if registered:
|
|
28
|
+
socket.on('handleWebhookEvent:{function_id}', handleEvent, namespace="/events")
|
|
29
|
+
else:
|
|
30
|
+
print("Could not set register webhook event handler for {function_id}")
|
|
52
31
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
32
|
+
async def handleEvent(data):
|
|
33
|
+
nonlocal api_key
|
|
34
|
+
nonlocal options
|
|
35
|
+
polyCustom = {{}}
|
|
36
|
+
resp = await callback(data.get("body"), data.get("headers"), data.get("params"), polyCustom)
|
|
37
|
+
if resp and options.get("waitForResponse"):
|
|
38
|
+
await socket.emit('setWebhookListenerResponse', {{
|
|
39
|
+
"webhookHandleID": function_id,
|
|
40
|
+
"apiKey": api_key,
|
|
41
|
+
"clientID": eventsClientId,
|
|
42
|
+
"executionId": data.get("executionId"),
|
|
43
|
+
"response": {{
|
|
44
|
+
"data": resp,
|
|
45
|
+
"statusCode": polyCustom.get("responseStatusCode", 200),
|
|
46
|
+
"contentType": polyCustom.get("responseContentType", None),
|
|
47
|
+
}},
|
|
48
|
+
}}, namespace="/events")
|
|
57
49
|
|
|
58
|
-
|
|
50
|
+
data = {{
|
|
59
51
|
"clientID": eventsClientId,
|
|
60
52
|
"webhookHandleID": function_id,
|
|
61
|
-
"apiKey": api_key
|
|
62
|
-
|
|
53
|
+
"apiKey": api_key,
|
|
54
|
+
"waitForResponse": options.get("waitForResponse"),
|
|
55
|
+
}}
|
|
56
|
+
await socket.emit('registerWebhookEventHandler', data, namespace="/events", callback=registerCallback)
|
|
57
|
+
|
|
58
|
+
async def closeEventHandler():
|
|
59
|
+
nonlocal socket
|
|
60
|
+
if not socket:
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
await socket.emit('unregisterWebhookEventHandler', {{
|
|
64
|
+
"clientID": eventsClientId,
|
|
65
|
+
"webhookHandleID": function_id,
|
|
66
|
+
"apiKey": api_key
|
|
67
|
+
}}, namespace="/events")
|
|
68
|
+
|
|
69
|
+
await socket.wait()
|
|
63
70
|
|
|
64
|
-
|
|
71
|
+
return closeEventHandler
|
|
65
72
|
|
|
66
|
-
return
|
|
73
|
+
return asyncio.run(inner())
|
|
67
74
|
"""
|
|
68
75
|
|
|
69
76
|
|
|
@@ -15,9 +15,9 @@ polyapi/server.py,sha256=mcbH8pG16fFMiFL52wdii0217ZLsznQnElAFEvXZ7IA,2211
|
|
|
15
15
|
polyapi/typedefs.py,sha256=RZ3I6sgJm_5MuuORG1QjUE-UJy_z2WRXNdiWjEdLvQg,1371
|
|
16
16
|
polyapi/utils.py,sha256=wZQrwSOst5wyoYYLoMk1DnAEbVsJ0-2YkmmDQ9gI3FY,5399
|
|
17
17
|
polyapi/variables.py,sha256=d36-trnfTL_8m2NkorMiImb4O3UrJbiFV38CHxV5i0A,4200
|
|
18
|
-
polyapi/webhook.py,sha256=
|
|
19
|
-
polyapi_python-0.2.
|
|
20
|
-
polyapi_python-0.2.
|
|
21
|
-
polyapi_python-0.2.
|
|
22
|
-
polyapi_python-0.2.
|
|
23
|
-
polyapi_python-0.2.
|
|
18
|
+
polyapi/webhook.py,sha256=fzUWzRShh602qEgi_L_6tPOsFojBGlDAb-lzdoTzJnc,2931
|
|
19
|
+
polyapi_python-0.2.1.dev1.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
|
|
20
|
+
polyapi_python-0.2.1.dev1.dist-info/METADATA,sha256=KFzcwNwjwyECQ93gaeoqGTJX_wq7qDWsHx93WsMDRMg,4823
|
|
21
|
+
polyapi_python-0.2.1.dev1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
22
|
+
polyapi_python-0.2.1.dev1.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
|
|
23
|
+
polyapi_python-0.2.1.dev1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|