polyapi-python 0.2.0.dev9__tar.gz → 0.2.1__tar.gz

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.
Files changed (35) hide show
  1. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/PKG-INFO +1 -1
  2. polyapi-python-0.2.1/polyapi/webhook.py +92 -0
  3. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi_python.egg-info/PKG-INFO +1 -1
  4. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/pyproject.toml +1 -1
  5. polyapi-python-0.2.0.dev9/polyapi/webhook.py +0 -85
  6. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/LICENSE +0 -0
  7. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/README.md +0 -0
  8. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/__init__.py +0 -0
  9. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/__main__.py +0 -0
  10. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/api.py +0 -0
  11. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/auth.py +0 -0
  12. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/cli.py +0 -0
  13. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/config.py +0 -0
  14. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/constants.py +0 -0
  15. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/exceptions.py +0 -0
  16. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/execute.py +0 -0
  17. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/function_cli.py +0 -0
  18. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/generate.py +0 -0
  19. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/py.typed +0 -0
  20. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/schema.py +0 -0
  21. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/server.py +0 -0
  22. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/typedefs.py +0 -0
  23. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/utils.py +0 -0
  24. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi/variables.py +0 -0
  25. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi_python.egg-info/SOURCES.txt +0 -0
  26. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi_python.egg-info/dependency_links.txt +0 -0
  27. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi_python.egg-info/requires.txt +0 -0
  28. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/polyapi_python.egg-info/top_level.txt +0 -0
  29. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/setup.cfg +0 -0
  30. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/tests/test_api.py +0 -0
  31. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/tests/test_auth.py +0 -0
  32. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/tests/test_function_cli.py +0 -0
  33. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/tests/test_server.py +0 -0
  34. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/tests/test_utils.py +0 -0
  35. {polyapi-python-0.2.0.dev9 → polyapi-python-0.2.1}/tests/test_variables.py +0 -0
@@ -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
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -0,0 +1,92 @@
1
+ import uuid
2
+ from typing import Any, Dict, List, Tuple
3
+
4
+ from polyapi.typedefs import PropertySpecification
5
+
6
+ WEBHOOK_TEMPLATE = """
7
+ import asyncio
8
+
9
+
10
+ def {function_name}(callback, options=None):
11
+ \"""{description}
12
+
13
+ Function ID: {function_id}
14
+ \"""
15
+ options = options or {{}}
16
+ eventsClientId = "{client_id}"
17
+ function_id = "{function_id}"
18
+
19
+ api_key, base_url = get_api_key_and_url()
20
+
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}")
31
+
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 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")
49
+
50
+ data = {{
51
+ "clientID": eventsClientId,
52
+ "webhookHandleID": function_id,
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()
70
+
71
+ return closeEventHandler
72
+
73
+ return asyncio.run(_inner())
74
+ """
75
+
76
+
77
+ def render_webhook_handle(
78
+ function_type: str,
79
+ function_name: str,
80
+ function_id: str,
81
+ function_description: str,
82
+ arguments: List[PropertySpecification],
83
+ return_type: Dict[str, Any],
84
+ ) -> Tuple[str, str]:
85
+ func_str = WEBHOOK_TEMPLATE.format(
86
+ description=function_description,
87
+ client_id=uuid.uuid4().hex,
88
+ function_id=function_id,
89
+ function_name=function_name,
90
+ )
91
+
92
+ return func_str, ""
@@ -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
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
3
3
 
4
4
  [project]
5
5
  name = "polyapi-python"
6
- version = "0.2.0.dev9"
6
+ version = "0.2.1"
7
7
  description = "The PolyAPI Python Client"
8
8
  authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
9
9
  dependencies = [
@@ -1,85 +0,0 @@
1
- import uuid
2
- from typing import Any, Dict, List, Tuple
3
-
4
- from polyapi.typedefs import PropertySpecification
5
-
6
- WEBHOOK_TEMPLATE = """
7
- async def {function_name}(callback, options=None):
8
- \"""{description}
9
-
10
- Function ID: {function_id}
11
- \"""
12
- options = options or {{}}
13
- eventsClientId = "{client_id}"
14
- function_id = "{function_id}"
15
-
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
-
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)
52
-
53
- async def closeEventHandler():
54
- nonlocal socket
55
- if not socket:
56
- return
57
-
58
- await socket.emit('unregisterWebhookEventHandler', {{
59
- "clientID": eventsClientId,
60
- "webhookHandleID": function_id,
61
- "apiKey": api_key
62
- }}, namespace="/events")
63
-
64
- await socket.wait()
65
-
66
- return closeEventHandler
67
- """
68
-
69
-
70
- def render_webhook_handle(
71
- function_type: str,
72
- function_name: str,
73
- function_id: str,
74
- function_description: str,
75
- arguments: List[PropertySpecification],
76
- return_type: Dict[str, Any],
77
- ) -> Tuple[str, str]:
78
- func_str = WEBHOOK_TEMPLATE.format(
79
- description=function_description,
80
- client_id=uuid.uuid4().hex,
81
- function_id=function_id,
82
- function_name=function_name,
83
- )
84
-
85
- return func_str, ""