konecty-sdk-python 2.0.3__py3-none-any.whl → 2.0.5__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.
@@ -7,16 +7,12 @@ from typing import Any, AsyncGenerator, Dict, List, Literal, Optional, Union, ca
7
7
 
8
8
  import aiohttp
9
9
 
10
- from .exceptions import (
11
- KonectyAPIError,
12
- KonectyError,
13
- KonectyValidationError,
14
- )
10
+ from .exceptions import KonectyAPIError, KonectyError, KonectyValidationError
11
+ from .feature_types.kpi import KpiConfig
15
12
  from .file_manager import FileManager
16
13
  from .filters import KonectyFilter, KonectyFindParams
17
- from .http import request as _http_request
18
14
  from .http import StreamResponse
19
- from .feature_types.kpi import KpiConfig
15
+ from .http import request as _http_request
20
16
  from .serialization import json_serial
21
17
  from .services.aggregation import AggregationService
22
18
  from .services.change_user import ChangeUserService
@@ -104,7 +100,9 @@ class KonectyClient:
104
100
  ...
105
101
  total = result.total
106
102
  """
107
- return await self._stream.find_stream(module, options, include_total=include_total)
103
+ return await self._stream.find_stream(
104
+ module, options, include_total=include_total
105
+ )
108
106
 
109
107
  async def count_stream(
110
108
  self,
@@ -234,13 +232,9 @@ class KonectyClient:
234
232
  self, module: str, data_id: str, comment_id: str, text: str
235
233
  ) -> Any:
236
234
  """Update a comment."""
237
- return await self._comments.update_comment(
238
- module, data_id, comment_id, text
239
- )
235
+ return await self._comments.update_comment(module, data_id, comment_id, text)
240
236
 
241
- async def delete_comment(
242
- self, module: str, data_id: str, comment_id: str
243
- ) -> Any:
237
+ async def delete_comment(self, module: str, data_id: str, comment_id: str) -> Any:
244
238
  """Delete (soft) a comment."""
245
239
  return await self._comments.delete_comment(module, data_id, comment_id)
246
240
 
@@ -248,9 +242,7 @@ class KonectyClient:
248
242
  self, module: str, data_id: str, query: str = ""
249
243
  ) -> Any:
250
244
  """Search users for @mention autocomplete."""
251
- return await self._comments.search_comment_users(
252
- module, data_id, query
253
- )
245
+ return await self._comments.search_comment_users(module, data_id, query)
254
246
 
255
247
  async def search_comments(
256
248
  self,
@@ -330,21 +322,15 @@ class KonectyClient:
330
322
  self._change_user_service = ChangeUserService(self)
331
323
  return self._change_user_service
332
324
 
333
- async def change_user_add(
334
- self, module: str, ids: List[Any], users: Any
335
- ) -> Any:
325
+ async def change_user_add(self, module: str, ids: List[Any], users: Any) -> Any:
336
326
  """Add users to records."""
337
327
  return await self._change_user.add_users(module, ids, users)
338
328
 
339
- async def change_user_remove(
340
- self, module: str, ids: List[Any], users: Any
341
- ) -> Any:
329
+ async def change_user_remove(self, module: str, ids: List[Any], users: Any) -> Any:
342
330
  """Remove users from records."""
343
331
  return await self._change_user.remove_users(module, ids, users)
344
332
 
345
- async def change_user_define(
346
- self, module: str, ids: List[Any], users: Any
347
- ) -> Any:
333
+ async def change_user_define(self, module: str, ids: List[Any], users: Any) -> Any:
348
334
  """Define users on records."""
349
335
  return await self._change_user.define_users(module, ids, users)
350
336
 
@@ -477,6 +463,35 @@ class KonectyClient:
477
463
  raise KonectyAPIError(errors)
478
464
  data = result.get("data", [])
479
465
  return cast(List[KonectyDict], data)
466
+
467
+ async def lookup(self, module: str, lookup_field: str, options: KonectyFindParams, search: str = "") -> List[KonectyDict]:
468
+ params: Dict[str, str] = {}
469
+ for key, value in options.model_dump(exclude_none=True).items():
470
+ params[key] = (
471
+ json.dumps(value, default=json_serial)
472
+ if key != "fields"
473
+ else ",".join(value)
474
+ )
475
+ if search:
476
+ params["search"] = search
477
+
478
+ print(f"params: {params}")
479
+ async with (
480
+ aiohttp.ClientSession() as session,
481
+ session.get(
482
+ f"{self.base_url}/rest/data/{module}/lookup/{lookup_field}",
483
+ params=params,
484
+ headers={"Authorization": self.headers["Authorization"]},
485
+ ) as response,
486
+ ):
487
+ response.raise_for_status()
488
+ result = await response.json()
489
+ if not result.get("success", False):
490
+ errors = result.get("errors", [])
491
+ logger.error(errors)
492
+ raise KonectyAPIError(errors)
493
+ data = result.get("data", [])
494
+ return cast(List[KonectyDict], data)
480
495
 
481
496
  def find_sync(self, module: str, options: KonectyFindParams) -> List[KonectyDict]:
482
497
  """Versão síncrona de find."""
@@ -662,7 +677,7 @@ class KonectyClient:
662
677
  async def get_setting(self, key: str) -> Optional[str]:
663
678
  """Obtém uma configuração do Konecty."""
664
679
  setting = await self.find_one(
665
- "Setting", KonectyFilter.create().add_condition("key", "equals", key)
680
+ "Setting", KonectyFilter.create().add_condition("name", "equals", key)
666
681
  )
667
682
  if setting is None:
668
683
  return None
@@ -671,13 +686,15 @@ class KonectyClient:
671
686
  def get_setting_sync(self, key: str) -> Optional[str]:
672
687
  """Versão síncrona de get_setting."""
673
688
  setting = self.find_one_sync(
674
- "Setting", KonectyFilter.create().add_condition("key", "equals", key)
689
+ "Setting", KonectyFilter.create().add_condition("name", "equals", key)
675
690
  )
676
691
  if setting is None:
677
692
  return None
678
693
  return cast(str, setting.get("value"))
679
694
 
680
- async def get_settings(self, keys: List[str]) -> Dict[str, str]:
695
+ async def get_settings(
696
+ self, keys: List[str], *, module: str | None = None
697
+ ) -> Dict[str, str]:
681
698
  """Obtém múltiplas configurações do Konecty.
682
699
 
683
700
  Args:
@@ -689,7 +706,9 @@ class KonectyClient:
689
706
  if not keys:
690
707
  return {}
691
708
 
692
- filter_params = KonectyFilter.create().add_condition("key", "in", keys)
709
+ filter_params = KonectyFilter.create().add_condition("name", "in", keys)
710
+ if module:
711
+ filter_params.add_condition("module", "equals", module)
693
712
  find_params = KonectyFindParams(filter=filter_params)
694
713
 
695
714
  settings = await self.find("Setting", find_params)
@@ -697,13 +716,15 @@ class KonectyClient:
697
716
  result = {}
698
717
 
699
718
  for setting in settings:
700
- key = setting.get("key")
719
+ key = setting.get("name")
701
720
  value = setting.get("value")
702
721
  result[key] = cast(str, value)
703
722
 
704
723
  return result
705
724
 
706
- def get_settings_sync(self, keys: List[str]) -> Dict[str, str]:
725
+ def get_settings_sync(
726
+ self, keys: List[str], *, module: str | None = None
727
+ ) -> Dict[str, str]:
707
728
  """Versão síncrona de get_settings.
708
729
 
709
730
  Args:
@@ -715,7 +736,9 @@ class KonectyClient:
715
736
  if not keys:
716
737
  return {}
717
738
 
718
- filter_params = KonectyFilter.create().add_condition("key", "in", keys)
739
+ filter_params = KonectyFilter.create().add_condition("name", "in", keys)
740
+ if module:
741
+ filter_params.add_condition("module", "equals", module)
719
742
  find_params = KonectyFindParams(filter=filter_params)
720
743
 
721
744
  settings = self.find_sync("Setting", find_params)
@@ -723,7 +746,7 @@ class KonectyClient:
723
746
  result = {}
724
747
 
725
748
  for setting in settings:
726
- key = setting.get("key")
749
+ key = setting.get("name")
727
750
  value = setting.get("value")
728
751
  result[key] = cast(str, value)
729
752
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: konecty_sdk_python
3
- Version: 2.0.3
3
+ Version: 2.0.5
4
4
  Summary: Konecty SDK Python
5
5
  Author-email: Leonardo Leal <leonardo.leal@konecty.com>, Derotino Silveira <derotino.silveira@konecty.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ KonectySdkPython/cli/apply.py,sha256=LyPoNcsU3oz9P_eTAi4BdtJHWkbp-sNK_SP9W8Xua04
4
4
  KonectySdkPython/cli/backup.py,sha256=rcla3EWfPsy-vWgmDK844EaM5u3h7JF-u7-b2HUBMgA,4785
5
5
  KonectySdkPython/cli/pull.py,sha256=n4gIkKtuEpPKULb3zcYu5tZlBLbt_4oNQDeu2l6tHxU,9529
6
6
  KonectySdkPython/lib/__init__.py,sha256=Du8jLNfFG1bQuHX5u7pAhbyV9TjC7Ie9K1Xo1KSUqqc,995
7
- KonectySdkPython/lib/client.py,sha256=eN8FBn9-xGbkKkU7wZ7O1Hkl-MA4XjYEU1BUOjpsvrg,30608
7
+ KonectySdkPython/lib/client.py,sha256=jX1_ayUYF_vMQuCj0Kuk1Fhw3SYie-RJ8Ekna9uUWSo,31954
8
8
  KonectySdkPython/lib/exceptions.py,sha256=HR48cd-cptFPoObr37NcvDrdkb-RtxKRteQoG-tuPkk,529
9
9
  KonectySdkPython/lib/file_manager.py,sha256=CLpOJWdA1tb2iq0qOIeRyEEIuACRq9tIo7Rls1YT2ig,9986
10
10
  KonectySdkPython/lib/filters.py,sha256=PsFaUFCEyKgxgzD566LdTLvuMJevoF_i9U1WnpJZzPQ,4482
@@ -28,7 +28,7 @@ KonectySdkPython/lib/services/notifications.py,sha256=7AtCBbBl-YAz_RBIW6bzoKvuws
28
28
  KonectySdkPython/lib/services/query.py,sha256=vCqbf0QdV8Blh8Hfsvq6Ne1-YFuC5siw1gVa7ZBGs_k,6605
29
29
  KonectySdkPython/lib/services/stream.py,sha256=1DMVxcg9Ymk2NgX0Qfvpjrr6vZJo5iFovPFT1NA3_CY,4737
30
30
  KonectySdkPython/lib/services/subscriptions.py,sha256=_Jq8jW7YkL_hwLNte1bWgrr4D2EMZUUSOXUgnRoGGK4,1022
31
- konecty_sdk_python-2.0.3.dist-info/METADATA,sha256=nTSe_aYWRydmKe_nUi4-NO9iM1wlDX3kUSNlln4qqlo,1622
32
- konecty_sdk_python-2.0.3.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
33
- konecty_sdk_python-2.0.3.dist-info/entry_points.txt,sha256=awf962DamFgy791G3PsJ354edBMLJg16Dqi-2Y1tb9s,58
34
- konecty_sdk_python-2.0.3.dist-info/RECORD,,
31
+ konecty_sdk_python-2.0.5.dist-info/METADATA,sha256=GNN5r6m-JKJaOiwghqtS-IscpxYTmQB-Or5JMgI3PeA,1622
32
+ konecty_sdk_python-2.0.5.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
33
+ konecty_sdk_python-2.0.5.dist-info/entry_points.txt,sha256=awf962DamFgy791G3PsJ354edBMLJg16Dqi-2Y1tb9s,58
34
+ konecty_sdk_python-2.0.5.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.29.0
2
+ Generator: hatchling 1.30.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any