everysk-lib 1.10.2__cp312-cp312-win_amd64.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.
- everysk/__init__.py +30 -0
- everysk/_version.py +683 -0
- everysk/api/__init__.py +61 -0
- everysk/api/api_requestor.py +167 -0
- everysk/api/api_resources/__init__.py +23 -0
- everysk/api/api_resources/api_resource.py +371 -0
- everysk/api/api_resources/calculation.py +779 -0
- everysk/api/api_resources/custom_index.py +42 -0
- everysk/api/api_resources/datastore.py +81 -0
- everysk/api/api_resources/file.py +42 -0
- everysk/api/api_resources/market_data.py +223 -0
- everysk/api/api_resources/parser.py +66 -0
- everysk/api/api_resources/portfolio.py +43 -0
- everysk/api/api_resources/private_security.py +42 -0
- everysk/api/api_resources/report.py +65 -0
- everysk/api/api_resources/report_template.py +39 -0
- everysk/api/api_resources/tests.py +115 -0
- everysk/api/api_resources/worker_execution.py +64 -0
- everysk/api/api_resources/workflow.py +65 -0
- everysk/api/api_resources/workflow_execution.py +93 -0
- everysk/api/api_resources/workspace.py +42 -0
- everysk/api/http_client.py +63 -0
- everysk/api/tests.py +32 -0
- everysk/api/utils.py +262 -0
- everysk/config.py +451 -0
- everysk/core/_tests/serialize/test_json.py +336 -0
- everysk/core/_tests/serialize/test_orjson.py +295 -0
- everysk/core/_tests/serialize/test_pickle.py +48 -0
- everysk/core/cloud_function/main.py +78 -0
- everysk/core/cloud_function/tests.py +86 -0
- everysk/core/compress.py +245 -0
- everysk/core/datetime/__init__.py +12 -0
- everysk/core/datetime/calendar.py +144 -0
- everysk/core/datetime/date.py +424 -0
- everysk/core/datetime/date_expression.py +299 -0
- everysk/core/datetime/date_mixin.py +1475 -0
- everysk/core/datetime/date_settings.py +30 -0
- everysk/core/datetime/datetime.py +713 -0
- everysk/core/exceptions.py +435 -0
- everysk/core/fields.py +1176 -0
- everysk/core/firestore.py +555 -0
- everysk/core/fixtures/_settings.py +29 -0
- everysk/core/fixtures/other/_settings.py +18 -0
- everysk/core/fixtures/user_agents.json +88 -0
- everysk/core/http.py +691 -0
- everysk/core/lists.py +92 -0
- everysk/core/log.py +709 -0
- everysk/core/number.py +37 -0
- everysk/core/object.py +1469 -0
- everysk/core/redis.py +1021 -0
- everysk/core/retry.py +51 -0
- everysk/core/serialize.py +674 -0
- everysk/core/sftp.py +414 -0
- everysk/core/signing.py +53 -0
- everysk/core/slack.py +127 -0
- everysk/core/string.py +199 -0
- everysk/core/tests.py +240 -0
- everysk/core/threads.py +199 -0
- everysk/core/undefined.py +70 -0
- everysk/core/unittests.py +73 -0
- everysk/core/workers.py +241 -0
- everysk/sdk/__init__.py +23 -0
- everysk/sdk/base.py +98 -0
- everysk/sdk/brutils/cnpj.py +391 -0
- everysk/sdk/brutils/cnpj_pd.py +129 -0
- everysk/sdk/engines/__init__.py +26 -0
- everysk/sdk/engines/cache.py +185 -0
- everysk/sdk/engines/compliance.py +37 -0
- everysk/sdk/engines/cryptography.py +69 -0
- everysk/sdk/engines/expression.cp312-win_amd64.pyd +0 -0
- everysk/sdk/engines/expression.pyi +55 -0
- everysk/sdk/engines/helpers.cp312-win_amd64.pyd +0 -0
- everysk/sdk/engines/helpers.pyi +26 -0
- everysk/sdk/engines/lock.py +120 -0
- everysk/sdk/engines/market_data.py +244 -0
- everysk/sdk/engines/settings.py +19 -0
- everysk/sdk/entities/__init__.py +23 -0
- everysk/sdk/entities/base.py +784 -0
- everysk/sdk/entities/base_list.py +131 -0
- everysk/sdk/entities/custom_index/base.py +209 -0
- everysk/sdk/entities/custom_index/settings.py +29 -0
- everysk/sdk/entities/datastore/base.py +160 -0
- everysk/sdk/entities/datastore/settings.py +17 -0
- everysk/sdk/entities/fields.py +375 -0
- everysk/sdk/entities/file/base.py +215 -0
- everysk/sdk/entities/file/settings.py +63 -0
- everysk/sdk/entities/portfolio/base.py +248 -0
- everysk/sdk/entities/portfolio/securities.py +241 -0
- everysk/sdk/entities/portfolio/security.py +580 -0
- everysk/sdk/entities/portfolio/settings.py +97 -0
- everysk/sdk/entities/private_security/base.py +226 -0
- everysk/sdk/entities/private_security/settings.py +17 -0
- everysk/sdk/entities/query.py +603 -0
- everysk/sdk/entities/report/base.py +214 -0
- everysk/sdk/entities/report/settings.py +23 -0
- everysk/sdk/entities/script.py +310 -0
- everysk/sdk/entities/secrets/base.py +128 -0
- everysk/sdk/entities/secrets/script.py +119 -0
- everysk/sdk/entities/secrets/settings.py +17 -0
- everysk/sdk/entities/settings.py +48 -0
- everysk/sdk/entities/tags.py +174 -0
- everysk/sdk/entities/worker_execution/base.py +307 -0
- everysk/sdk/entities/worker_execution/settings.py +63 -0
- everysk/sdk/entities/workflow_execution/base.py +113 -0
- everysk/sdk/entities/workflow_execution/settings.py +32 -0
- everysk/sdk/entities/workspace/base.py +99 -0
- everysk/sdk/entities/workspace/settings.py +27 -0
- everysk/sdk/settings.py +67 -0
- everysk/sdk/tests.py +105 -0
- everysk/sdk/worker_base.py +47 -0
- everysk/server/__init__.py +9 -0
- everysk/server/applications.py +63 -0
- everysk/server/endpoints.py +516 -0
- everysk/server/example_api.py +69 -0
- everysk/server/middlewares.py +80 -0
- everysk/server/requests.py +62 -0
- everysk/server/responses.py +119 -0
- everysk/server/routing.py +64 -0
- everysk/server/settings.py +36 -0
- everysk/server/tests.py +36 -0
- everysk/settings.py +98 -0
- everysk/sql/__init__.py +9 -0
- everysk/sql/connection.py +232 -0
- everysk/sql/model.py +376 -0
- everysk/sql/query.py +417 -0
- everysk/sql/row_factory.py +63 -0
- everysk/sql/settings.py +49 -0
- everysk/sql/utils.py +129 -0
- everysk/tests.py +23 -0
- everysk/utils.py +81 -0
- everysk/version.py +15 -0
- everysk_lib-1.10.2.dist-info/.gitignore +5 -0
- everysk_lib-1.10.2.dist-info/METADATA +326 -0
- everysk_lib-1.10.2.dist-info/RECORD +137 -0
- everysk_lib-1.10.2.dist-info/WHEEL +5 -0
- everysk_lib-1.10.2.dist-info/licenses/LICENSE.txt +9 -0
- everysk_lib-1.10.2.dist-info/top_level.txt +2 -0
everysk/api/__init__.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright 2025 EVERYSK TECHNOLOGIES
|
|
4
|
+
#
|
|
5
|
+
# This is an unpublished work containing confidential and proprietary
|
|
6
|
+
# information of EVERYSK TECHNOLOGIES. Disclosure, use, or reproduction
|
|
7
|
+
# without authorization of EVERYSK TECHNOLOGIES is prohibited.
|
|
8
|
+
#
|
|
9
|
+
###############################################################################
|
|
10
|
+
from everysk.config import settings
|
|
11
|
+
|
|
12
|
+
def get_api_config(params) -> tuple:
|
|
13
|
+
"""
|
|
14
|
+
Retrieve API configuration settings from the give parameters or environment variables
|
|
15
|
+
|
|
16
|
+
This function checks if the arguments `api_entry`, `api_version`, `api_sid`, `api_token`, and `verify_ssl_certs` are provided in the `params` dictionary.
|
|
17
|
+
If not, it attempts to retrieve them from global variables or environment variables.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
params (dict): A dictionary containing the API configuration settings
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
tuple: A tuple containing the API entry point, version, session ID, token, and SSL certificate.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
>>> data = {
|
|
27
|
+
>>> ... 'api_entry': 'https://example.com',
|
|
28
|
+
>>> ... 'api_version': 'v2',
|
|
29
|
+
>>> ... 'api_sid': 'abc',
|
|
30
|
+
>>> ... 'api_token': 'token_example123',
|
|
31
|
+
>>> ... 'verify_ssl_certs': True
|
|
32
|
+
>>> }
|
|
33
|
+
|
|
34
|
+
>>> config = get_api_config(data)
|
|
35
|
+
>>> print(config)
|
|
36
|
+
('https://example.com', 'v2', 'abc', 'token_example123', True)
|
|
37
|
+
"""
|
|
38
|
+
api_entry = params.get('api_entry', None)
|
|
39
|
+
if api_entry is None:
|
|
40
|
+
api_entry = settings.EVERYSK_API_URL
|
|
41
|
+
|
|
42
|
+
api_version = params.get('api_version', None)
|
|
43
|
+
if api_version is None:
|
|
44
|
+
api_version = settings.EVERYSK_API_VERSION
|
|
45
|
+
|
|
46
|
+
api_sid = params.get('api_sid', None)
|
|
47
|
+
if api_sid is None:
|
|
48
|
+
api_sid = settings.EVERYSK_API_SID
|
|
49
|
+
|
|
50
|
+
api_token = params.get('api_token', None)
|
|
51
|
+
if api_token is None:
|
|
52
|
+
api_token = settings.EVERYSK_API_TOKEN
|
|
53
|
+
|
|
54
|
+
verify_ssl_certs = params.get('verify_ssl_certs', None)
|
|
55
|
+
if verify_ssl_certs is None:
|
|
56
|
+
verify_ssl_certs = settings.EVERYSK_API_VERIFY_SSL_CERTS
|
|
57
|
+
|
|
58
|
+
return (api_entry, api_version, api_sid, api_token, verify_ssl_certs)
|
|
59
|
+
|
|
60
|
+
from everysk.utils import *
|
|
61
|
+
from everysk.api.api_resources import *
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright 2025 EVERYSK TECHNOLOGIES
|
|
4
|
+
#
|
|
5
|
+
# This is an unpublished work containing confidential and proprietary
|
|
6
|
+
# information of EVERYSK TECHNOLOGIES. Disclosure, use, or reproduction
|
|
7
|
+
# without authorization of EVERYSK TECHNOLOGIES is prohibited.
|
|
8
|
+
#
|
|
9
|
+
###############################################################################
|
|
10
|
+
import json
|
|
11
|
+
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from everysk.config import settings
|
|
15
|
+
from everysk.api import http_client
|
|
16
|
+
from everysk.core.exceptions import APIError
|
|
17
|
+
|
|
18
|
+
###############################################################################
|
|
19
|
+
# APIRequestor Implementation
|
|
20
|
+
###############################################################################
|
|
21
|
+
class APIRequestor(object):
|
|
22
|
+
|
|
23
|
+
def __init__(self, api_entry, api_version, api_sid, api_token, verify_ssl_certs) -> None:
|
|
24
|
+
"""
|
|
25
|
+
Initializes an APIRequestor object with the necessary parameters to make HTTP requests to an API.
|
|
26
|
+
|
|
27
|
+
This constructors sets up the APIRequestor with custom headers, including authorization, content type and user agent details.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
api_entry (str): The base URL of the API endpoint.
|
|
31
|
+
api_version (str): The current version of the API.
|
|
32
|
+
api_sid (str): The API SID (identifier) for authentication.
|
|
33
|
+
api_token (str): The API token for authentication.
|
|
34
|
+
verify_ssl_certs (bool): Specified whether SSL certificates should be verified.
|
|
35
|
+
|
|
36
|
+
Raises:
|
|
37
|
+
Exception: If any of the parameters are invalid.
|
|
38
|
+
|
|
39
|
+
Example:
|
|
40
|
+
>>> from everysk.api.api_requestor import APIRequestor
|
|
41
|
+
|
|
42
|
+
>>> api_requestor = APIRequestor(
|
|
43
|
+
>>> ... api_entry='https://api.example.com',
|
|
44
|
+
>>> ... api_version='v2',
|
|
45
|
+
>>> ... api_sid='your_api_sid',
|
|
46
|
+
>>> ... api_token='your_api_token',
|
|
47
|
+
>>> ... verify_ssl_certs=True
|
|
48
|
+
>>> ... )
|
|
49
|
+
"""
|
|
50
|
+
if not api_entry:
|
|
51
|
+
raise ValueError('Empty api_entry.') # pylint: disable=broad-exception-raised
|
|
52
|
+
if api_version != 'v2':
|
|
53
|
+
raise ValueError('Invalid api_version (supported version: "v2").') # pylint: disable=broad-exception-raised
|
|
54
|
+
if not api_sid:
|
|
55
|
+
raise ValueError('Invalid api_sid.') # pylint: disable=broad-exception-raised
|
|
56
|
+
if not api_token:
|
|
57
|
+
raise ValueError('Invalid api_token.') # pylint: disable=broad-exception-raised
|
|
58
|
+
|
|
59
|
+
self.headers = settings.HTTP_DEFAULT_HEADERS.copy()
|
|
60
|
+
self.headers.update(
|
|
61
|
+
{
|
|
62
|
+
'Content-Type': 'application/json',
|
|
63
|
+
'Authorization': f'Bearer {api_sid}:{api_token}',
|
|
64
|
+
'User-Agent': f'Everysk PythonBindings/{api_version}'
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
self.base_url = f'{api_entry}/{api_version}'
|
|
68
|
+
self.client = http_client.new_default_http_client(
|
|
69
|
+
timeout=3600,
|
|
70
|
+
verify_ssl_certs=verify_ssl_certs,
|
|
71
|
+
allow_redirects=False
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def _clean_response(self, code: int, response: str) -> Any:
|
|
75
|
+
if code not in settings.HTTP_SUCCESS_STATUS_CODES:
|
|
76
|
+
raise APIError(code, response)
|
|
77
|
+
return json.loads(response)
|
|
78
|
+
|
|
79
|
+
def get(self, path, params):
|
|
80
|
+
"""
|
|
81
|
+
Sends a GET request to the specified path with the given parameters.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
path (str): The path to send the GET request to.
|
|
85
|
+
params (dict): The parameters to include in the GET request.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
dict: The JSON response from the GET request.
|
|
89
|
+
|
|
90
|
+
Raises:
|
|
91
|
+
APIError: If the response code is not in the HTTP_SUCCESS_STATUS_CODES list.
|
|
92
|
+
"""
|
|
93
|
+
url = f'{self.base_url}{path}'
|
|
94
|
+
code, response = self.client.request(
|
|
95
|
+
'GET',
|
|
96
|
+
url,
|
|
97
|
+
headers=self.headers,
|
|
98
|
+
params=params
|
|
99
|
+
)
|
|
100
|
+
return self._clean_response(code, response)
|
|
101
|
+
|
|
102
|
+
def post(self, path, payload):
|
|
103
|
+
"""
|
|
104
|
+
Sends a POST request to the specified path with the given payload.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
path (str): The path to send the request to.
|
|
108
|
+
payload (dict): The payload to include in the request.
|
|
109
|
+
|
|
110
|
+
Raises:
|
|
111
|
+
APIError: If the response code is not in the HTTP_SUCCESS_STATUS_CODES list.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
dict: The JSON response from the API.
|
|
115
|
+
"""
|
|
116
|
+
url = f'{self.base_url}{path}'
|
|
117
|
+
code, response = self.client.request(
|
|
118
|
+
'POST',
|
|
119
|
+
url,
|
|
120
|
+
headers=self.headers,
|
|
121
|
+
payload=payload
|
|
122
|
+
)
|
|
123
|
+
return self._clean_response(code, response)
|
|
124
|
+
|
|
125
|
+
def delete(self, path):
|
|
126
|
+
"""
|
|
127
|
+
Sends a DELETE request to the specified path.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
path (str): The path to send the DELETE request to.
|
|
131
|
+
|
|
132
|
+
Raises:
|
|
133
|
+
APIError: If the response code is not in the HTTP_SUCCESS_STATUS_CODES list.
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
dict: The JSON response from the server.
|
|
137
|
+
"""
|
|
138
|
+
url = f'{self.base_url}{path}'
|
|
139
|
+
code, response = self.client.request(
|
|
140
|
+
'DELETE',
|
|
141
|
+
url,
|
|
142
|
+
headers=self.headers
|
|
143
|
+
)
|
|
144
|
+
return self._clean_response(code, response)
|
|
145
|
+
|
|
146
|
+
def put(self, path, payload):
|
|
147
|
+
"""
|
|
148
|
+
Sends a PUT request to the specified path with the given payload.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
path (str): The path to send the request to.
|
|
152
|
+
payload (dict): The payload to include in the request.
|
|
153
|
+
|
|
154
|
+
Raises:
|
|
155
|
+
APIError: If the response code is not in the HTTP_SUCCESS_STATUS_CODES list.
|
|
156
|
+
|
|
157
|
+
Returns:
|
|
158
|
+
dict: The JSON response from the server.
|
|
159
|
+
"""
|
|
160
|
+
url = f'{self.base_url}{path}'
|
|
161
|
+
code, response = self.client.request(
|
|
162
|
+
'PUT',
|
|
163
|
+
url,
|
|
164
|
+
headers=self.headers,
|
|
165
|
+
payload=payload
|
|
166
|
+
)
|
|
167
|
+
return self._clean_response(code, response)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright 2025 EVERYSK TECHNOLOGIES
|
|
4
|
+
#
|
|
5
|
+
# This is an unpublished work containing confidential and proprietary
|
|
6
|
+
# information of EVERYSK TECHNOLOGIES. Disclosure, use, or reproduction
|
|
7
|
+
# without authorization of EVERYSK TECHNOLOGIES is prohibited.
|
|
8
|
+
#
|
|
9
|
+
###############################################################################
|
|
10
|
+
from everysk.api.api_resources.workspace import Workspace
|
|
11
|
+
from everysk.api.api_resources.workflow import Workflow
|
|
12
|
+
from everysk.api.api_resources.workflow_execution import WorkflowExecution
|
|
13
|
+
from everysk.api.api_resources.worker_execution import WorkerExecution
|
|
14
|
+
from everysk.api.api_resources.portfolio import Portfolio
|
|
15
|
+
from everysk.api.api_resources.report import Report
|
|
16
|
+
from everysk.api.api_resources.report_template import ReportTemplate
|
|
17
|
+
from everysk.api.api_resources.datastore import Datastore
|
|
18
|
+
from everysk.api.api_resources.file import File
|
|
19
|
+
from everysk.api.api_resources.custom_index import CustomIndex
|
|
20
|
+
from everysk.api.api_resources.private_security import PrivateSecurity
|
|
21
|
+
from everysk.api.api_resources.calculation import Calculation
|
|
22
|
+
from everysk.api.api_resources.market_data import MarketData
|
|
23
|
+
from everysk.api.api_resources.parser import Parser
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright 2025 EVERYSK TECHNOLOGIES
|
|
4
|
+
#
|
|
5
|
+
# This is an unpublished work containing confidential and proprietary
|
|
6
|
+
# information of EVERYSK TECHNOLOGIES. Disclosure, use, or reproduction
|
|
7
|
+
# without authorization of EVERYSK TECHNOLOGIES is prohibited.
|
|
8
|
+
#
|
|
9
|
+
###############################################################################
|
|
10
|
+
|
|
11
|
+
###############################################################################
|
|
12
|
+
# Imports
|
|
13
|
+
###############################################################################
|
|
14
|
+
from everysk.api import utils
|
|
15
|
+
from everysk.core.string import pluralize, snake_case
|
|
16
|
+
|
|
17
|
+
###############################################################################
|
|
18
|
+
# APIResource Implementation
|
|
19
|
+
###############################################################################
|
|
20
|
+
class APIResource(utils.EveryskObject):
|
|
21
|
+
"""
|
|
22
|
+
Represents a resource accessible via an API
|
|
23
|
+
|
|
24
|
+
This class serves as a base class for API resources and provides method for refreshing resource data and obtaining class names and URLs.
|
|
25
|
+
"""
|
|
26
|
+
def __init__(self, retrieve_params, params) -> None:
|
|
27
|
+
super().__init__(retrieve_params, params)
|
|
28
|
+
self.__retrieve_params = retrieve_params
|
|
29
|
+
|
|
30
|
+
def refresh(self, **kwargs):
|
|
31
|
+
"""
|
|
32
|
+
Refreshes the resource data from the API.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
**kwargs: Additional keyword arguments.
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
APIResource: The refreshed APIResource object.
|
|
39
|
+
"""
|
|
40
|
+
api_req = utils.create_api_requestor(kwargs)
|
|
41
|
+
url = f"{self.class_url()}/{self.get('id')}"
|
|
42
|
+
response = api_req.get(url, self.__retrieve_params)
|
|
43
|
+
data = response[self.class_name()]
|
|
44
|
+
self.update(data)
|
|
45
|
+
self.clear_unsaved_values()
|
|
46
|
+
return self
|
|
47
|
+
|
|
48
|
+
@classmethod
|
|
49
|
+
def class_name(cls):
|
|
50
|
+
"""
|
|
51
|
+
convert the class name to the snake case format
|
|
52
|
+
"""
|
|
53
|
+
return snake_case(cls.__name__)
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def class_name_list(cls):
|
|
57
|
+
"""
|
|
58
|
+
Returns the pluralized class name.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
str: The pluralized class name.
|
|
62
|
+
"""
|
|
63
|
+
return pluralize(cls.class_name())
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def class_url(cls):
|
|
67
|
+
"""
|
|
68
|
+
Returns the URL path for the class.
|
|
69
|
+
Utilizing the class name list and ensuring consistency across different parts of the code.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
str: The URL path for the class.
|
|
73
|
+
"""
|
|
74
|
+
return f'/{cls.class_name_list()}'
|
|
75
|
+
|
|
76
|
+
###############################################################################
|
|
77
|
+
# Retrievable APIResource Implementation
|
|
78
|
+
###############################################################################
|
|
79
|
+
class RetrievableAPIResource(APIResource):
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def retrieve(cls, id, **kwargs):
|
|
83
|
+
"""
|
|
84
|
+
Retrieves a single resource from the API by its ID.
|
|
85
|
+
Sends a GET request to the API to retrieve a single resource of the specified class type
|
|
86
|
+
identified by the provided ID.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
id (str):
|
|
90
|
+
The unique identifier of the resource.
|
|
91
|
+
|
|
92
|
+
workspace (str):
|
|
93
|
+
Determines on which workspace the request will be made
|
|
94
|
+
|
|
95
|
+
**kwargs (dict):
|
|
96
|
+
Any additional keyword arguments to customize the request
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
object: A single resource of the class type.
|
|
100
|
+
"""
|
|
101
|
+
api_req = utils.create_api_requestor(kwargs)
|
|
102
|
+
url = f'{cls.class_url()}/{id}'
|
|
103
|
+
response = api_req.get(url, kwargs)
|
|
104
|
+
return utils.to_object(cls, kwargs, response)
|
|
105
|
+
|
|
106
|
+
###############################################################################
|
|
107
|
+
# Listable APIResource Implementation
|
|
108
|
+
###############################################################################
|
|
109
|
+
class ListableAPIResource(APIResource):
|
|
110
|
+
|
|
111
|
+
@classmethod
|
|
112
|
+
def list(cls, **kwargs):
|
|
113
|
+
"""
|
|
114
|
+
Retrieves a list of resources from the API.
|
|
115
|
+
This class method sends a GET request to the API to retrieve a list of resources of the specified class type.
|
|
116
|
+
Check https://everysk.com/api/docs/#list-all-portfolios for additional information
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
query (str, optional):
|
|
120
|
+
Request a list of portfolios fileting it by `name` or `tag`
|
|
121
|
+
|
|
122
|
+
workspace (str, optional):
|
|
123
|
+
Determines on which workspace the request will be made
|
|
124
|
+
|
|
125
|
+
page_size (int, optional):
|
|
126
|
+
Set the number of object that will be listed per page
|
|
127
|
+
|
|
128
|
+
page_token (int, optional):
|
|
129
|
+
This token defines which page will be returned to the user
|
|
130
|
+
|
|
131
|
+
**kwargs (dict):
|
|
132
|
+
Additional keyword arguments to customize the request
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
list: A list of resource of the class type.
|
|
136
|
+
"""
|
|
137
|
+
api_req = utils.create_api_requestor(kwargs)
|
|
138
|
+
url = cls.class_url()
|
|
139
|
+
response = api_req.get(url, kwargs)
|
|
140
|
+
return utils.to_list(cls, kwargs, response)
|
|
141
|
+
|
|
142
|
+
@classmethod
|
|
143
|
+
def auto_paging_iter(cls, **kwargs):
|
|
144
|
+
"""
|
|
145
|
+
Provides an iterator over all resources, handling pagination automatically.
|
|
146
|
+
This class method iterates over all resources of the specified class type, handling pagination automatically
|
|
147
|
+
to retrieve the complete list of resources. Check https://everysk.com/api/docs/#pagination for more information
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
page_size (int):
|
|
151
|
+
A limit on the number of objects to be returned, between 1 and 100
|
|
152
|
+
|
|
153
|
+
page_token (str):
|
|
154
|
+
Returns the previous page token
|
|
155
|
+
|
|
156
|
+
**kwargs (dict):
|
|
157
|
+
Additional keyword arguments to customize the request, such as filters or pagination parameters.
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
object: A resource of the class type.
|
|
161
|
+
"""
|
|
162
|
+
params = dict(kwargs)
|
|
163
|
+
page = cls.list(**params)
|
|
164
|
+
while True:
|
|
165
|
+
for item in page:
|
|
166
|
+
yield item
|
|
167
|
+
if page.next_page_token() is None:
|
|
168
|
+
return
|
|
169
|
+
params['page_token'] = page.next_page_token()
|
|
170
|
+
page = cls.list(**params)
|
|
171
|
+
|
|
172
|
+
###############################################################################
|
|
173
|
+
# Deletable APIResource Implementation
|
|
174
|
+
###############################################################################
|
|
175
|
+
class DeletableAPIResource(APIResource):
|
|
176
|
+
|
|
177
|
+
def delete(self):
|
|
178
|
+
"""
|
|
179
|
+
Deletes the current instance of the resource from the API
|
|
180
|
+
This class method sends a DELETE request to the API to delete the current instance.
|
|
181
|
+
|
|
182
|
+
Example:
|
|
183
|
+
>>> from everysk.api.api_resources.api_resource import DeletableAPIResource
|
|
184
|
+
>>> resource = DeletableAPIResource.retrieve("resource_id")
|
|
185
|
+
>>> resource.delete()
|
|
186
|
+
"""
|
|
187
|
+
api_req = utils.create_api_requestor()
|
|
188
|
+
url = f"{self.class_url()}/{self.get('id')}"
|
|
189
|
+
workspace = self.get('workspace', None)
|
|
190
|
+
if workspace:
|
|
191
|
+
url = f'{url}?workspace={workspace}'
|
|
192
|
+
response = api_req.delete(url)
|
|
193
|
+
data = response[self.class_name()]
|
|
194
|
+
self.clear()
|
|
195
|
+
self.update(data)
|
|
196
|
+
self.clear_unsaved_values()
|
|
197
|
+
return self
|
|
198
|
+
|
|
199
|
+
@classmethod
|
|
200
|
+
def remove(cls, id, **kwargs):
|
|
201
|
+
"""
|
|
202
|
+
Deletes a resource from the API by its ID.
|
|
203
|
+
Sends a DELETE request to the API to delete a resource of the specified class type
|
|
204
|
+
identified by the provided ID.
|
|
205
|
+
|
|
206
|
+
Args:
|
|
207
|
+
id: The unique identifier of the resource to be deleted.
|
|
208
|
+
|
|
209
|
+
workspace (str, optional):
|
|
210
|
+
Determines on which workspace the request will be made.
|
|
211
|
+
|
|
212
|
+
**kwargs (dict): Additional keyword arguments to customize the request.
|
|
213
|
+
|
|
214
|
+
Example:
|
|
215
|
+
>>> DeletableAPIResource.remove('resource_id')
|
|
216
|
+
Deleted resource_object
|
|
217
|
+
"""
|
|
218
|
+
api_req = utils.create_api_requestor()
|
|
219
|
+
url = f'{cls.class_url()}/{id}'
|
|
220
|
+
workspace = kwargs.get('workspace', None)
|
|
221
|
+
if workspace:
|
|
222
|
+
url = f'{url}?workspace={workspace}'
|
|
223
|
+
response = api_req.delete(url)
|
|
224
|
+
data = response[cls.class_name()]
|
|
225
|
+
return utils.to_object(cls, {}, response)
|
|
226
|
+
|
|
227
|
+
###############################################################################
|
|
228
|
+
# Creatable APIResource Implementation
|
|
229
|
+
###############################################################################
|
|
230
|
+
class CreateableAPIResource(APIResource):
|
|
231
|
+
|
|
232
|
+
@classmethod
|
|
233
|
+
def create(cls, **kwargs):
|
|
234
|
+
"""
|
|
235
|
+
Creates a new instance of the resource and saves it to the API.
|
|
236
|
+
This class method sends a POST request to the API to create a new instance of the resource with the provided data.
|
|
237
|
+
|
|
238
|
+
Args:
|
|
239
|
+
description (str, optional):
|
|
240
|
+
Provides detailed information about the resource
|
|
241
|
+
|
|
242
|
+
tags (list, optional):
|
|
243
|
+
Sequence of hashtags used to label the related resources. Any sequence of lowercase character, numbers, and underscore might be used.
|
|
244
|
+
|
|
245
|
+
date (str, optional):
|
|
246
|
+
Resource date in the following format: `YYYYMMDD`
|
|
247
|
+
|
|
248
|
+
workspace (str, optional):
|
|
249
|
+
Determines on which workspace the request will be made
|
|
250
|
+
|
|
251
|
+
**kwargs (dict):
|
|
252
|
+
Keyword arguments representing the data for creating the resource. Depending on the resource, each entity will have different kwargs.
|
|
253
|
+
|
|
254
|
+
Example:
|
|
255
|
+
>>> new_resource_data = {'name': 'New Resource'}
|
|
256
|
+
>>> new_resource = CreatableAPIResource.create(**new_resource_data)
|
|
257
|
+
>>> print(new_resource)
|
|
258
|
+
New resource_object
|
|
259
|
+
"""
|
|
260
|
+
api_req = utils.create_api_requestor(kwargs)
|
|
261
|
+
url = cls.class_url()
|
|
262
|
+
response = api_req.post(url, kwargs)
|
|
263
|
+
return utils.to_object(cls, kwargs, response)
|
|
264
|
+
|
|
265
|
+
###############################################################################
|
|
266
|
+
# Updatable APIResource Implementation
|
|
267
|
+
###############################################################################
|
|
268
|
+
class UpdateableAPIResource(APIResource):
|
|
269
|
+
|
|
270
|
+
@classmethod
|
|
271
|
+
def modify(cls, id, **kwargs):
|
|
272
|
+
"""
|
|
273
|
+
Modifies a resource by its ID with the provided data.
|
|
274
|
+
|
|
275
|
+
This class method sends a PUT request to the API to modify a resource of the specified class type
|
|
276
|
+
identified by the provided ID with the provided data.
|
|
277
|
+
|
|
278
|
+
Args:
|
|
279
|
+
id (str):
|
|
280
|
+
The unique identifier of the resource to be modified.
|
|
281
|
+
|
|
282
|
+
**kwargs (dict):
|
|
283
|
+
Keyword arguments representing the data to be updated. The kwargs will differ for each entity.
|
|
284
|
+
|
|
285
|
+
Example:
|
|
286
|
+
>>> updated_data = {'name': 'Updated Resource'}
|
|
287
|
+
>>> updated_resource = UpdateableAPIResource.modify('resource_id', **updated_data)
|
|
288
|
+
>>> print(updated_resource)
|
|
289
|
+
Updated resource_object
|
|
290
|
+
"""
|
|
291
|
+
api_req = utils.create_api_requestor(kwargs)
|
|
292
|
+
url = f'{cls.class_url()}/{id}'
|
|
293
|
+
response = api_req.put(url, kwargs)
|
|
294
|
+
data = response[cls.class_name()]
|
|
295
|
+
return utils.to_object(cls, kwargs, response)
|
|
296
|
+
|
|
297
|
+
def save(self, **kwargs):
|
|
298
|
+
"""
|
|
299
|
+
Saves the changes made to the current instance of the resource to the API.
|
|
300
|
+
This method sends a PUT request to the API to save the changes made to the current instance of the resource.
|
|
301
|
+
|
|
302
|
+
Args:
|
|
303
|
+
**kwargs (dict):
|
|
304
|
+
each entity will have different arguments for saving
|
|
305
|
+
|
|
306
|
+
Example:
|
|
307
|
+
>>> resource = UpdateableAPIResource.retrieve('resource_id')
|
|
308
|
+
>>> resource['name'] = 'Updated Name'
|
|
309
|
+
>>> resource.save()
|
|
310
|
+
Updated resource_object
|
|
311
|
+
"""
|
|
312
|
+
api_req = utils.create_api_requestor(kwargs)
|
|
313
|
+
url = f"{self.class_url()}/{self.get('id')}"
|
|
314
|
+
#response = api_req.put(url, self)
|
|
315
|
+
unsaved_values = self.get_unsaved_values()
|
|
316
|
+
response = api_req.put(url, unsaved_values)
|
|
317
|
+
data = response[self.class_name()]
|
|
318
|
+
self.update(data)
|
|
319
|
+
self.clear_unsaved_values()
|
|
320
|
+
return self
|
|
321
|
+
|
|
322
|
+
###############################################################################
|
|
323
|
+
# Filterable APIResource Implementation
|
|
324
|
+
###############################################################################
|
|
325
|
+
class FilterableAPIResource(APIResource):
|
|
326
|
+
|
|
327
|
+
@classmethod
|
|
328
|
+
def filter(cls,**kwargs):
|
|
329
|
+
"""
|
|
330
|
+
Filters resources based on the provided criteria.
|
|
331
|
+
|
|
332
|
+
This class method sends a POST request to the API to filter resources of the specified class type
|
|
333
|
+
based on the provided criteria.
|
|
334
|
+
|
|
335
|
+
Args:
|
|
336
|
+
limit (int, optional): The maximum number of resources to retrieve. Defaults to a predetermined limit if not specified.
|
|
337
|
+
|
|
338
|
+
tags (list[str], optional):
|
|
339
|
+
A list of strings representing tags used to filter resources. Tags should be a sequence
|
|
340
|
+
of lowercase characters, numbers, and underscores.
|
|
341
|
+
|
|
342
|
+
start (str, optional):
|
|
343
|
+
A start value used for filtering. The format and usage of this parameter can vary
|
|
344
|
+
depending on the resource type and should be a string or null.
|
|
345
|
+
|
|
346
|
+
end (str, optional):
|
|
347
|
+
An end value for filtering, similar in format and function to `start`. It should be a string or null.
|
|
348
|
+
|
|
349
|
+
date_time (str, optional):
|
|
350
|
+
A datetime string used for filtering resources. The expected format should be compliant
|
|
351
|
+
with the API's datetime format requirements.
|
|
352
|
+
|
|
353
|
+
link_uid (str, optional):
|
|
354
|
+
A unique identifier used to filter resources by their association to another entity.
|
|
355
|
+
|
|
356
|
+
**kwargs (dict):
|
|
357
|
+
Additional keyword arguments that represent other filtering criteria not explicitly listed. These should
|
|
358
|
+
align with the filterable fields of the resources.
|
|
359
|
+
|
|
360
|
+
Returns:
|
|
361
|
+
list: A list of filtered resources.
|
|
362
|
+
|
|
363
|
+
Example:
|
|
364
|
+
>>> filtered_resources = FilterableAPIResource.filter(param1=value1, param2=value2)
|
|
365
|
+
>>> print(filtered_resources)
|
|
366
|
+
[filtered_resource1, filtered_resource2, ...]
|
|
367
|
+
"""
|
|
368
|
+
api_req = utils.create_api_requestor(kwargs)
|
|
369
|
+
url = f'/{cls.class_name_list()}/filter'
|
|
370
|
+
response = api_req.post(url, kwargs)
|
|
371
|
+
return utils.to_list(cls, kwargs, response)
|