|
| 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