Skip to content

Commit a2ad3eb

Browse files
committed
feat: support core sdk
1 parent ea0195f commit a2ad3eb

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-2
lines changed

volcenginesdkcore/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
from volcenginesdkcore.configuration import Configuration
44
from volcenginesdkcore.api_client import ApiClient
5+
from volcenginesdkcore.universal import UniversalApi, UniversalInfo

volcenginesdkcore/api_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,13 @@ def __call_api(
122122
quote(str(v), safe=config.safe_chars_for_path_param)
123123
)
124124

125+
# request module name
126+
md = ""
127+
125128
# body
126129
if body:
130+
if type(body) is not dict:
131+
md = body.__module__.split(".")[0]
127132
body = self.sanitize_for_serialization(body)
128133

129134
# query parameters
@@ -187,7 +192,7 @@ def _build_query(prefix, querys): # prefix is string and querys is a dict
187192
if _preload_content:
188193
# deserialize response data
189194
if response_type:
190-
return_data = self.deserialize(response_data, response_type, service)
195+
return_data = self.deserialize(response_data, response_type, md)
191196
else:
192197
return_data = None
193198

@@ -299,7 +304,7 @@ def __deserialize(self, data, klass, service):
299304
klass = self.NATIVE_TYPES_MAPPING[klass]
300305
else:
301306
# black box for dynamic get models type
302-
klass = getattr(__import__("volcenginesdk" + service.replace("_", "") + ".models"), klass)
307+
klass = getattr(__import__(service + ".models"), klass)
303308

304309
if klass in self.PRIMITIVE_TYPES:
305310
return self.__deserialize_primitive(data, klass)

volcenginesdkcore/universal.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# coding: utf-8
2+
3+
from volcenginesdkcore import ApiClient
4+
import six
5+
6+
7+
class UniversalInfo(object):
8+
def __init__(self, method=None, service=None, version=None, action=None):
9+
self.method = method
10+
self.service = service
11+
self.version = version
12+
self.action = action
13+
14+
15+
class UniversalApi(object):
16+
17+
def __init__(self, api_client=None):
18+
if api_client is None:
19+
api_client = ApiClient()
20+
self.api_client = api_client
21+
22+
def do_call(self, info, body, **kwargs): # noqa: E501
23+
kwargs['_return_http_data_only'] = True
24+
if kwargs.get('async_req'):
25+
return self.do_call_with_http_info(info, body, **kwargs) # noqa: E501
26+
else:
27+
(data) = self.do_call_with_http_info(info, body, **kwargs) # noqa: E501
28+
return data
29+
30+
def do_call_with_http_info(self, info, body, **kwargs): # noqa: E501
31+
all_params = ['body', 'async_req', '_return_http_data_only', '_preload_content',
32+
'_request_timeout'] # noqa: E501
33+
34+
params = locals()
35+
for key, val in six.iteritems(params['kwargs']):
36+
if key not in all_params:
37+
raise TypeError(
38+
"Got an unexpected keyword argument '%s'"
39+
" to method do_call" % key
40+
)
41+
params[key] = val
42+
del params['kwargs']
43+
44+
# verify the required parameter 'body' is set
45+
if self.api_client.client_side_validation and ('body' not in params or
46+
params['body'] is None): # noqa: E501
47+
raise ValueError(
48+
"Missing the required parameter `body` when calling `do_call`") # noqa: E501
49+
50+
if type(params['body']) is not dict:
51+
raise ValueError(
52+
"The required parameter `body` must be dict") # noqa: E501
53+
54+
collection_formats = {}
55+
56+
path_params = {}
57+
58+
query_params = []
59+
60+
header_params = {}
61+
62+
form_params = []
63+
local_var_files = {}
64+
65+
body_params = None
66+
if 'body' in params:
67+
body_params = params['body']
68+
69+
# HTTP header `Accept`
70+
header_params['Accept'] = self.api_client.select_header_accept(
71+
['application/json']) # noqa: E501
72+
73+
# HTTP header `Content-Type`
74+
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
75+
['text/plain']) # noqa: E501
76+
77+
if info.method.lower() != "get":
78+
header_params['Content-Type'] = 'application/json' # noqa: E501
79+
80+
# Authentication setting
81+
auth_settings = ['volcengineSign'] # noqa: E501
82+
83+
path = '/' + info.action + '/' + info.version + '/' + info.service + '/' + info.method.lower() + '/'
84+
return self.api_client.call_api(
85+
path, info.method.upper(),
86+
path_params,
87+
query_params,
88+
header_params,
89+
body=body_params,
90+
post_params=form_params,
91+
files=local_var_files,
92+
response_type=object, # noqa: E501
93+
auth_settings=auth_settings,
94+
async_req=params.get('async_req'),
95+
_return_http_data_only=params.get('_return_http_data_only'),
96+
_preload_content=params.get('_preload_content', True),
97+
_request_timeout=params.get('_request_timeout'),
98+
collection_formats=collection_formats)

0 commit comments

Comments
 (0)