celitech-sdk 1.0.0__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.
Files changed (53) hide show
  1. celitech/__init__.py +2 -0
  2. celitech/hooks/__init__.py +0 -0
  3. celitech/hooks/hook.py +95 -0
  4. celitech/models/__init__.py +14 -0
  5. celitech/models/base.py +251 -0
  6. celitech/models/create_purchase_ok_response.py +85 -0
  7. celitech/models/create_purchase_request.py +54 -0
  8. celitech/models/edit_purchase_ok_response.py +41 -0
  9. celitech/models/edit_purchase_request.py +41 -0
  10. celitech/models/get_esim_device_ok_response.py +41 -0
  11. celitech/models/get_esim_history_ok_response.py +50 -0
  12. celitech/models/get_esim_mac_ok_response.py +39 -0
  13. celitech/models/get_esim_ok_response.py +43 -0
  14. celitech/models/get_purchase_consumption_ok_response.py +17 -0
  15. celitech/models/list_destinations_ok_response.py +38 -0
  16. celitech/models/list_packages_ok_response.py +61 -0
  17. celitech/models/list_purchases_ok_response.py +129 -0
  18. celitech/models/top_up_esim_ok_response.py +82 -0
  19. celitech/models/top_up_esim_request.py +49 -0
  20. celitech/models/utils/cast_models.py +81 -0
  21. celitech/models/utils/json_map.py +80 -0
  22. celitech/net/__init__.py +0 -0
  23. celitech/net/environment/__init__.py +1 -0
  24. celitech/net/environment/environment.py +11 -0
  25. celitech/net/headers/__init__.py +0 -0
  26. celitech/net/headers/base_header.py +9 -0
  27. celitech/net/request_chain/__init__.py +0 -0
  28. celitech/net/request_chain/handlers/__init__.py +0 -0
  29. celitech/net/request_chain/handlers/base_handler.py +39 -0
  30. celitech/net/request_chain/handlers/hook_handler.py +47 -0
  31. celitech/net/request_chain/handlers/http_handler.py +80 -0
  32. celitech/net/request_chain/handlers/retry_handler.py +65 -0
  33. celitech/net/request_chain/request_chain.py +57 -0
  34. celitech/net/transport/__init__.py +0 -0
  35. celitech/net/transport/request.py +89 -0
  36. celitech/net/transport/request_error.py +53 -0
  37. celitech/net/transport/response.py +57 -0
  38. celitech/net/transport/serializer.py +249 -0
  39. celitech/net/transport/utils.py +28 -0
  40. celitech/sdk.py +30 -0
  41. celitech/services/__init__.py +0 -0
  42. celitech/services/destinations.py +29 -0
  43. celitech/services/e_sim.py +121 -0
  44. celitech/services/packages.py +72 -0
  45. celitech/services/purchases.py +189 -0
  46. celitech/services/utils/base_service.py +63 -0
  47. celitech/services/utils/default_headers.py +57 -0
  48. celitech/services/utils/validator.py +170 -0
  49. celitech_sdk-1.0.0.dist-info/LICENSE +21 -0
  50. celitech_sdk-1.0.0.dist-info/METADATA +482 -0
  51. celitech_sdk-1.0.0.dist-info/RECORD +53 -0
  52. celitech_sdk-1.0.0.dist-info/WHEEL +5 -0
  53. celitech_sdk-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,39 @@
1
+ from .utils.json_map import JsonMap
2
+ from .base import BaseModel
3
+
4
+
5
+ @JsonMap(
6
+ {"smdp_address": "smdpAddress", "manual_activation_code": "manualActivationCode"}
7
+ )
8
+ class GetEsimMacOkResponseEsim(BaseModel):
9
+ """GetEsimMacOkResponseEsim
10
+
11
+ :param iccid: ID of the eSIM, defaults to None
12
+ :type iccid: str, optional
13
+ :param smdp_address: SM-DP+ Address, defaults to None
14
+ :type smdp_address: str, optional
15
+ :param manual_activation_code: The manual activation code, defaults to None
16
+ :type manual_activation_code: str, optional
17
+ """
18
+
19
+ def __init__(
20
+ self,
21
+ iccid: str = None,
22
+ smdp_address: str = None,
23
+ manual_activation_code: str = None,
24
+ ):
25
+ self.iccid = iccid
26
+ self.smdp_address = smdp_address
27
+ self.manual_activation_code = manual_activation_code
28
+
29
+
30
+ @JsonMap({})
31
+ class GetEsimMacOkResponse(BaseModel):
32
+ """GetEsimMacOkResponse
33
+
34
+ :param esim: esim, defaults to None
35
+ :type esim: GetEsimMacOkResponseEsim, optional
36
+ """
37
+
38
+ def __init__(self, esim: GetEsimMacOkResponseEsim = None):
39
+ self.esim = self._define_object(esim, GetEsimMacOkResponseEsim)
@@ -0,0 +1,43 @@
1
+ from .utils.json_map import JsonMap
2
+ from .base import BaseModel
3
+
4
+
5
+ @JsonMap(
6
+ {"smdp_address": "smdpAddress", "manual_activation_code": "manualActivationCode"}
7
+ )
8
+ class GetEsimOkResponseEsim(BaseModel):
9
+ """GetEsimOkResponseEsim
10
+
11
+ :param iccid: ID of the eSIM, defaults to None
12
+ :type iccid: str, optional
13
+ :param smdp_address: SM-DP+ Address, defaults to None
14
+ :type smdp_address: str, optional
15
+ :param manual_activation_code: The manual activation code, defaults to None
16
+ :type manual_activation_code: str, optional
17
+ :param status: Status of the eSIM, possible values are 'RELEASED', 'DOWNLOADED', 'INSTALLED', 'ENABLED', 'DELETED', or 'ERROR', defaults to None
18
+ :type status: str, optional
19
+ """
20
+
21
+ def __init__(
22
+ self,
23
+ iccid: str = None,
24
+ smdp_address: str = None,
25
+ manual_activation_code: str = None,
26
+ status: str = None,
27
+ ):
28
+ self.iccid = iccid
29
+ self.smdp_address = smdp_address
30
+ self.manual_activation_code = manual_activation_code
31
+ self.status = status
32
+
33
+
34
+ @JsonMap({})
35
+ class GetEsimOkResponse(BaseModel):
36
+ """GetEsimOkResponse
37
+
38
+ :param esim: esim, defaults to None
39
+ :type esim: GetEsimOkResponseEsim, optional
40
+ """
41
+
42
+ def __init__(self, esim: GetEsimOkResponseEsim = None):
43
+ self.esim = self._define_object(esim, GetEsimOkResponseEsim)
@@ -0,0 +1,17 @@
1
+ from .utils.json_map import JsonMap
2
+ from .base import BaseModel
3
+
4
+
5
+ @JsonMap({"data_usage_remaining_in_bytes": "dataUsageRemainingInBytes"})
6
+ class GetPurchaseConsumptionOkResponse(BaseModel):
7
+ """GetPurchaseConsumptionOkResponse
8
+
9
+ :param data_usage_remaining_in_bytes: Remaining balance of the package in bytes, defaults to None
10
+ :type data_usage_remaining_in_bytes: float, optional
11
+ :param status: Status of the connectivity, possible values are 'ACTIVE' or 'NOT_ACTIVE', defaults to None
12
+ :type status: str, optional
13
+ """
14
+
15
+ def __init__(self, data_usage_remaining_in_bytes: float = None, status: str = None):
16
+ self.data_usage_remaining_in_bytes = data_usage_remaining_in_bytes
17
+ self.status = status
@@ -0,0 +1,38 @@
1
+ from typing import List
2
+ from .utils.json_map import JsonMap
3
+ from .base import BaseModel
4
+
5
+
6
+ @JsonMap({"supported_countries": "supportedCountries"})
7
+ class Destinations(BaseModel):
8
+ """Destinations
9
+
10
+ :param name: Name of the destination, defaults to None
11
+ :type name: str, optional
12
+ :param destination: ISO representation of the destination, defaults to None
13
+ :type destination: str, optional
14
+ :param supported_countries: supported_countries, defaults to None
15
+ :type supported_countries: List[str], optional
16
+ """
17
+
18
+ def __init__(
19
+ self,
20
+ name: str = None,
21
+ destination: str = None,
22
+ supported_countries: List[str] = None,
23
+ ):
24
+ self.name = name
25
+ self.destination = destination
26
+ self.supported_countries = supported_countries
27
+
28
+
29
+ @JsonMap({})
30
+ class ListDestinationsOkResponse(BaseModel):
31
+ """ListDestinationsOkResponse
32
+
33
+ :param destinations: destinations, defaults to None
34
+ :type destinations: List[Destinations], optional
35
+ """
36
+
37
+ def __init__(self, destinations: List[Destinations] = None):
38
+ self.destinations = self._define_list(destinations, Destinations)
@@ -0,0 +1,61 @@
1
+ from typing import List
2
+ from .utils.json_map import JsonMap
3
+ from .base import BaseModel
4
+
5
+
6
+ @JsonMap(
7
+ {
8
+ "id_": "id",
9
+ "data_limit_in_bytes": "dataLimitInBytes",
10
+ "min_days": "minDays",
11
+ "max_days": "maxDays",
12
+ "price_in_cents": "priceInCents",
13
+ }
14
+ )
15
+ class Packages(BaseModel):
16
+ """Packages
17
+
18
+ :param id_: ID of the package, defaults to None
19
+ :type id_: str, optional
20
+ :param destination: ISO representation of the package's destination, defaults to None
21
+ :type destination: str, optional
22
+ :param data_limit_in_bytes: Size of the package in Bytes, defaults to None
23
+ :type data_limit_in_bytes: float, optional
24
+ :param min_days: Min number of days for the package, defaults to None
25
+ :type min_days: float, optional
26
+ :param max_days: Max number of days for the package, defaults to None
27
+ :type max_days: float, optional
28
+ :param price_in_cents: Price of the package in cents, defaults to None
29
+ :type price_in_cents: float, optional
30
+ """
31
+
32
+ def __init__(
33
+ self,
34
+ id_: str = None,
35
+ destination: str = None,
36
+ data_limit_in_bytes: float = None,
37
+ min_days: float = None,
38
+ max_days: float = None,
39
+ price_in_cents: float = None,
40
+ ):
41
+ self.id_ = id_
42
+ self.destination = destination
43
+ self.data_limit_in_bytes = data_limit_in_bytes
44
+ self.min_days = min_days
45
+ self.max_days = max_days
46
+ self.price_in_cents = price_in_cents
47
+
48
+
49
+ @JsonMap({"after_cursor": "afterCursor"})
50
+ class ListPackagesOkResponse(BaseModel):
51
+ """ListPackagesOkResponse
52
+
53
+ :param packages: packages, defaults to None
54
+ :type packages: List[Packages], optional
55
+ :param after_cursor: The cursor value representing the end of the current page of results. Use this cursor value as the "afterCursor" parameter in your next request to retrieve the subsequent page of results. It ensures that you continue fetching data from where you left off, facilitating smooth pagination, defaults to None
56
+ :type after_cursor: str, optional
57
+ """
58
+
59
+ def __init__(self, packages: List[Packages] = None, after_cursor: str = None):
60
+ self.packages = self._define_list(packages, Packages)
61
+ self.after_cursor = after_cursor
@@ -0,0 +1,129 @@
1
+ from typing import List
2
+ from .utils.json_map import JsonMap
3
+ from .base import BaseModel
4
+
5
+
6
+ @JsonMap(
7
+ {
8
+ "id_": "id",
9
+ "data_limit_in_bytes": "dataLimitInBytes",
10
+ "destination_name": "destinationName",
11
+ "price_in_cents": "priceInCents",
12
+ }
13
+ )
14
+ class Package(BaseModel):
15
+ """Package
16
+
17
+ :param id_: ID of the package, defaults to None
18
+ :type id_: str, optional
19
+ :param data_limit_in_bytes: Size of the package in Bytes, defaults to None
20
+ :type data_limit_in_bytes: float, optional
21
+ :param destination: ISO representation of the package's destination, defaults to None
22
+ :type destination: str, optional
23
+ :param destination_name: Name of the package's destination, defaults to None
24
+ :type destination_name: str, optional
25
+ :param price_in_cents: Price of the package in cents, defaults to None
26
+ :type price_in_cents: float, optional
27
+ """
28
+
29
+ def __init__(
30
+ self,
31
+ id_: str = None,
32
+ data_limit_in_bytes: float = None,
33
+ destination: str = None,
34
+ destination_name: str = None,
35
+ price_in_cents: float = None,
36
+ ):
37
+ self.id_ = id_
38
+ self.data_limit_in_bytes = data_limit_in_bytes
39
+ self.destination = destination
40
+ self.destination_name = destination_name
41
+ self.price_in_cents = price_in_cents
42
+
43
+
44
+ @JsonMap({})
45
+ class PurchasesEsim(BaseModel):
46
+ """PurchasesEsim
47
+
48
+ :param iccid: ID of the eSIM, defaults to None
49
+ :type iccid: str, optional
50
+ """
51
+
52
+ def __init__(self, iccid: str = None):
53
+ self.iccid = iccid
54
+
55
+
56
+ @JsonMap(
57
+ {
58
+ "id_": "id",
59
+ "start_date": "startDate",
60
+ "end_date": "endDate",
61
+ "created_date": "createdDate",
62
+ "start_time": "startTime",
63
+ "end_time": "endTime",
64
+ "created_at": "createdAt",
65
+ }
66
+ )
67
+ class Purchases(BaseModel):
68
+ """Purchases
69
+
70
+ :param id_: ID of the purchase, defaults to None
71
+ :type id_: str, optional
72
+ :param start_date: Start date of the package's validity in the format 'yyyy-MM-ddThh:mm:ssZZ', defaults to None
73
+ :type start_date: str, optional
74
+ :param end_date: End date of the package's validity in the format 'yyyy-MM-ddThh:mm:ssZZ', defaults to None
75
+ :type end_date: str, optional
76
+ :param created_date: Creation date of the purchase in the format 'yyyy-MM-ddThh:mm:ssZZ', defaults to None
77
+ :type created_date: str, optional
78
+ :param start_time: Epoch value representing the start time of the package's validity, defaults to None
79
+ :type start_time: float, optional
80
+ :param end_time: Epoch value representing the end time of the package's validity, defaults to None
81
+ :type end_time: float, optional
82
+ :param created_at: Epoch value representing the date of creation of the purchase, defaults to None
83
+ :type created_at: float, optional
84
+ :param package: package, defaults to None
85
+ :type package: Package, optional
86
+ :param esim: esim, defaults to None
87
+ :type esim: PurchasesEsim, optional
88
+ :param source: The source indicates where the eSIM was purchased, which can be from the API, dashboard, or landing-page. For purchases made before September 8, 2023, the value will be displayed as 'Not available'., defaults to None
89
+ :type source: str, optional
90
+ """
91
+
92
+ def __init__(
93
+ self,
94
+ id_: str = None,
95
+ start_date: str = None,
96
+ end_date: str = None,
97
+ created_date: str = None,
98
+ start_time: float = None,
99
+ end_time: float = None,
100
+ created_at: float = None,
101
+ package: Package = None,
102
+ esim: PurchasesEsim = None,
103
+ source: str = None,
104
+ ):
105
+ self.id_ = id_
106
+ self.start_date = start_date
107
+ self.end_date = end_date
108
+ self.created_date = created_date
109
+ self.start_time = start_time
110
+ self.end_time = end_time
111
+ self.created_at = created_at
112
+ self.package = self._define_object(package, Package)
113
+ self.esim = self._define_object(esim, PurchasesEsim)
114
+ self.source = source
115
+
116
+
117
+ @JsonMap({"after_cursor": "afterCursor"})
118
+ class ListPurchasesOkResponse(BaseModel):
119
+ """ListPurchasesOkResponse
120
+
121
+ :param purchases: purchases, defaults to None
122
+ :type purchases: List[Purchases], optional
123
+ :param after_cursor: The cursor value representing the end of the current page of results. Use this cursor value as the "afterCursor" parameter in your next request to retrieve the subsequent page of results. It ensures that you continue fetching data from where you left off, facilitating smooth pagination., defaults to None
124
+ :type after_cursor: str, optional
125
+ """
126
+
127
+ def __init__(self, purchases: List[Purchases] = None, after_cursor: str = None):
128
+ self.purchases = self._define_list(purchases, Purchases)
129
+ self.after_cursor = after_cursor
@@ -0,0 +1,82 @@
1
+ from .utils.json_map import JsonMap
2
+ from .base import BaseModel
3
+
4
+
5
+ @JsonMap(
6
+ {
7
+ "id_": "id",
8
+ "package_id": "packageId",
9
+ "start_date": "startDate",
10
+ "end_date": "endDate",
11
+ "created_date": "createdDate",
12
+ "start_time": "startTime",
13
+ "end_time": "endTime",
14
+ }
15
+ )
16
+ class TopUpEsimOkResponsePurchase(BaseModel):
17
+ """TopUpEsimOkResponsePurchase
18
+
19
+ :param id_: ID of the purchase, defaults to None
20
+ :type id_: str, optional
21
+ :param package_id: ID of the package, defaults to None
22
+ :type package_id: str, optional
23
+ :param start_date: Start date of the package's validity in the format 'yyyy-MM-ddThh:mm:ssZZ', defaults to None
24
+ :type start_date: str, optional
25
+ :param end_date: End date of the package's validity in the format 'yyyy-MM-ddThh:mm:ssZZ', defaults to None
26
+ :type end_date: str, optional
27
+ :param created_date: Creation date of the purchase in the format 'yyyy-MM-ddThh:mm:ssZZ', defaults to None
28
+ :type created_date: str, optional
29
+ :param start_time: Epoch value representing the start time of the package's validity, defaults to None
30
+ :type start_time: float, optional
31
+ :param end_time: Epoch value representing the end time of the package's validity, defaults to None
32
+ :type end_time: float, optional
33
+ """
34
+
35
+ def __init__(
36
+ self,
37
+ id_: str = None,
38
+ package_id: str = None,
39
+ start_date: str = None,
40
+ end_date: str = None,
41
+ created_date: str = None,
42
+ start_time: float = None,
43
+ end_time: float = None,
44
+ ):
45
+ self.id_ = id_
46
+ self.package_id = package_id
47
+ self.start_date = start_date
48
+ self.end_date = end_date
49
+ self.created_date = created_date
50
+ self.start_time = start_time
51
+ self.end_time = end_time
52
+
53
+
54
+ @JsonMap({})
55
+ class TopUpEsimOkResponseProfile(BaseModel):
56
+ """TopUpEsimOkResponseProfile
57
+
58
+ :param iccid: ID of the eSIM, defaults to None
59
+ :type iccid: str, optional
60
+ """
61
+
62
+ def __init__(self, iccid: str = None):
63
+ self.iccid = iccid
64
+
65
+
66
+ @JsonMap({})
67
+ class TopUpEsimOkResponse(BaseModel):
68
+ """TopUpEsimOkResponse
69
+
70
+ :param purchase: purchase, defaults to None
71
+ :type purchase: TopUpEsimOkResponsePurchase, optional
72
+ :param profile: profile, defaults to None
73
+ :type profile: TopUpEsimOkResponseProfile, optional
74
+ """
75
+
76
+ def __init__(
77
+ self,
78
+ purchase: TopUpEsimOkResponsePurchase = None,
79
+ profile: TopUpEsimOkResponseProfile = None,
80
+ ):
81
+ self.purchase = self._define_object(purchase, TopUpEsimOkResponsePurchase)
82
+ self.profile = self._define_object(profile, TopUpEsimOkResponseProfile)
@@ -0,0 +1,49 @@
1
+ from .utils.json_map import JsonMap
2
+ from .base import BaseModel
3
+
4
+
5
+ @JsonMap(
6
+ {
7
+ "data_limit_in_gb": "dataLimitInGB",
8
+ "start_date": "startDate",
9
+ "end_date": "endDate",
10
+ "start_time": "startTime",
11
+ "end_time": "endTime",
12
+ }
13
+ )
14
+ class TopUpEsimRequest(BaseModel):
15
+ """TopUpEsimRequest
16
+
17
+ :param iccid: ID of the eSIM
18
+ :type iccid: str
19
+ :param data_limit_in_gb: Size of the package in GB. The available options are 1, 2, 3, 5, 8, 20GB
20
+ :type data_limit_in_gb: float
21
+ :param start_date: Start date of the package's validity in the format 'yyyy-MM-dd'. This date can be set to the current day or any day within the next 12 months.
22
+ :type start_date: str
23
+ :param end_date: End date of the package's validity in the format 'yyyy-MM-dd'. End date can be maximum 60 days after Start date.
24
+ :type end_date: str
25
+ :param email: Email address where the purchase confirmation email will be sent (excluding QR Code & activation steps), defaults to None
26
+ :type email: str, optional
27
+ :param start_time: Epoch value representing the start time of the package's validity. This timestamp can be set to the current time or any time within the next 12 months., defaults to None
28
+ :type start_time: float, optional
29
+ :param end_time: Epoch value representing the end time of the package's validity. End time can be maximum 60 days after Start time., defaults to None
30
+ :type end_time: float, optional
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ iccid: str,
36
+ data_limit_in_gb: float,
37
+ start_date: str,
38
+ end_date: str,
39
+ email: str = None,
40
+ start_time: float = None,
41
+ end_time: float = None,
42
+ ):
43
+ self.iccid = iccid
44
+ self.data_limit_in_gb = data_limit_in_gb
45
+ self.start_date = start_date
46
+ self.end_date = end_date
47
+ self.email = email
48
+ self.start_time = start_time
49
+ self.end_time = end_time
@@ -0,0 +1,81 @@
1
+ from enum import Enum
2
+ from typing import get_origin, get_args, Union
3
+ from inspect import isclass
4
+ from ..base import OneOfBaseModel
5
+
6
+
7
+ def cast_models(func):
8
+ """
9
+ A decorator that allows for the conversion of dictionaries and enum values to model instances.
10
+
11
+ :param func: The function to decorate.
12
+ :type func: Callable
13
+ :return: The decorated function.
14
+ :rtype: Callable
15
+ """
16
+
17
+ def wrapper(self, *clss, **kwargs):
18
+ cls_types = func.__annotations__
19
+ new_cls_args = []
20
+ new_kwargs = {}
21
+
22
+ for input, input_type in zip(clss, cls_types.values()):
23
+ new_cls_args.append(_get_instanced_type(input, input_type))
24
+
25
+ for type_name, input in kwargs.items():
26
+ new_kwargs[type_name] = _get_instanced_type(input, cls_types[type_name])
27
+
28
+ return func(self, *new_cls_args, **new_kwargs)
29
+
30
+ def _get_instanced_type(data, input_type):
31
+ """
32
+ Get instanced type based on the input data and type.
33
+
34
+ :param data: The input data.
35
+ :param input_type: The type of the input.
36
+ :return: The instanced type.
37
+ """
38
+ # Instanciate oneOf models
39
+ if _is_one_of_model(input_type):
40
+ class_list = {
41
+ arg.__name__: arg for arg in get_args(input_type) if arg.__name__
42
+ }
43
+ OneOfBaseModel.class_list = class_list
44
+ return OneOfBaseModel.return_one_of(data)
45
+
46
+ # Instanciate enum values
47
+ elif (
48
+ isclass(input_type)
49
+ and issubclass(input_type, Enum)
50
+ and not isinstance(data, input_type)
51
+ ):
52
+ return input_type(data)
53
+
54
+ # Instanciate object models
55
+ elif isinstance(data, dict) and input_type is not str:
56
+ return input_type(**data)
57
+
58
+ # Instanciate list of object models
59
+ elif isinstance(data, list) and all(isinstance(i, dict) for i in data):
60
+ element_type = get_args(input_type)[0]
61
+ return [element_type(**item) for item in data]
62
+
63
+ # Instanciate bytes if input is str
64
+ elif input_type is bytes and isinstance(data, str):
65
+ return data.encode()
66
+
67
+ # Pass other types
68
+ else:
69
+ return data
70
+
71
+ def _is_one_of_model(cls_type):
72
+ """
73
+ Check if the class type is a oneOf model.
74
+
75
+ :param cls_type: The class type to check.
76
+ :return: True if the class type is a oneOf model, False otherwise.
77
+ :rtype: bool
78
+ """
79
+ return hasattr(cls_type, "__origin__") and cls_type.__origin__ is Union
80
+
81
+ return wrapper
@@ -0,0 +1,80 @@
1
+ from enum import Enum
2
+
3
+
4
+ class JsonMap:
5
+ """
6
+ A class decorator used to map adjusted attribute names to original JSON attribute names before a request,
7
+ and vice versa after the request.
8
+
9
+ Example:
10
+ @JsonMapping({
11
+ 'adjusted_name': 'original_name',
12
+ 'adjusted_list': 'original_list'
13
+ })
14
+ class SomeClass(BaseModel):
15
+ adjusted_name: str
16
+ adjusted_list: List[OtherClass]
17
+
18
+ :param mapping: A dictionary specifying the mapping between adjusted attribute names and original JSON attribute names.
19
+ :type mapping: dict
20
+ """
21
+
22
+ def __init__(self, mapping):
23
+ self.mapping = mapping
24
+
25
+ def __call__(self, cls):
26
+ """
27
+ Transform the decorated class with attribute mapping capabilities.
28
+
29
+ :param cls: The class to be decorated.
30
+ :type cls: type
31
+ :return: The decorated class.
32
+ :rtype: type
33
+ """
34
+ cls.__json_mapping = self.mapping
35
+
36
+ def _map(self):
37
+ """
38
+ Convert the object's attributes to a dictionary with mapped attribute names.
39
+
40
+ :return: A dictionary with mapped attribute names and values.
41
+ :rtype: dict
42
+ """
43
+ map = self.__json_mapping
44
+ attribute_dict = vars(self)
45
+ result_dict = {}
46
+
47
+ for key, value in attribute_dict.items():
48
+ if isinstance(value, list):
49
+ value = [v._map() if hasattr(v, "_map") else v for v in value]
50
+ elif isinstance(value, Enum):
51
+ value = value.value
52
+ elif hasattr(value, "_map"):
53
+ value = value._map()
54
+ mapped_key = map.get(key, key)
55
+ result_dict[mapped_key] = value
56
+
57
+ return result_dict
58
+
59
+ @classmethod
60
+ def _unmap(cls, mapped_data):
61
+ """
62
+ Create an object instance from a dictionary with mapped attribute names.
63
+
64
+ :param mapped_data: A dictionary with mapped attribute names and values.
65
+ :type mapped_data: dict
66
+ :return: An instance of the class with attribute values assigned from the dictionary.
67
+ :rtype: cls
68
+ """
69
+ reversed_map = {v: k for k, v in cls.__json_mapping.items()}
70
+ mapped_attributes = {}
71
+ for key, value in mapped_data.items():
72
+ mapped_key = reversed_map.get(key, key)
73
+ mapped_attributes[mapped_key] = value
74
+
75
+ return cls(**mapped_attributes)
76
+
77
+ cls._map = _map
78
+ cls._unmap = _unmap
79
+
80
+ return cls
File without changes
@@ -0,0 +1 @@
1
+ from .environment import Environment
@@ -0,0 +1,11 @@
1
+ """
2
+ An enum class containing all the possible environments for the SDK
3
+ """
4
+
5
+ from enum import Enum
6
+
7
+
8
+ class Environment(Enum):
9
+ """The environments available for the SDK"""
10
+
11
+ DEFAULT = "https://api.celitech.net/v1"
File without changes
@@ -0,0 +1,9 @@
1
+ from typing import Any, Dict
2
+
3
+
4
+ class BaseHeader:
5
+ def set_value(self, value: Any) -> None:
6
+ pass
7
+
8
+ def get_headers(self) -> Dict[str, str]:
9
+ pass
File without changes
File without changes