|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +# ----------------------------------------------------------------------------------- |
| 4 | +# <copyright company="Aspose Pty Ltd"> |
| 5 | +# Copyright (c) 2003-2019 Aspose Pty Ltd |
| 6 | +# </copyright> |
| 7 | +# <summary> |
| 8 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | +# of this software and associated documentation files (the "Software"), to deal |
| 10 | +# in the Software without restriction, including without limitation the rights |
| 11 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | +# copies of the Software, and to permit persons to whom the Software is |
| 13 | +# furnished to do so, subject to the following conditions: |
| 14 | +# |
| 15 | +# The above copyright notice and this permission notice shall be included in all |
| 16 | +# copies or substantial portions of the Software. |
| 17 | +# |
| 18 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | +# SOFTWARE. |
| 25 | +# </summary> |
| 26 | +# ----------------------------------------------------------------------------------- |
| 27 | + |
| 28 | +from __future__ import absolute_import |
| 29 | + |
| 30 | +import re # noqa: F401 |
| 31 | + |
| 32 | +# python 2 and python 3 compatibility library |
| 33 | +import six |
| 34 | + |
| 35 | +from groupdocs_conversion_cloud.auth import Auth |
| 36 | +from groupdocs_conversion_cloud.api_client import ApiClient |
| 37 | +from groupdocs_conversion_cloud.api_exception import ApiException |
| 38 | +from groupdocs_conversion_cloud.configuration import Configuration |
| 39 | + |
| 40 | +class ConvertApi(object): |
| 41 | + """ |
| 42 | + GroupDocs.Conversion Cloud API |
| 43 | +
|
| 44 | + :param configuration: API configuration |
| 45 | + """ |
| 46 | + |
| 47 | + def __init__(self, configuration): |
| 48 | + api_client = ApiClient(configuration) |
| 49 | + |
| 50 | + self.auth = Auth(configuration, api_client) |
| 51 | + self.api_client = api_client |
| 52 | + self.configuration = configuration |
| 53 | + |
| 54 | + def close(self): # noqa: E501 |
| 55 | + """ |
| 56 | + Closes thread pool. This method should be called when |
| 57 | + methods are executed asynchronously (is_async=True is passed as parameter) |
| 58 | + and this instance of ConvertApi is not going to be used any more. |
| 59 | + """ |
| 60 | + if self.api_client is not None: |
| 61 | + if(self.api_client.pool is not None): |
| 62 | + self.api_client.pool.close() |
| 63 | + self.api_client.pool.join() |
| 64 | + self.api_client.pool = None |
| 65 | + |
| 66 | + @classmethod |
| 67 | + def from_keys(cls, app_sid, app_key): |
| 68 | + """ |
| 69 | + Initializes new instance of ConvertApi with API keys |
| 70 | +
|
| 71 | + :param app_sid Application identifier (App SID) |
| 72 | + :param app_key Application private key (App Key) |
| 73 | + """ |
| 74 | + configuration = Configuration(app_sid, app_key) |
| 75 | + return ConvertApi(configuration) |
| 76 | + |
| 77 | + @classmethod |
| 78 | + def from_config(cls, configuration): |
| 79 | + """ |
| 80 | + Initializes new instance of ConvertApi with configuration options |
| 81 | +
|
| 82 | + :param configuration API configuration |
| 83 | + """ |
| 84 | + return ConvertApi(configuration) |
| 85 | + |
| 86 | + def convert_document(self, request,**kwargs): # noqa: E501 |
| 87 | + """Converts specified input document to format specified in the convertSettings with specified options # noqa: E501 |
| 88 | +
|
| 89 | + This method makes a synchronous HTTP request by default. To make an |
| 90 | + asynchronous HTTP request, please pass is_async=True |
| 91 | +
|
| 92 | + :param is_async bool |
| 93 | + :param ConvertSettings convert_settings: (required) |
| 94 | + :return: list[StoredConvertedResult] |
| 95 | + If the method is called asynchronously, |
| 96 | + returns the request thread. |
| 97 | + """ |
| 98 | + kwargs['_return_http_data_only'] = True |
| 99 | + |
| 100 | + if kwargs.get('is_async'): |
| 101 | + return self._convert_document_with_http_info(request, **kwargs) # noqa: E501 |
| 102 | + |
| 103 | + (data) = self._convert_document_with_http_info(request, **kwargs) # noqa: E501 |
| 104 | + return data |
| 105 | + |
| 106 | + def _convert_document_with_http_info(self, request, **kwargs): # noqa: E501 |
| 107 | + """Converts specified input document to format specified in the convertSettings with specified options # noqa: E501 |
| 108 | +
|
| 109 | + This method makes a synchronous HTTP request by default. To make an |
| 110 | + asynchronous HTTP request, please pass is_async=True |
| 111 | +
|
| 112 | + :param is_async bool |
| 113 | + :param ConvertDocumentRequest request object with parameters |
| 114 | + :return: list[StoredConvertedResult] |
| 115 | + If the method is called asynchronously, |
| 116 | + returns the request thread. |
| 117 | + """ |
| 118 | + params = locals() |
| 119 | + params['is_async'] = '' |
| 120 | + params['_return_http_data_only'] = False |
| 121 | + params['_preload_content'] = True |
| 122 | + params['_request_timeout'] = '' |
| 123 | + for key, val in six.iteritems(params['kwargs']): |
| 124 | + if key not in params: |
| 125 | + raise TypeError( |
| 126 | + "Got an unexpected keyword argument '%s'" |
| 127 | + " to method convert_document" % key |
| 128 | + ) |
| 129 | + params[key] = val |
| 130 | + del params['kwargs'] |
| 131 | + # verify the required parameter 'convert_settings' is set |
| 132 | + if request.convert_settings is None: |
| 133 | + raise ValueError("Missing the required parameter `convert_settings` when calling `convert_document`") # noqa: E501 |
| 134 | + |
| 135 | + collection_formats = {} |
| 136 | + path = '/conversion' |
| 137 | + path_params = {} |
| 138 | + |
| 139 | + query_params = [] |
| 140 | + |
| 141 | + header_params = {} |
| 142 | + |
| 143 | + form_params = [] |
| 144 | + local_var_files = [] |
| 145 | + |
| 146 | + body_params = None |
| 147 | + if request.convert_settings is not None: |
| 148 | + body_params = request.convert_settings |
| 149 | + # HTTP header `Accept` |
| 150 | + header_params['Accept'] = self.api_client.select_header_accept( |
| 151 | + ['application/json']) # noqa: E501 |
| 152 | + |
| 153 | + # HTTP header `Content-Type` |
| 154 | + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 |
| 155 | + ['application/json']) # noqa: E501 |
| 156 | + |
| 157 | + call_kwargs = { |
| 158 | + 'resource_path':path, |
| 159 | + 'method':'POST', |
| 160 | + 'path_params':path_params, |
| 161 | + 'query_params':query_params, |
| 162 | + 'header_params':header_params, |
| 163 | + 'body':body_params, |
| 164 | + 'post_params':form_params, |
| 165 | + 'files':local_var_files, |
| 166 | + 'response_type':'list[StoredConvertedResult]', # noqa: E501 |
| 167 | + 'auth_settings':self.auth.get_auth_settings(), |
| 168 | + 'is_async':params.get('is_async'), |
| 169 | + '_return_http_data_only':params.get('_return_http_data_only'), |
| 170 | + '_preload_content':params.get('_preload_content', True), |
| 171 | + '_request_timeout':params.get('_request_timeout'), |
| 172 | + 'collection_formats':collection_formats |
| 173 | + } |
| 174 | + |
| 175 | + return self.api_client.call_api(**call_kwargs) # noqa: E501 |
| 176 | + |
| 177 | + def convert_document_download(self, request,**kwargs): # noqa: E501 |
| 178 | + """Converts specified input document to format specified in the convertSettings with specified options # noqa: E501 |
| 179 | +
|
| 180 | + This method makes a synchronous HTTP request by default. To make an |
| 181 | + asynchronous HTTP request, please pass is_async=True |
| 182 | +
|
| 183 | + :param is_async bool |
| 184 | + :param ConvertSettings convert_settings: (required) |
| 185 | + :return: file |
| 186 | + If the method is called asynchronously, |
| 187 | + returns the request thread. |
| 188 | + """ |
| 189 | + kwargs['_return_http_data_only'] = True |
| 190 | + |
| 191 | + if kwargs.get('is_async'): |
| 192 | + return self._convert_document_download_with_http_info(request, **kwargs) # noqa: E501 |
| 193 | + |
| 194 | + (data) = self._convert_document_download_with_http_info(request, **kwargs) # noqa: E501 |
| 195 | + return data |
| 196 | + |
| 197 | + def _convert_document_download_with_http_info(self, request, **kwargs): # noqa: E501 |
| 198 | + """Converts specified input document to format specified in the convertSettings with specified options # noqa: E501 |
| 199 | +
|
| 200 | + This method makes a synchronous HTTP request by default. To make an |
| 201 | + asynchronous HTTP request, please pass is_async=True |
| 202 | +
|
| 203 | + :param is_async bool |
| 204 | + :param ConvertDocumentRequest request object with parameters |
| 205 | + :return: list[StoredConvertedResult] |
| 206 | + If the method is called asynchronously, |
| 207 | + returns the request thread. |
| 208 | + """ |
| 209 | + params = locals() |
| 210 | + params['is_async'] = '' |
| 211 | + params['_return_http_data_only'] = False |
| 212 | + params['_preload_content'] = True |
| 213 | + params['_request_timeout'] = '' |
| 214 | + for key, val in six.iteritems(params['kwargs']): |
| 215 | + if key not in params: |
| 216 | + raise TypeError( |
| 217 | + "Got an unexpected keyword argument '%s'" |
| 218 | + " to method convert_document" % key |
| 219 | + ) |
| 220 | + params[key] = val |
| 221 | + del params['kwargs'] |
| 222 | + # verify the required parameter 'convert_settings' is set |
| 223 | + if request.convert_settings is None: |
| 224 | + raise ValueError("Missing the required parameter `convert_settings` when calling `convert_document`") # noqa: E501 |
| 225 | + |
| 226 | + collection_formats = {} |
| 227 | + path = '/conversion' |
| 228 | + path_params = {} |
| 229 | + |
| 230 | + query_params = [] |
| 231 | + |
| 232 | + header_params = {} |
| 233 | + |
| 234 | + form_params = [] |
| 235 | + local_var_files = [] |
| 236 | + |
| 237 | + body_params = None |
| 238 | + if request.convert_settings is not None: |
| 239 | + body_params = request.convert_settings |
| 240 | + # HTTP header `Accept` |
| 241 | + header_params['Accept'] = self.api_client.select_header_accept( |
| 242 | + ['application/json']) # noqa: E501 |
| 243 | + |
| 244 | + # HTTP header `Content-Type` |
| 245 | + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 |
| 246 | + ['application/json']) # noqa: E501 |
| 247 | + |
| 248 | + call_kwargs = { |
| 249 | + 'resource_path':path, |
| 250 | + 'method':'POST', |
| 251 | + 'path_params':path_params, |
| 252 | + 'query_params':query_params, |
| 253 | + 'header_params':header_params, |
| 254 | + 'body':body_params, |
| 255 | + 'post_params':form_params, |
| 256 | + 'files':local_var_files, |
| 257 | + 'response_type':'file', # noqa: E501 |
| 258 | + 'auth_settings':self.auth.get_auth_settings(), |
| 259 | + 'is_async':params.get('is_async'), |
| 260 | + '_return_http_data_only':params.get('_return_http_data_only'), |
| 261 | + '_preload_content':params.get('_preload_content', True), |
| 262 | + '_request_timeout':params.get('_request_timeout'), |
| 263 | + 'collection_formats':collection_formats |
| 264 | + } |
| 265 | + |
| 266 | + return self.api_client.call_api(**call_kwargs) # noqa: E501 |
| 267 | + |
| 268 | + def __downcase_first_letter(self, s): |
| 269 | + if len(s) == 0: |
| 270 | + return str |
| 271 | + else: |
| 272 | + return s[0].lower() + s[1:] |
| 273 | + |
| 274 | +# coding: utf-8 |
| 275 | + |
| 276 | +# -------------------------------------------------------------------------------- |
| 277 | +# <copyright company="Aspose Pty Ltd" file="convert_document_request.py"> |
| 278 | +# Copyright (c) 2003-2019 Aspose Pty Ltd |
| 279 | +# </copyright> |
| 280 | +# <summary> |
| 281 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 282 | +# of this software and associated documentation files (the "Software"), to deal |
| 283 | +# in the Software without restriction, including without limitation the rights |
| 284 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 285 | +# copies of the Software, and to permit persons to whom the Software is |
| 286 | +# furnished to do so, subject to the following conditions: |
| 287 | +# |
| 288 | +# The above copyright notice and this permission notice shall be included in all |
| 289 | +# copies or substantial portions of the Software. |
| 290 | +# |
| 291 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 292 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 293 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 294 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 295 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 296 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 297 | +# SOFTWARE. |
| 298 | +# </summary> |
| 299 | +# -------------------------------------------------------------------------------- |
| 300 | + |
| 301 | +class ConvertDocumentRequest(object): |
| 302 | + """ |
| 303 | + Request model for convert_document operation. |
| 304 | + :param convert_settings |
| 305 | + """ |
| 306 | + |
| 307 | + def __init__(self, convert_settings): |
| 308 | + """Initializes new instance of ConvertDocumentRequest.""" # noqa: E501 |
| 309 | + self.convert_settings = convert_settings |
0 commit comments