konecty-sdk-python 1.0.7__tar.gz → 1.1.0__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.
@@ -15,6 +15,7 @@ from .types import (
15
15
  KonectyLookup,
16
16
  KonectyPersonName,
17
17
  KonectyPhone,
18
+ KonectyUpdateId,
18
19
  KonectyUser,
19
20
  )
20
21
 
@@ -38,4 +39,5 @@ __all__ = [
38
39
  "KonectyFilter",
39
40
  "KonectyFindParams",
40
41
  "KonectyDict",
42
+ "KonectyUpdateId",
41
43
  ]
@@ -9,7 +9,7 @@ import aiohttp
9
9
 
10
10
  from .file_manager import FileManager
11
11
  from .filters import KonectyFilter, KonectyFindParams
12
- from .types import KonectyDateTime
12
+ from .types import KonectyDateTime, KonectyUpdateId
13
13
 
14
14
  # Configura o logger do urllib3 para mostrar apenas erros
15
15
  logging.getLogger("urllib3.connectionpool").setLevel(logging.ERROR)
@@ -217,6 +217,27 @@ class KonectyClient:
217
217
  raise KonectyAPIError(errors)
218
218
  return result.get("data", [None])[0]
219
219
 
220
+ async def update(
221
+ self, module: str, ids: list[KonectyUpdateId], data: KonectyDict
222
+ ) -> list[KonectyDict]:
223
+ endpoint = f"/rest/data/{module}"
224
+ cleaned_data = {
225
+ k: v for k, v in data.items() if k not in KONECTY_UPDATE_IGNORE_FIELDS
226
+ }
227
+ payload = {
228
+ "ids": [id.to_dict() for id in ids],
229
+ "data": json.loads(json.dumps(cleaned_data, default=json_serial)),
230
+ }
231
+ async with (
232
+ aiohttp.ClientSession(base_url=self.base_url) as session,
233
+ session.put(endpoint, headers=self.headers, json=payload) as response,
234
+ ):
235
+ result = await response.json()
236
+ if not result.get("success", False):
237
+ errors = result.get("errors", [])
238
+ raise KonectyAPIError(errors)
239
+ return result.get("data", [])
240
+
220
241
  async def delete_one(
221
242
  self, module: str, id: str, updatedAt: datetime
222
243
  ) -> Optional[KonectyDict]:
@@ -392,3 +392,23 @@ class KonectyPersonName(BaseModel):
392
392
 
393
393
  def to_dict(self) -> dict[str, Any]:
394
394
  return self.model_dump(by_alias=True)
395
+
396
+
397
+ class KonectyUpdateId(BaseModel):
398
+ _id: str = Field(alias="_id")
399
+ _updatedAt: KonectyDateTime = Field(alias="_updatedAt")
400
+
401
+ @classmethod
402
+ def from_dict(cls, data: dict[str, Any]) -> Self:
403
+ id = data.get("_id")
404
+ updatedAt = data.get("_updatedAt")
405
+ if id is None or updatedAt is None:
406
+ raise ValueError("Invalid value for KonectyUpdateIds")
407
+ return cls(id=id, updatedAt=KonectyDateTime.from_any(updatedAt))
408
+
409
+ @classmethod
410
+ def from_list(cls, data: list[dict[str, Any]]) -> list[Self]:
411
+ return [cls.from_dict(item) for item in data]
412
+
413
+ def to_dict(self) -> dict[str, Any]:
414
+ return {"_id": self._id, "_updatedAt": self._updatedAt.to_json()}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: konecty_sdk_python
3
- Version: 1.0.7
3
+ Version: 1.1.0
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "konecty_sdk_python"
3
- version = "1.0.7"
3
+ version = "1.1.0"
4
4
  description = "Konecty SDK Python"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"