polyapi-python 0.2.4.dev8__py3-none-any.whl → 0.2.4.dev10__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/error_handler.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import asyncio
2
2
  import copy
3
3
  import socketio # type: ignore
4
+ from socketio.exceptions import ConnectionError # type: ignore
4
5
  from typing import Any, Callable, Dict, List, Optional
5
6
 
6
7
  from polyapi.config import get_api_key_and_url
@@ -28,7 +29,7 @@ async def get_client_and_connect():
28
29
 
29
30
 
30
31
  async def unregister(data: Dict[str, Any]):
31
- print(f"stopping error handler for '{data['path']}'...")
32
+ print(f"Stopping error handler for {data['path']}...")
32
33
  assert client
33
34
  await client.emit(
34
35
  "unregisterErrorHandler",
@@ -40,14 +41,17 @@ async def unregister(data: Dict[str, Any]):
40
41
  async def unregister_all():
41
42
  _, base_url = get_api_key_and_url()
42
43
  # need to reconnect because maybe socketio client disconnected after Ctrl+C?
43
- await client.connect(base_url, transports=["websocket"], namespaces=["/events"])
44
+ try:
45
+ await client.connect(base_url, transports=["websocket"], namespaces=["/events"])
46
+ except ConnectionError:
47
+ pass
44
48
  await asyncio.gather(*[unregister(handler) for handler in active_handlers])
45
49
 
46
50
 
47
51
  async def on(
48
52
  path: str, callback: Callable, options: Optional[Dict[str, Any]] = None
49
53
  ) -> None:
50
- print(f"starting error handler for {path}...")
54
+ print(f"Starting error handler for {path}...")
51
55
 
52
56
  if not client:
53
57
  raise Exception("Client not initialized. Abort!")
polyapi/generate.py CHANGED
@@ -176,6 +176,7 @@ def render_spec(spec: SpecificationDto):
176
176
  function_type = spec["type"]
177
177
  function_description = spec["description"]
178
178
  function_name = spec["name"]
179
+ function_context = spec["context"]
179
180
  function_id = spec["id"]
180
181
 
181
182
  arguments: List[PropertySpecification] = []
@@ -223,6 +224,7 @@ def render_spec(spec: SpecificationDto):
223
224
  elif function_type == "webhookHandle":
224
225
  func_str, func_type_defs = render_webhook_handle(
225
226
  function_type,
227
+ function_context,
226
228
  function_name,
227
229
  function_id,
228
230
  function_description,
polyapi/utils.py CHANGED
@@ -165,4 +165,13 @@ def parse_arguments(function_name: str, arguments: List[PropertySpecification])
165
165
  arg_string += f", # {description}\n"
166
166
  else:
167
167
  arg_string += ",\n"
168
- return arg_string.rstrip("\n"), "\n\n".join(args_def)
168
+ return arg_string.rstrip("\n"), "\n\n".join(args_def)
169
+
170
+
171
+ def poly_full_path(context, name) -> str:
172
+ """get the functions path as it will be exposed in the poly library"""
173
+ if context:
174
+ path = context + "." + name
175
+ else:
176
+ path = name
177
+ return f"poly.{path}"
polyapi/webhook.py CHANGED
@@ -1,10 +1,12 @@
1
1
  import asyncio
2
2
  import socketio # type: ignore
3
+ from socketio.exceptions import ConnectionError # type: ignore
3
4
  import uuid
4
5
  from typing import Any, Dict, List, Tuple
5
6
 
6
7
  from polyapi.config import get_api_key_and_url
7
8
  from polyapi.typedefs import PropertySpecification
9
+ from polyapi.utils import poly_full_path
8
10
 
9
11
  # all active webhook handlers, used by unregister_all to cleanup
10
12
  active_handlers: List[Dict[str, Any]] = []
@@ -23,7 +25,7 @@ async def {function_name}(callback, options=None):
23
25
  \"""
24
26
  from polyapi.webhook import client, active_handlers
25
27
 
26
- print("Starting webhook for {function_name}...")
28
+ print("Starting webhook for {function_path}...")
27
29
 
28
30
  if not client:
29
31
  raise Exception("Client not initialized. Abort!")
@@ -65,7 +67,7 @@ async def {function_name}(callback, options=None):
65
67
  "waitForResponse": options.get("waitForResponse"),
66
68
  }}
67
69
  await client.emit('registerWebhookEventHandler', data, namespace="/events", callback=registerCallback)
68
- active_handlers.append({{"clientID": eventsClientId, "webhookHandleID": function_id, "apiKey": api_key}})
70
+ active_handlers.append({{"clientID": eventsClientId, "webhookHandleID": function_id, "apiKey": api_key, "path": "{function_path}"}})
69
71
  """
70
72
 
71
73
 
@@ -77,7 +79,7 @@ async def get_client_and_connect():
77
79
 
78
80
 
79
81
  async def unregister(data: Dict[str, Any]):
80
- print(f"stopping webhook handler for '{data['webhookHandleID']}'...")
82
+ print(f"Stopping webhook handler for {data['path']}...")
81
83
  assert client
82
84
  await client.emit(
83
85
  "unregisterWebhookEventHandler",
@@ -92,13 +94,18 @@ async def unregister(data: Dict[str, Any]):
92
94
 
93
95
  async def unregister_all():
94
96
  _, base_url = get_api_key_and_url()
95
- # need to reconnect because maybe socketio client disconnected after Ctrl+C?
96
- await client.connect(base_url, transports=["websocket"], namespaces=["/events"])
97
+ # maybe need to reconnect because maybe socketio client disconnected after Ctrl+C?
98
+ # feels like Linux disconnects but Windows stays connected
99
+ try:
100
+ await client.connect(base_url, transports=["websocket"], namespaces=["/events"])
101
+ except ConnectionError:
102
+ pass
97
103
  await asyncio.gather(*[unregister(handler) for handler in active_handlers])
98
104
 
99
105
 
100
106
  def render_webhook_handle(
101
107
  function_type: str,
108
+ function_context: str,
102
109
  function_name: str,
103
110
  function_id: str,
104
111
  function_description: str,
@@ -110,6 +117,7 @@ def render_webhook_handle(
110
117
  client_id=uuid.uuid4().hex,
111
118
  function_id=function_id,
112
119
  function_name=function_name,
120
+ function_path=poly_full_path(function_context, function_name),
113
121
  )
114
122
 
115
123
  return func_str, ""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.4.dev8
3
+ Version: 0.2.4.dev10
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -6,21 +6,21 @@ polyapi/cli.py,sha256=xlKH4cSmSo7eXbyXCLWyL4rXM1QFsltC_MxoxMPgt6I,2187
6
6
  polyapi/client.py,sha256=8k50Vwg9HnmHHTyfKH1vfMJqF0jnnVMsWuWI9AfASkM,761
7
7
  polyapi/config.py,sha256=S8TU10upy5OW1_vX-CqQTJD-ZOB6329aMjiUCmukfUI,2292
8
8
  polyapi/constants.py,sha256=NGjso6K5rGnE8TGdrXmdEfvvr-HI3DTVGwOYiWO68LM,511
9
- polyapi/error_handler.py,sha256=i_jtG6qBBUgU8z1poT8PN1wB9sHgBP1zeLSW24fSO00,2282
9
+ polyapi/error_handler.py,sha256=I_e0iz6VM23FLVQWJljxs2NGcl_OODbi43OcbnqBlp8,2398
10
10
  polyapi/exceptions.py,sha256=Zh7i7eCUhDuXEdUYjatkLFTeZkrx1BJ1P5ePgbJ9eIY,89
11
11
  polyapi/execute.py,sha256=kXnvlNQ7nz9cRlV2_5gXH09UCmyiDP5zi3wiAw0uDuk,1943
12
12
  polyapi/function_cli.py,sha256=F0cb5MGcmFvspgwxptWq_2e50X5NNno0B0p8Vgu_oNI,9129
13
- polyapi/generate.py,sha256=O1lb7rLsce7tItIrMx1EbWzRlAKKOp-7upNM80cMmMw,8499
13
+ polyapi/generate.py,sha256=fNEBy3ALEu4m1GEEcly-5u-Y1i3G6EWMKKgCyBBJsqc,8568
14
14
  polyapi/poly_custom.py,sha256=IQRZIMGs0CXotbn71_wyHMinSkoBwKdFdgv90VLYV90,173
15
15
  polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  polyapi/schema.py,sha256=1a7nIO867Xy3bagmPUNdYMxtS5OoCAv8oKIbYgj55dk,2957
17
17
  polyapi/server.py,sha256=iXUR1Kd5TnWK-V5qHhvFvQuHx-3IcTv8WChXVY5Mbog,1882
18
18
  polyapi/typedefs.py,sha256=a5WfHaAvjeql3y1iA3_SkpUztTbKvS5bPqkVxkCvr9E,1459
19
- polyapi/utils.py,sha256=UD3uV3kzt2w23zxAdHCUROhdvtdO44KCJIpqnFwEhqE,5937
19
+ polyapi/utils.py,sha256=86OSrkXlaB0HZppkItT9Xp3m2LBfIT4nPIhyBkIJ0OU,6164
20
20
  polyapi/variables.py,sha256=d36-trnfTL_8m2NkorMiImb4O3UrJbiFV38CHxV5i0A,4200
21
- polyapi/webhook.py,sha256=AAioBn4H3gp7Zaxyp5_MnW-61rAIggi4T6WisgHpz1k,3977
22
- polyapi_python-0.2.4.dev8.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
23
- polyapi_python-0.2.4.dev8.dist-info/METADATA,sha256=VEizn1nBPNVNIOSUSeT67sxfd33N4AKxagz6IyHkcZU,4867
24
- polyapi_python-0.2.4.dev8.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
25
- polyapi_python-0.2.4.dev8.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
26
- polyapi_python-0.2.4.dev8.dist-info/RECORD,,
21
+ polyapi/webhook.py,sha256=bNDfdeFGaRHk8yFAvGK94Pys9jZQ48q8bO9BV579DC8,4317
22
+ polyapi_python-0.2.4.dev10.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
23
+ polyapi_python-0.2.4.dev10.dist-info/METADATA,sha256=eCYlh-nZAnYdlaSuywh_kGcbrelBV0qZjxXeyOGUfDM,4868
24
+ polyapi_python-0.2.4.dev10.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
25
+ polyapi_python-0.2.4.dev10.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
26
+ polyapi_python-0.2.4.dev10.dist-info/RECORD,,