wingify-fme-python-sdk 1.70.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.
- tests/data/__init__.py +13 -0
- tests/data/dummy_test_data_reader.py +63 -0
- tests/data/user_storage.py +48 -0
- tests/e2e/__init__.py +13 -0
- tests/e2e/custom_bucketing_test.py +514 -0
- tests/e2e/force_users_test.py +368 -0
- tests/e2e/get_flag_test.py +195 -0
- tests/unit/__init__.py +13 -0
- tests/unit/packages/__init__.py +13 -0
- tests/unit/packages/decision_maker/__init__.py +13 -0
- tests/unit/packages/decision_maker/decision_maker_test.py +83 -0
- tests/unit/packages/segmentation_evaluator/__init__.py +13 -0
- tests/unit/packages/segmentation_evaluator/segmentation_evaluator_test.py +284 -0
- tests/unit/packages/segmentation_evaluator/segmentation_manager_test.py +215 -0
- tests/unit/packages/segmentation_evaluator/web_testing_segment_test.py +216 -0
- tests/unit/services/__init__.py +0 -0
- tests/unit/services/hooks_manager_test.py +80 -0
- tests/unit/services/internal_events_sampling_service_test.py +160 -0
- tests/unit/settings/__init__.py +13 -0
- tests/unit/settings/settings_schema_validation_test.py +67 -0
- tests/unit/utils/__init__.py +0 -0
- tests/unit/utils/campaign_util_test.py +248 -0
- tests/unit/utils/decision_util_force_users_test.py +790 -0
- tests/unit/utils/log_message_test.py +65 -0
- tests/unit/vwo_wingify_test.py +175 -0
- tests/unit/wingify_client_validation_test.py +72 -0
- vwo/__init__.py +35 -0
- vwo/models/__init__.py +13 -0
- vwo/models/batch_event_data.py +19 -0
- vwo/models/user/__init__.py +13 -0
- vwo/models/user/context_vwo_model.py +21 -0
- vwo/models/user/get_flag.py +19 -0
- vwo/models/vwo_options_model.py +21 -0
- vwo/packages/__init__.py +13 -0
- vwo/packages/logger/__init__.py +13 -0
- vwo/packages/logger/enums/__init__.py +13 -0
- vwo/packages/logger/enums/log_level_enum.py +19 -0
- vwo/packages/storage/__init__.py +13 -0
- vwo/packages/storage/connector.py +19 -0
- vwo/vwo.py +58 -0
- vwo/vwo_builder.py +21 -0
- vwo/vwo_client.py +22 -0
- wingify/__init__.py +36 -0
- wingify/api/__init__.py +13 -0
- wingify/api/get_flag_api.py +727 -0
- wingify/api/set_attribute_api.py +60 -0
- wingify/api/track_api.py +99 -0
- wingify/constants/Constants.py +94 -0
- wingify/constants/__init__.py +13 -0
- wingify/constants/sampled_debug_error_template_keys.py +34 -0
- wingify/decorators/__init__.py +13 -0
- wingify/decorators/storage_decorator.py +92 -0
- wingify/enums/__init__.py +13 -0
- wingify/enums/api_enum.py +26 -0
- wingify/enums/campaign_type_enum.py +22 -0
- wingify/enums/debug_category_enum.py +24 -0
- wingify/enums/event_enum.py +26 -0
- wingify/enums/headers_enum.py +21 -0
- wingify/enums/hooks_enum.py +24 -0
- wingify/enums/status_enum.py +21 -0
- wingify/enums/storage_enum.py +25 -0
- wingify/enums/url_enum.py +29 -0
- wingify/models/Alias.py +60 -0
- wingify/models/AliasSetResponse.py +43 -0
- wingify/models/__init__.py +13 -0
- wingify/models/batch_event_data.py +68 -0
- wingify/models/campaign/__init__.py +13 -0
- wingify/models/campaign/campaign_model.py +140 -0
- wingify/models/campaign/feature_model.py +95 -0
- wingify/models/campaign/holdout_model.py +94 -0
- wingify/models/campaign/impact_campaign_model.py +60 -0
- wingify/models/campaign/metric_model.py +42 -0
- wingify/models/campaign/rule_model.py +42 -0
- wingify/models/campaign/variable_model.py +44 -0
- wingify/models/campaign/variation_model.py +109 -0
- wingify/models/gateway_service_model.py +48 -0
- wingify/models/schemas/__init__.py +13 -0
- wingify/models/schemas/campaign_group_schema.py +19 -0
- wingify/models/schemas/campaign_metric_schema.py +26 -0
- wingify/models/schemas/campaign_schema.py +37 -0
- wingify/models/schemas/campaign_variation_schema.py +34 -0
- wingify/models/schemas/empty_object_schema.py +15 -0
- wingify/models/schemas/feature_schema.py +38 -0
- wingify/models/schemas/group_schema.py +37 -0
- wingify/models/schemas/holdout_schema.py +29 -0
- wingify/models/schemas/rule_schema.py +24 -0
- wingify/models/schemas/settings_schema.py +47 -0
- wingify/models/schemas/variable_schema.py +24 -0
- wingify/models/settings/__init__.py +13 -0
- wingify/models/settings/internal_event_sampling_settings_model.py +53 -0
- wingify/models/settings/settings_model.py +127 -0
- wingify/models/storage/__init__.py +13 -0
- wingify/models/storage/storage_model.py +84 -0
- wingify/models/user/__init__.py +13 -0
- wingify/models/user/context_model.py +113 -0
- wingify/models/user/context_vwo_model.py +34 -0
- wingify/models/user/get_flag.py +47 -0
- wingify/models/vwo_options_model.py +21 -0
- wingify/models/wingify_options_model.py +129 -0
- wingify/packages/__init__.py +13 -0
- wingify/packages/decision_maker/__init__.py +13 -0
- wingify/packages/decision_maker/decision_maker.py +89 -0
- wingify/packages/logger/__init__.py +13 -0
- wingify/packages/logger/core/__init__.py +13 -0
- wingify/packages/logger/core/log_manager.py +123 -0
- wingify/packages/logger/core/log_transport_manager.py +57 -0
- wingify/packages/logger/enums/__init__.py +13 -0
- wingify/packages/logger/enums/log_level_enum.py +24 -0
- wingify/packages/logger/enums/log_level_number_enum.py +21 -0
- wingify/packages/logger/log_message_builder.py +70 -0
- wingify/packages/logger/logger.py +38 -0
- wingify/packages/logger/transports/__init__.py +13 -0
- wingify/packages/logger/transports/console_transport.py +43 -0
- wingify/packages/network_layer/__init__.py +13 -0
- wingify/packages/network_layer/client/__init__.py +13 -0
- wingify/packages/network_layer/client/network_client.py +167 -0
- wingify/packages/network_layer/handlers/__init__.py +13 -0
- wingify/packages/network_layer/handlers/request_handler.py +40 -0
- wingify/packages/network_layer/manager/__init__.py +13 -0
- wingify/packages/network_layer/manager/network_manager.py +79 -0
- wingify/packages/network_layer/models/__init__.py +13 -0
- wingify/packages/network_layer/models/global_request_model.py +70 -0
- wingify/packages/network_layer/models/request_model.py +133 -0
- wingify/packages/network_layer/models/response_model.py +55 -0
- wingify/packages/segmentation_evaluator/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/core/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/core/segmentation_manager.py +140 -0
- wingify/packages/segmentation_evaluator/enums/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/enums/segment_operand_regex_enum.py +31 -0
- wingify/packages/segmentation_evaluator/enums/segment_operand_value_enum.py +29 -0
- wingify/packages/segmentation_evaluator/enums/segment_operator_value_enum.py +37 -0
- wingify/packages/segmentation_evaluator/evaluators/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/evaluators/segment_evaluator.py +237 -0
- wingify/packages/segmentation_evaluator/evaluators/segment_operand_evaluator.py +518 -0
- wingify/packages/segmentation_evaluator/utils/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/utils/segment_util.py +33 -0
- wingify/packages/segmentation_evaluator/utils/web_testing_segment_util.py +295 -0
- wingify/packages/storage/__init__.py +13 -0
- wingify/packages/storage/connector.py +25 -0
- wingify/packages/storage/storage.py +39 -0
- wingify/resources/__init__.py +13 -0
- wingify/resources/debug-messages.json +21 -0
- wingify/resources/error-messages.json +62 -0
- wingify/resources/info-message.json +47 -0
- wingify/resources/trace-messages.json +1 -0
- wingify/resources/warn-messages.json +1 -0
- wingify/services/__init__.py +13 -0
- wingify/services/batch_event_queue.py +140 -0
- wingify/services/campaign_decision_service.py +268 -0
- wingify/services/hooks_manager.py +65 -0
- wingify/services/internal_events_sampling_service.py +62 -0
- wingify/services/settings_manager.py +293 -0
- wingify/services/storage_service.py +58 -0
- wingify/services/url_service.py +51 -0
- wingify/utils/__init__.py +13 -0
- wingify/utils/aliasing_util.py +108 -0
- wingify/utils/brand_context.py +26 -0
- wingify/utils/brand_util.py +37 -0
- wingify/utils/campaign_util.py +592 -0
- wingify/utils/data_type_util.py +125 -0
- wingify/utils/debugger_service_util.py +58 -0
- wingify/utils/decision_util.py +589 -0
- wingify/utils/event_util.py +85 -0
- wingify/utils/function_util.py +188 -0
- wingify/utils/gateway_service_util.py +179 -0
- wingify/utils/holdout_util.py +264 -0
- wingify/utils/impression_util.py +151 -0
- wingify/utils/internal_events_sampling_util.py +106 -0
- wingify/utils/log_message_util.py +95 -0
- wingify/utils/meg_util.py +561 -0
- wingify/utils/model_utils.py +136 -0
- wingify/utils/network_util.py +706 -0
- wingify/utils/rule_evaluation_util.py +102 -0
- wingify/utils/settings_util.py +39 -0
- wingify/utils/usage_stats_util.py +116 -0
- wingify/utils/uuid_util.py +81 -0
- wingify/vwo_client.py +21 -0
- wingify/wingify.py +159 -0
- wingify/wingify_builder.py +282 -0
- wingify/wingify_client.py +520 -0
- wingify_fme_python_sdk-1.70.0.dist-info/METADATA +1415 -0
- wingify_fme_python_sdk-1.70.0.dist-info/RECORD +186 -0
- wingify_fme_python_sdk-1.70.0.dist-info/WHEEL +5 -0
- wingify_fme_python_sdk-1.70.0.dist-info/licenses/LICENSE +202 -0
- wingify_fme_python_sdk-1.70.0.dist-info/licenses/NOTICE +18 -0
- wingify_fme_python_sdk-1.70.0.dist-info/top_level.txt +3 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import time
|
|
16
|
+
import requests
|
|
17
|
+
from ..models.request_model import RequestModel
|
|
18
|
+
from ..models.response_model import ResponseModel
|
|
19
|
+
from ....constants.Constants import Constants
|
|
20
|
+
from ...logger.core.log_manager import LogManager
|
|
21
|
+
from ....utils.log_message_util import error_messages
|
|
22
|
+
from ....enums.event_enum import EventEnum
|
|
23
|
+
|
|
24
|
+
class NetworkClient:
|
|
25
|
+
"""
|
|
26
|
+
NetworkClient is a class that handles the network requests for the VWO SDK.
|
|
27
|
+
"""
|
|
28
|
+
def __init__(self):
|
|
29
|
+
self.session = requests.Session()
|
|
30
|
+
self.max_retries = Constants.MAX_RETRIES
|
|
31
|
+
self.initial_wait_time = Constants.INITIAL_WAIT_TIME
|
|
32
|
+
|
|
33
|
+
def get(self, request_model: RequestModel) -> ResponseModel:
|
|
34
|
+
"""
|
|
35
|
+
Sends a GET request to the specified URL.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
:param request_model: The request model containing the URL and headers.
|
|
39
|
+
:return: The response model containing the status code, headers, and data.
|
|
40
|
+
"""
|
|
41
|
+
response_model = ResponseModel()
|
|
42
|
+
options = request_model.get_options()
|
|
43
|
+
for attempt in range(0, self.max_retries + 1):
|
|
44
|
+
try:
|
|
45
|
+
response = self.session.get(
|
|
46
|
+
options["url"],
|
|
47
|
+
headers=options.get("headers"),
|
|
48
|
+
timeout=options.get("timeout"),
|
|
49
|
+
)
|
|
50
|
+
response_model.set_status_code(response.status_code)
|
|
51
|
+
response_model.set_headers(response.headers)
|
|
52
|
+
|
|
53
|
+
if response.headers.get("Content-Type", "").startswith(
|
|
54
|
+
"application/json"
|
|
55
|
+
):
|
|
56
|
+
response_model.set_data(response.json())
|
|
57
|
+
else:
|
|
58
|
+
response_model.set_data(response.text)
|
|
59
|
+
|
|
60
|
+
# If the response is 400, it means the request is invalid and we should return the error
|
|
61
|
+
if response.status_code == 400:
|
|
62
|
+
response_model.set_error(response.text)
|
|
63
|
+
return response_model
|
|
64
|
+
if response.status_code < 200 or response.status_code >= 300:
|
|
65
|
+
raise requests.HTTPError(f"HTTP {response.status_code} error {response.text}")
|
|
66
|
+
|
|
67
|
+
return response_model
|
|
68
|
+
|
|
69
|
+
except (
|
|
70
|
+
requests.Timeout,
|
|
71
|
+
requests.ConnectionError,
|
|
72
|
+
requests.HTTPError,
|
|
73
|
+
) as e:
|
|
74
|
+
response_model.set_error(str(e))
|
|
75
|
+
response_model.set_total_attempts(attempt)
|
|
76
|
+
url_without_query_params = options["url"].split("?")[0]
|
|
77
|
+
if attempt == self.max_retries:
|
|
78
|
+
LogManager.get_instance().error(
|
|
79
|
+
error_messages.get("NETWORK_CALL_RETRY_FAILED").format(
|
|
80
|
+
endPoint=url_without_query_params, err=str(e)
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
return response_model
|
|
84
|
+
|
|
85
|
+
sleep_time = self.initial_wait_time * (2 ** (attempt))
|
|
86
|
+
LogManager.get_instance().error(
|
|
87
|
+
error_messages.get("ATTEMPTING_RETRY_FOR_FAILED_NETWORK_CALL").format(
|
|
88
|
+
endPoint=url_without_query_params,
|
|
89
|
+
err=str(e),
|
|
90
|
+
delay=round(sleep_time, 2),
|
|
91
|
+
attempt=attempt + 1,
|
|
92
|
+
maxRetries=self.max_retries,
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
time.sleep(sleep_time)
|
|
96
|
+
return response_model
|
|
97
|
+
|
|
98
|
+
def post(self, request_model: RequestModel) -> ResponseModel:
|
|
99
|
+
"""
|
|
100
|
+
Sends a POST request to the specified URL.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
request_model: The request model containing the URL and headers.
|
|
104
|
+
:return: The response model containing the status code, headers, and data.
|
|
105
|
+
"""
|
|
106
|
+
response_model = ResponseModel()
|
|
107
|
+
options = request_model.get_options()
|
|
108
|
+
|
|
109
|
+
for attempt in range(0, self.max_retries + 1):
|
|
110
|
+
try:
|
|
111
|
+
response = self.session.post(
|
|
112
|
+
options["url"],
|
|
113
|
+
json=options.get("json"),
|
|
114
|
+
headers=options.get("headers"),
|
|
115
|
+
timeout=options.get("timeout"),
|
|
116
|
+
)
|
|
117
|
+
response_model.set_status_code(response.status_code)
|
|
118
|
+
response_model.set_headers(response.headers)
|
|
119
|
+
|
|
120
|
+
if response.headers.get("Content-Type", "").startswith(
|
|
121
|
+
"application/json"
|
|
122
|
+
):
|
|
123
|
+
response_model.set_data(response.json())
|
|
124
|
+
else:
|
|
125
|
+
response_model.set_data(response.text)
|
|
126
|
+
|
|
127
|
+
# If the response is 400, it means the request is invalid and we should return the error
|
|
128
|
+
if response.status_code == 400:
|
|
129
|
+
response_model.set_error(response.text)
|
|
130
|
+
return response_model
|
|
131
|
+
|
|
132
|
+
if response.status_code < 200 or response.status_code >= 300:
|
|
133
|
+
raise requests.HTTPError(f"HTTP {response.status_code} error {response.text}")
|
|
134
|
+
|
|
135
|
+
return response_model
|
|
136
|
+
|
|
137
|
+
except (
|
|
138
|
+
requests.Timeout,
|
|
139
|
+
requests.ConnectionError,
|
|
140
|
+
requests.HTTPError,
|
|
141
|
+
) as e:
|
|
142
|
+
response_model.set_error(str(e))
|
|
143
|
+
response_model.set_total_attempts(attempt)
|
|
144
|
+
url_without_query_params = options["url"].split("?")[0]
|
|
145
|
+
if EventEnum.LOG_EVENT.value in options["url"]:
|
|
146
|
+
return response_model
|
|
147
|
+
|
|
148
|
+
if attempt == self.max_retries:
|
|
149
|
+
LogManager.get_instance().error(
|
|
150
|
+
error_messages.get("NETWORK_CALL_RETRY_FAILED").format(
|
|
151
|
+
endPoint=url_without_query_params, err=str(e)
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
return response_model
|
|
155
|
+
|
|
156
|
+
sleep_time = self.initial_wait_time * (2 ** (attempt))
|
|
157
|
+
LogManager.get_instance().error(
|
|
158
|
+
error_messages.get("ATTEMPTING_RETRY_FOR_FAILED_NETWORK_CALL").format(
|
|
159
|
+
endPoint=url_without_query_params,
|
|
160
|
+
err=str(e),
|
|
161
|
+
delay=round(sleep_time, 2),
|
|
162
|
+
attempt=attempt + 1,
|
|
163
|
+
maxRetries=self.max_retries,
|
|
164
|
+
)
|
|
165
|
+
)
|
|
166
|
+
time.sleep(sleep_time)
|
|
167
|
+
return response_model
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from ..models.request_model import RequestModel
|
|
17
|
+
from ..models.global_request_model import GlobalRequestModel
|
|
18
|
+
from typing import Optional
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class RequestHandler:
|
|
22
|
+
def create_request(
|
|
23
|
+
self, request: RequestModel, config: GlobalRequestModel
|
|
24
|
+
) -> Optional[RequestModel]:
|
|
25
|
+
if not config.get_base_url() and not request.get_url():
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
request.set_url(request.get_url() or config.get_base_url())
|
|
29
|
+
request.set_timeout(request.get_timeout() or config.get_timeout())
|
|
30
|
+
request.set_body(request.get_body() or config.get_body())
|
|
31
|
+
request.set_headers(request.get_headers() or config.get_headers())
|
|
32
|
+
|
|
33
|
+
request_query_params = request.get_query()
|
|
34
|
+
config_query_params = config.get_query()
|
|
35
|
+
for key, value in config_query_params.items():
|
|
36
|
+
if key not in request_query_params:
|
|
37
|
+
request_query_params[key] = value
|
|
38
|
+
|
|
39
|
+
request.set_query(request_query_params)
|
|
40
|
+
return request
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from ..models.global_request_model import GlobalRequestModel
|
|
17
|
+
from ..models.request_model import RequestModel
|
|
18
|
+
from ..models.response_model import ResponseModel
|
|
19
|
+
from ..handlers.request_handler import RequestHandler
|
|
20
|
+
from ..client.network_client import NetworkClient
|
|
21
|
+
from ...logger.core.log_manager import LogManager
|
|
22
|
+
from ....utils.log_message_util import error_messages
|
|
23
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
24
|
+
from typing import Callable, Dict, Any
|
|
25
|
+
from ....constants.Constants import Constants
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class NetworkManager:
|
|
29
|
+
_instance = None
|
|
30
|
+
|
|
31
|
+
def __init__(self, threading: Dict[str, Any] = None):
|
|
32
|
+
self.client = None
|
|
33
|
+
self.config = None
|
|
34
|
+
self.should_use_threading = threading.get(
|
|
35
|
+
"enabled", Constants.SHOULD_USE_THREADING
|
|
36
|
+
)
|
|
37
|
+
self.thread_pool_max_workers = threading.get(
|
|
38
|
+
"max_workers", Constants.THREAD_POOL_MAX_WORKERS
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def set_config(self, config: GlobalRequestModel):
|
|
42
|
+
self.config = config
|
|
43
|
+
|
|
44
|
+
def get_config(self) -> GlobalRequestModel:
|
|
45
|
+
return self.config
|
|
46
|
+
|
|
47
|
+
def attach_client(self):
|
|
48
|
+
self.client = NetworkClient()
|
|
49
|
+
self.config = GlobalRequestModel()
|
|
50
|
+
|
|
51
|
+
@classmethod
|
|
52
|
+
def get_instance(cls, threading: Dict[str, Any] = None) -> "NetworkManager":
|
|
53
|
+
if cls._instance is None:
|
|
54
|
+
cls._instance = cls(threading)
|
|
55
|
+
return cls._instance
|
|
56
|
+
|
|
57
|
+
def create_request(self, request: RequestModel) -> RequestModel:
|
|
58
|
+
return RequestHandler().create_request(request, self.config)
|
|
59
|
+
|
|
60
|
+
def get(self, request: RequestModel) -> ResponseModel:
|
|
61
|
+
request_model = self.create_request(request)
|
|
62
|
+
if not request_model or not request_model.get_url():
|
|
63
|
+
response = ResponseModel()
|
|
64
|
+
response.set_error("No URL found")
|
|
65
|
+
return response
|
|
66
|
+
return self.client.get(request_model)
|
|
67
|
+
|
|
68
|
+
def post(self, request: RequestModel) -> ResponseModel:
|
|
69
|
+
request_model = self.create_request(request)
|
|
70
|
+
if not request_model or not request_model.get_url():
|
|
71
|
+
response = ResponseModel()
|
|
72
|
+
response.set_error("No URL found")
|
|
73
|
+
return response
|
|
74
|
+
return self.client.post(request_model)
|
|
75
|
+
|
|
76
|
+
# Generic function to handle background task execution with ThreadPoolExecutor
|
|
77
|
+
def execute_in_background(self, func: Callable):
|
|
78
|
+
executor = ThreadPoolExecutor(max_workers=self.thread_pool_max_workers)
|
|
79
|
+
executor.submit(func)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from typing import Dict, Any, Optional
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class GlobalRequestModel:
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
url: Optional[str] = None,
|
|
23
|
+
query: Optional[Dict[str, Any]] = None,
|
|
24
|
+
body: Optional[Dict[str, Any]] = None,
|
|
25
|
+
headers: Optional[Dict[str, str]] = None,
|
|
26
|
+
timeout: int = 3000,
|
|
27
|
+
is_development_mode: bool = False,
|
|
28
|
+
):
|
|
29
|
+
self.url = url
|
|
30
|
+
self.query = query or {}
|
|
31
|
+
self.body = body or {}
|
|
32
|
+
self.headers = headers or {}
|
|
33
|
+
self.timeout = timeout / 1000 # Convert milliseconds to seconds
|
|
34
|
+
self.is_development_mode = is_development_mode
|
|
35
|
+
|
|
36
|
+
def set_query(self, query: Dict[str, Any]):
|
|
37
|
+
self.query = query
|
|
38
|
+
|
|
39
|
+
def get_query(self) -> Dict[str, Any]:
|
|
40
|
+
return self.query
|
|
41
|
+
|
|
42
|
+
def set_body(self, body: Dict[str, Any]):
|
|
43
|
+
self.body = body
|
|
44
|
+
|
|
45
|
+
def get_body(self) -> Dict[str, Any]:
|
|
46
|
+
return self.body
|
|
47
|
+
|
|
48
|
+
def set_base_url(self, url: str):
|
|
49
|
+
self.url = url
|
|
50
|
+
|
|
51
|
+
def get_base_url(self) -> str:
|
|
52
|
+
return self.url
|
|
53
|
+
|
|
54
|
+
def set_timeout(self, timeout: int):
|
|
55
|
+
self.timeout = timeout / 1000
|
|
56
|
+
|
|
57
|
+
def get_timeout(self) -> int:
|
|
58
|
+
return int(self.timeout * 1000)
|
|
59
|
+
|
|
60
|
+
def set_headers(self, headers: Dict[str, str]):
|
|
61
|
+
self.headers = headers
|
|
62
|
+
|
|
63
|
+
def get_headers(self) -> Dict[str, str]:
|
|
64
|
+
return self.headers
|
|
65
|
+
|
|
66
|
+
def set_development_mode(self, is_development_mode: bool):
|
|
67
|
+
self.is_development_mode = is_development_mode
|
|
68
|
+
|
|
69
|
+
def get_development_mode(self) -> bool:
|
|
70
|
+
return self.is_development_mode
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from typing import Dict, Any, Optional
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class RequestModel:
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
url: Optional[str] = None,
|
|
23
|
+
method: str = "GET",
|
|
24
|
+
path: str = "",
|
|
25
|
+
query: Optional[Dict[str, Any]] = None,
|
|
26
|
+
body: Optional[Dict[str, Any]] = None,
|
|
27
|
+
headers: Optional[Dict[str, str]] = None,
|
|
28
|
+
scheme: str = "https",
|
|
29
|
+
port: Optional[int] = None,
|
|
30
|
+
timeout: int = 3000,
|
|
31
|
+
):
|
|
32
|
+
self.url = url
|
|
33
|
+
self.method = method
|
|
34
|
+
self.path = path
|
|
35
|
+
self.query = query or {}
|
|
36
|
+
self.body = body or {}
|
|
37
|
+
self.headers = headers or {}
|
|
38
|
+
self.scheme = scheme
|
|
39
|
+
self.port = port
|
|
40
|
+
self.timeout = timeout / 1000 # Convert milliseconds to seconds
|
|
41
|
+
self.last_error = None
|
|
42
|
+
|
|
43
|
+
def get_method(self) -> str:
|
|
44
|
+
return self.method
|
|
45
|
+
|
|
46
|
+
def set_method(self, method: str):
|
|
47
|
+
self.method = method
|
|
48
|
+
|
|
49
|
+
def get_body(self) -> Dict[str, Any]:
|
|
50
|
+
return self.body
|
|
51
|
+
|
|
52
|
+
def set_body(self, body: Dict[str, Any]):
|
|
53
|
+
self.body = body
|
|
54
|
+
|
|
55
|
+
def set_query(self, query: Dict[str, Any]):
|
|
56
|
+
self.query = query
|
|
57
|
+
|
|
58
|
+
def get_query(self) -> Dict[str, Any]:
|
|
59
|
+
return self.query
|
|
60
|
+
|
|
61
|
+
def set_headers(self, headers: Dict[str, str]):
|
|
62
|
+
self.headers = headers
|
|
63
|
+
|
|
64
|
+
def get_headers(self) -> Dict[str, str]:
|
|
65
|
+
return self.headers
|
|
66
|
+
|
|
67
|
+
def set_timeout(self, timeout: int):
|
|
68
|
+
self.timeout = timeout / 1000
|
|
69
|
+
|
|
70
|
+
def get_timeout(self) -> int:
|
|
71
|
+
return int(self.timeout * 1000)
|
|
72
|
+
|
|
73
|
+
def get_url(self) -> Optional[str]:
|
|
74
|
+
return self.url
|
|
75
|
+
|
|
76
|
+
def set_url(self, url: str):
|
|
77
|
+
self.url = url
|
|
78
|
+
|
|
79
|
+
def get_scheme(self) -> str:
|
|
80
|
+
return self.scheme
|
|
81
|
+
|
|
82
|
+
def set_scheme(self, scheme: str):
|
|
83
|
+
self.scheme = scheme
|
|
84
|
+
|
|
85
|
+
def get_port(self) -> Optional[int]:
|
|
86
|
+
return self.port
|
|
87
|
+
|
|
88
|
+
def set_port(self, port: int):
|
|
89
|
+
self.port = port
|
|
90
|
+
|
|
91
|
+
def get_path(self) -> str:
|
|
92
|
+
return self.path
|
|
93
|
+
|
|
94
|
+
def set_path(self, path: str):
|
|
95
|
+
self.path = path
|
|
96
|
+
|
|
97
|
+
def set_user_id(self, user_id: str):
|
|
98
|
+
self.user_id = user_id
|
|
99
|
+
|
|
100
|
+
def get_user_id(self) -> str:
|
|
101
|
+
return self.user_id
|
|
102
|
+
|
|
103
|
+
def set_last_error(self, last_error: str):
|
|
104
|
+
self.last_error = last_error
|
|
105
|
+
|
|
106
|
+
def get_last_error(self) -> str:
|
|
107
|
+
return self.last_error
|
|
108
|
+
|
|
109
|
+
def get_options(self) -> Dict[str, Any]:
|
|
110
|
+
query_params = "&".join([f"{key}={value}" for key, value in self.query.items()])
|
|
111
|
+
options = {
|
|
112
|
+
"url": self.url,
|
|
113
|
+
"method": self.method,
|
|
114
|
+
"headers": self.headers,
|
|
115
|
+
"timeout": self.timeout,
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if self.scheme and self.url:
|
|
119
|
+
options["url"] = f"{self.scheme}://{self.url}"
|
|
120
|
+
|
|
121
|
+
if self.port:
|
|
122
|
+
options["url"] += f":{self.port}"
|
|
123
|
+
|
|
124
|
+
if self.path:
|
|
125
|
+
options["url"] += self.path
|
|
126
|
+
|
|
127
|
+
if query_params:
|
|
128
|
+
options["url"] += f"?{query_params}"
|
|
129
|
+
|
|
130
|
+
if self.body:
|
|
131
|
+
options["json"] = self.body
|
|
132
|
+
|
|
133
|
+
return options
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from typing import Dict, Any, Optional
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ResponseModel:
|
|
20
|
+
def __init__(self):
|
|
21
|
+
self.status_code = None
|
|
22
|
+
self.headers = {}
|
|
23
|
+
self.data = None
|
|
24
|
+
self.error = None
|
|
25
|
+
self.total_attempts = 0
|
|
26
|
+
|
|
27
|
+
def set_status_code(self, status_code: int):
|
|
28
|
+
self.status_code = status_code
|
|
29
|
+
|
|
30
|
+
def get_status_code(self) -> Optional[int]:
|
|
31
|
+
return self.status_code
|
|
32
|
+
|
|
33
|
+
def set_headers(self, headers: Dict[str, str]):
|
|
34
|
+
self.headers = headers
|
|
35
|
+
|
|
36
|
+
def get_headers(self) -> Dict[str, str]:
|
|
37
|
+
return self.headers
|
|
38
|
+
|
|
39
|
+
def set_data(self, data: Any):
|
|
40
|
+
self.data = data
|
|
41
|
+
|
|
42
|
+
def get_data(self) -> Any:
|
|
43
|
+
return self.data
|
|
44
|
+
|
|
45
|
+
def set_error(self, error: Any):
|
|
46
|
+
self.error = error
|
|
47
|
+
|
|
48
|
+
def get_error(self) -> Any:
|
|
49
|
+
return self.error
|
|
50
|
+
|
|
51
|
+
def set_total_attempts(self, total_attempts: int):
|
|
52
|
+
self.total_attempts = total_attempts
|
|
53
|
+
|
|
54
|
+
def get_total_attempts(self) -> int:
|
|
55
|
+
return self.total_attempts
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|