rcer-iot-client-pkg 0.5.0__tar.gz → 0.5.2__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 (46) hide show
  1. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/PKG-INFO +14 -8
  2. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/README.md +13 -7
  3. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/pyproject.toml +1 -1
  4. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/__init__.py +2 -1
  5. rcer_iot_client_pkg-0.5.2/src/rcer_iot_client_pkg/general_types/api/__init__.py +3 -0
  6. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/general_types/error_types/api/update_thies_data_error_types.py +14 -1
  7. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/sharepoint_client/clients/sharepoint_rest_api.py +15 -10
  8. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/services/epii/controllers/update_thies_data.py +3 -3
  9. rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/libs/async_http_client/__init__.py +0 -10
  10. rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/libs/async_http_client/async_http_client.py +0 -34
  11. rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/libs/async_http_client/async_http_client_contract.py +0 -29
  12. rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/libs/async_http_client/clients/aiohttp_client.py +0 -50
  13. rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/libs/async_http_client/types/__init__.py +0 -3
  14. rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/libs/async_http_client/types/async_http_client_types.py +0 -17
  15. rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/libs/ftp_client/clients/__init__.py +0 -0
  16. rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/services/epii/__init__.py +0 -0
  17. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/LICENSE +0 -0
  18. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/general_types/__init__.py +0 -0
  19. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/general_types/api/update_thies_data_types.py +0 -0
  20. {rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/general_types/api → rcer_iot_client_pkg-0.5.2/src/rcer_iot_client_pkg/general_types/error_types}/__init__.py +0 -0
  21. {rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/general_types/error_types → rcer_iot_client_pkg-0.5.2/src/rcer_iot_client_pkg/general_types/error_types/api}/__init__.py +0 -0
  22. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/general_types/error_types/common/__init__.py +0 -0
  23. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/general_types/error_types/common/common_types.py +0 -0
  24. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/ftp_client/__init__.py +0 -0
  25. {rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/general_types/error_types/api → rcer_iot_client_pkg-0.5.2/src/rcer_iot_client_pkg/libs/ftp_client/clients}/__init__.py +0 -0
  26. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/ftp_client/clients/aioftp_client.py +0 -0
  27. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/ftp_client/ftp_client.py +0 -0
  28. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/ftp_client/ftp_client_contract.py +0 -0
  29. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/ftp_client/types/__init__.py +0 -0
  30. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/ftp_client/types/ftp_client_types.py +0 -0
  31. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/sharepoint_client/__init__.py +0 -0
  32. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/sharepoint_client/sharepoint_client.py +0 -0
  33. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/sharepoint_client/sharepoint_client_contract.py +0 -0
  34. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/sharepoint_client/types/sharepoint_client_types.py +0 -0
  35. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/libs/zero_dependency/utils/datetime_utils.py +0 -0
  36. {rcer_iot_client_pkg-0.5.0/src/rcer_iot_client_pkg/libs/async_http_client/clients → rcer_iot_client_pkg-0.5.2/src/rcer_iot_client_pkg/services/epii}/__init__.py +0 -0
  37. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/services/epii/api.py +0 -0
  38. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/services/epii/constants/update_thies_data_constants.py +0 -0
  39. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/services/epii/controllers/__init__.py +0 -0
  40. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/services/epii/controllers/types/__init__.py +0 -0
  41. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/services/epii/controllers/types/update_thies_data_types.py +0 -0
  42. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/services/epii/use_cases/types/__init__.py +0 -0
  43. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/services/epii/use_cases/types/update_thies_data_types.py +0 -0
  44. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/services/epii/use_cases/update_thies_data.py +0 -0
  45. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/services/epii/utils/__init__.py +0 -0
  46. {rcer_iot_client_pkg-0.5.0 → rcer_iot_client_pkg-0.5.2}/src/rcer_iot_client_pkg/services/epii/utils/update_thies_data_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: rcer_iot_client_pkg
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: A client library for IoT projects in the RCER initiative
5
5
  License: MIT
6
6
  Author: pedropablozavalat
@@ -45,23 +45,29 @@ api_client = EpiiAPI()
45
45
  The library provides a method to synchronize THIES Data Logger files with the RCER SharePoint client. This method updates the folder containing binary files with meteorological data:
46
46
 
47
47
  ```python
48
+ from rcer_iot_client_pkg import EpiiAPIConfig
48
49
  import asyncio
49
50
 
50
51
  async def update_thies_data():
51
- response = await api_client.update_thies_data(
52
- ftp_port=PORT,
53
- ftp_host=LOCAL_HOST,
54
- ftp_password=PASSWORD,
55
- ftp_user=USER
52
+ config = EpiiAPIConfig(
53
+ ftp_port=FTP_PORT,
54
+ ftp_host=FTP_HOST,
55
+ ftp_user=FTP_USER,
56
+ ftp_password=FTP_PASSWORD,
57
+ sharepoint_client_id=SHAREPOINT_CLIENT_ID,
58
+ sharepoint_client_secret=SHAREPOINT_CLIENT_SECRET,
59
+ sharepoint_tenant_id=SHAREPOINT_TENANT_ID,
60
+ sharepoint_tenant_name=SHAREPOINT_TENANT_NAME,
61
+ sharepoint_site_name=SHAREPOINT_SITE_NAME
56
62
  )
63
+ response = await api_client.update_thies_data(config)
57
64
  return response
58
65
 
59
66
  asyncio.run(update_thies_data())
60
67
  ```
61
68
 
62
69
  **Notes:**
63
- - Store sensitive data like `PASSWORD` and `USER` securely, e.g., in environment variables or a secrets file.
64
- - Ensure `asyncio` is installed to run concurrent code with `EpiiAPI` methods.
70
+ - Store sensitive data like `FTP_PASSWORD`, `FTP_USER`, and SharePoint credentials securely. Use environment variables or a secrets management tool to avoid hardcoding sensitive information in your codebase.
65
71
 
66
72
  ## Development
67
73
 
@@ -24,23 +24,29 @@ api_client = EpiiAPI()
24
24
  The library provides a method to synchronize THIES Data Logger files with the RCER SharePoint client. This method updates the folder containing binary files with meteorological data:
25
25
 
26
26
  ```python
27
+ from rcer_iot_client_pkg import EpiiAPIConfig
27
28
  import asyncio
28
29
 
29
30
  async def update_thies_data():
30
- response = await api_client.update_thies_data(
31
- ftp_port=PORT,
32
- ftp_host=LOCAL_HOST,
33
- ftp_password=PASSWORD,
34
- ftp_user=USER
31
+ config = EpiiAPIConfig(
32
+ ftp_port=FTP_PORT,
33
+ ftp_host=FTP_HOST,
34
+ ftp_user=FTP_USER,
35
+ ftp_password=FTP_PASSWORD,
36
+ sharepoint_client_id=SHAREPOINT_CLIENT_ID,
37
+ sharepoint_client_secret=SHAREPOINT_CLIENT_SECRET,
38
+ sharepoint_tenant_id=SHAREPOINT_TENANT_ID,
39
+ sharepoint_tenant_name=SHAREPOINT_TENANT_NAME,
40
+ sharepoint_site_name=SHAREPOINT_SITE_NAME
35
41
  )
42
+ response = await api_client.update_thies_data(config)
36
43
  return response
37
44
 
38
45
  asyncio.run(update_thies_data())
39
46
  ```
40
47
 
41
48
  **Notes:**
42
- - Store sensitive data like `PASSWORD` and `USER` securely, e.g., in environment variables or a secrets file.
43
- - Ensure `asyncio` is installed to run concurrent code with `EpiiAPI` methods.
49
+ - Store sensitive data like `FTP_PASSWORD`, `FTP_USER`, and SharePoint credentials securely. Use environment variables or a secrets management tool to avoid hardcoding sensitive information in your codebase.
44
50
 
45
51
  ## Development
46
52
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "rcer_iot_client_pkg"
3
- version = "0.5.0"
3
+ version = "0.5.2"
4
4
  description = "A client library for IoT projects in the RCER initiative"
5
5
  authors = ["pedropablozavalat"]
6
6
  license = "MIT"
@@ -4,5 +4,6 @@ from importlib.metadata import version
4
4
  __version__ = version("rcer_iot_client_pkg")
5
5
 
6
6
  from .services.epii.api import EpiiAPI
7
+ from .general_types.api.update_thies_data_types import EpiiAPIConfig
7
8
 
8
- __all__ = ["EpiiAPI"]
9
+ __all__ = ["EpiiAPI", "EpiiAPIConfig"]
@@ -0,0 +1,3 @@
1
+ from .update_thies_data_types import EpiiAPIConfig
2
+
3
+ __all__ = ["EpiiAPIConfig"]
@@ -1,3 +1,6 @@
1
+ import json
2
+
3
+
1
4
  class ThiesConnectionError(Exception):
2
5
  """Raised when unable to connect to the THIES FTP Server"""
3
6
 
@@ -26,5 +29,15 @@ class ThiesFetchingError(Exception):
26
29
  class SharePointFetchingError(Exception):
27
30
  """Raised when there is an error fetching file names from the RCER cloud."""
28
31
 
32
+ def __init__(self, *args, reason):
33
+ super().__init__(*args, reason)
34
+ self.reason = reason
35
+
29
36
  def __str__(self):
30
- return "An error occurred while retrieving file names from the RCER cloud"
37
+ try:
38
+ _, internal_metadata = self.reason.__str__().split(",", 1)
39
+ internal_metadata_dict = json.loads(internal_metadata)
40
+ return internal_metadata_dict["error_description"]
41
+
42
+ except json.decoder.JSONDecodeError:
43
+ return self.reason.__str__()
@@ -65,17 +65,22 @@ class SharepointRestAPI(SharepointClientContract):
65
65
  }
66
66
 
67
67
  async def __aenter__(self) -> "SharepointRestAPI":
68
- self.credentials = await self._load_credentials()
69
- site_url = f"https://{self.tenant_name}.sharepoint.com"
68
+ try:
69
+ self.credentials = await self._load_credentials()
70
+ site_url = f"https://{self.tenant_name}.sharepoint.com"
70
71
 
71
- self.base_headers = {
72
- "Authorization": f"Bearer {self.credentials['access_token']}",
73
- "Accept": "application/json",
74
- "Content-Type": "application/json",
75
- }
76
- self.base_url = f"{site_url}/sites/{self.site_name}/_api/"
77
- self.session = ClientSession(headers=self.base_headers, base_url=self.base_url)
78
- return self
72
+ self.base_headers = {
73
+ "Authorization": f"Bearer {self.credentials['access_token']}",
74
+ "Accept": "application/json",
75
+ "Content-Type": "application/json",
76
+ }
77
+ self.base_url = f"{site_url}/sites/{self.site_name}/_api/"
78
+ self.session = ClientSession(
79
+ headers=self.base_headers, base_url=self.base_url
80
+ )
81
+ return self
82
+ except ClientError as error:
83
+ raise ConnectionError(error)
79
84
 
80
85
  async def __aexit__(
81
86
  self, _exc_type: type[BaseException], _exc_val: BaseException, _exc_tb: Any
@@ -73,14 +73,14 @@ class UpdateThiesDataController:
73
73
  except SharepointClientError as error:
74
74
  return UpdateThiesDataControllerOutput(
75
75
  message="Sharepoint Client initialization fails.",
76
- status=HTTPStatus.BAD_REQUEST.value,
76
+ status=HTTPStatus.INTERNAL_SERVER_ERROR.value,
77
77
  metadata={"error": error.__str__()},
78
78
  )
79
79
 
80
80
  except SharePointFetchingError as error:
81
81
  return UpdateThiesDataControllerOutput(
82
- message="An error occurred while retrieving file names from the RCER cloud",
83
- status=HTTPStatus.INTERNAL_SERVER_ERROR.value,
82
+ message="An error occurred while retrieving file names from Microsoft SharePoint",
83
+ status=HTTPStatus.BAD_REQUEST.value,
84
84
  metadata={"error": error.__str__()},
85
85
  )
86
86
 
@@ -1,10 +0,0 @@
1
- """Export defined type classes."""
2
-
3
- from .async_http_client import AsyncHTTPClient
4
- from .types.async_http_client_types import (
5
- AsyncHttpClientInitArgs,
6
- GetArgs,
7
- UploadFileArgs,
8
- )
9
-
10
- __all__ = ["AsyncHTTPClient", "AsyncHttpClientInitArgs", "GetArgs", "UploadFileArgs"]
@@ -1,34 +0,0 @@
1
- from typing import Any
2
-
3
- from .async_http_client_contract import AsyncHTTPClientContract
4
- from .clients.aiohttp_client import AioHttpClient
5
- from .types.async_http_client_types import (
6
- AsyncHttpClientInitArgs,
7
- GetArgs,
8
- UploadFileArgs,
9
- )
10
-
11
-
12
- class AsyncHTTPClient(AsyncHTTPClientContract):
13
- CLIENTS = {"aiohttp_client"}
14
-
15
- def __init__(self, args: AsyncHttpClientInitArgs) -> None:
16
- if args.client_name not in AsyncHTTPClient.CLIENTS:
17
- msg = f"Unsupported client '{args.client_name}'"
18
- raise KeyError(msg)
19
- self.client_name = args.client_name
20
-
21
- if args.client_name == "aiohttp_client":
22
- self.client_obj = AioHttpClient(args)
23
-
24
- async def __aenter__(self):
25
- return await self.client_obj.__aenter__()
26
-
27
- async def __aexit__(self, exc_type, exc_val, exc_tb):
28
- await self.client_obj.__aexit__(exc_type, exc_val, exc_tb)
29
-
30
- async def get(self, args: GetArgs) -> dict[str, Any]:
31
- return await self.client_obj.get(args)
32
-
33
- async def upload_file(self, args: UploadFileArgs) -> dict[str, Any]:
34
- return await self.client_obj.upload_file(args)
@@ -1,29 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from typing import Any
3
-
4
- from .types.async_http_client_types import GetArgs, UploadFileArgs
5
-
6
-
7
- class AsyncHTTPClientContract(ABC):
8
- """
9
- A contract for asynchronous HTTP client implementations.
10
-
11
- This abstract base class defines the required methods for performing
12
- HTTP GET requests and uploading files asynchronously.
13
-
14
- Methods.
15
- -------
16
- get(args: GetArgs) -> dict[str, Any]
17
- Perform an HTTP GET request with the specified arguments.
18
-
19
- upload_file(args: UploadFileArgs) -> dict[str, Any]
20
- Upload a file using the specified arguments.
21
- """
22
-
23
- @abstractmethod
24
- async def get(self, args: GetArgs) -> dict[str, Any]:
25
- pass
26
-
27
- @abstractmethod
28
- async def upload_file(self, args: UploadFileArgs) -> dict[str, Any]:
29
- pass
@@ -1,50 +0,0 @@
1
- from typing import Any
2
-
3
- from aiohttp import ClientError, ClientSession
4
-
5
- from rcer_iot_client_pkg.libs.async_http_client.async_http_client_contract import (
6
- AsyncHTTPClientContract,
7
- )
8
- from rcer_iot_client_pkg.libs.async_http_client.types.async_http_client_types import (
9
- AsyncHttpClientInitArgs,
10
- GetArgs,
11
- UploadFileArgs,
12
- )
13
-
14
-
15
- class AioHttpClient(AsyncHTTPClientContract):
16
- def __init__(self, args: AsyncHttpClientInitArgs) -> None:
17
- self.access_token = args.access_token
18
- self.base_url = args.base_url
19
- self.headers = self._build_headers()
20
- self.session: ClientSession | None = None
21
-
22
- def _build_headers(self) -> dict:
23
- return {"Authorization": f"Bearer {self.access_token}"}
24
-
25
- async def __aenter__(self) -> "AioHttpClient":
26
- self.session = ClientSession(headers=self.headers, base_url=self.base_url)
27
- return self
28
-
29
- async def __aexit__(
30
- self, _exc_type: type[BaseException], _exc_val: BaseException, _exc_tb: Any
31
- ) -> None:
32
- await self.session.close()
33
-
34
- async def get(self, args: GetArgs) -> dict[str, Any]:
35
- try:
36
- endpoint, params = args.endpoint.lstrip("/"), args.params
37
- response = await self.session.get(endpoint, params=params)
38
- response.raise_for_status()
39
- return await response.json()
40
- except ClientError as error:
41
- raise ConnectionError(error) from error
42
-
43
- async def upload_file(self, args: UploadFileArgs) -> dict[str, Any]:
44
- try:
45
- endpoint, file_bytes = args.endpoint.lstrip("/"), args.file_bytes
46
- response = await self.session.put(endpoint, data=file_bytes)
47
- response.raise_for_status()
48
- return await response.json()
49
- except ClientError as error:
50
- raise ConnectionError(error) from error
@@ -1,3 +0,0 @@
1
- from .async_http_client_types import AsyncHttpClientInitArgs, GetArgs, UploadFileArgs
2
-
3
- __all__ = ["AsyncHttpClientInitArgs", "GetArgs", "UploadFileArgs"]
@@ -1,17 +0,0 @@
1
- from pydantic import BaseModel, Field
2
-
3
-
4
- class AsyncHttpClientInitArgs(BaseModel):
5
- access_token: str
6
- base_url: str
7
- client_name: str = "aiohttp_client"
8
-
9
-
10
- class GetArgs(BaseModel):
11
- endpoint: str
12
- params: dict | None = Field(default=None)
13
-
14
-
15
- class UploadFileArgs(BaseModel):
16
- endpoint: str
17
- file_bytes: bytes