polyapi-python 0.2.0.dev9__py3-none-any.whl → 0.2.1.dev0__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 CHANGED
@@ -4,7 +4,7 @@ from typing import Any, Dict, List, Tuple
4
4
  from polyapi.typedefs import PropertySpecification
5
5
 
6
6
  WEBHOOK_TEMPLATE = """
7
- async def {function_name}(callback, options=None):
7
+ def {function_name}(callback, options=None):
8
8
  \"""{description}
9
9
 
10
10
  Function ID: {function_id}
@@ -14,56 +14,60 @@ async def {function_name}(callback, options=None):
14
14
  function_id = "{function_id}"
15
15
 
16
16
  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
17
 
45
- data = {{
46
- "clientID": eventsClientId,
47
- "webhookHandleID": function_id,
48
- "apiKey": api_key,
49
- "waitForResponse": options.get("waitForResponse"),
50
- }}
51
- await socket.emit('registerWebhookEventHandler', data, namespace="/events", callback=registerCallback)
18
+ async def _inner():
19
+ socket = socketio.AsyncClient()
20
+ await socket.connect(base_url, transports=['websocket'], namespaces=['/events'])
52
21
 
53
- async def closeEventHandler():
54
- nonlocal socket
55
- if not socket:
56
- return
22
+ def registerCallback(registered: bool):
23
+ nonlocal socket
24
+ if registered:
25
+ socket.on('handleWebhookEvent:{function_id}', handleEvent, namespace="/events")
26
+ else:
27
+ print("Could not set register webhook event handler for {function_id}")
57
28
 
58
- await socket.emit('unregisterWebhookEventHandler', {{
29
+ async def handleEvent(data):
30
+ nonlocal api_key
31
+ nonlocal options
32
+ polyCustom = {{}}
33
+ resp = await callback(data.get("body"), data.get("headers"), data.get("params"), polyCustom)
34
+ if resp and options.get("waitForResponse"):
35
+ await socket.emit('setWebhookListenerResponse', {{
36
+ "webhookHandleID": function_id,
37
+ "apiKey": api_key,
38
+ "clientID": eventsClientId,
39
+ "executionId": data.get("executionId"),
40
+ "response": {{
41
+ "data": resp,
42
+ "statusCode": polyCustom.get("responseStatusCode", 200),
43
+ "contentType": polyCustom.get("responseContentType", None),
44
+ }},
45
+ }}, namespace="/events")
46
+
47
+ data = {{
59
48
  "clientID": eventsClientId,
60
49
  "webhookHandleID": function_id,
61
- "apiKey": api_key
62
- }}, namespace="/events")
50
+ "apiKey": api_key,
51
+ "waitForResponse": options.get("waitForResponse"),
52
+ }}
53
+ await socket.emit('registerWebhookEventHandler', data, namespace="/events", callback=registerCallback)
54
+
55
+ async def closeEventHandler():
56
+ nonlocal socket
57
+ if not socket:
58
+ return
59
+
60
+ await socket.emit('unregisterWebhookEventHandler', {{
61
+ "clientID": eventsClientId,
62
+ "webhookHandleID": function_id,
63
+ "apiKey": api_key
64
+ }}, namespace="/events")
65
+
66
+ await socket.wait()
63
67
 
64
- await socket.wait()
68
+ return closeEventHandler
65
69
 
66
- return closeEventHandler
70
+ return asyncio.run(inner())
67
71
  """
68
72
 
69
73
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.0.dev9
3
+ Version: 0.2.1.dev0
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -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=d-qCnZs5d8m4x4YX-QSsvwAwWWD4ZIyhVcMFlXFolCk,2690
19
- polyapi_python-0.2.0.dev9.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
20
- polyapi_python-0.2.0.dev9.dist-info/METADATA,sha256=vDqk474YSS3jOw04armGAxCgeUM8qmBuOnk7F9KCMWA,4823
21
- polyapi_python-0.2.0.dev9.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
22
- polyapi_python-0.2.0.dev9.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
23
- polyapi_python-0.2.0.dev9.dist-info/RECORD,,
18
+ polyapi/webhook.py,sha256=yHfcLjlr-zmlsM39AgBVLX2_MJOH10GRLxTb0JeWjrI,2914
19
+ polyapi_python-0.2.1.dev0.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
20
+ polyapi_python-0.2.1.dev0.dist-info/METADATA,sha256=tjRWo5WiDU2UxkBkSdaWyW3fiaFfyGUFgdB2xPY_llI,4823
21
+ polyapi_python-0.2.1.dev0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
22
+ polyapi_python-0.2.1.dev0.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
23
+ polyapi_python-0.2.1.dev0.dist-info/RECORD,,