|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * -------------------------------------------------------------------------------- |
| 4 | + * <copyright company="Aspose" file="TranslateNodeIdOnlineRequest.php"> |
| 5 | + * Copyright (c) 2024 Aspose.Words for Cloud |
| 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 | + |
| 29 | +namespace Aspose\Words\Model\Requests; |
| 30 | + |
| 31 | +use GuzzleHttp\Client; |
| 32 | +use GuzzleHttp\ClientInterface; |
| 33 | +use GuzzleHttp\Exception\RequestException; |
| 34 | +use GuzzleHttp\Psr7\MultipartStream; |
| 35 | +use GuzzleHttp\Psr7\Request; |
| 36 | +use GuzzleHttp\RequestOptions; |
| 37 | +use Aspose\Words\ObjectSerializer; |
| 38 | +use Aspose\Words\HeaderSelector; |
| 39 | +use Aspose\Words\Model\Response\TranslateNodeIdOnlineResponse; |
| 40 | +use Aspose\Words\Encryptor; |
| 41 | + |
| 42 | +/* |
| 43 | + * Request model for translateNodeIdOnline operation. |
| 44 | + */ |
| 45 | +class TranslateNodeIdOnlineRequest extends BaseApiRequest |
| 46 | +{ |
| 47 | + /* |
| 48 | + * The document. |
| 49 | + */ |
| 50 | + public $document; |
| 51 | + |
| 52 | + /* |
| 53 | + * The node identifier. Identifier examples: id0.0.0. |
| 54 | + */ |
| 55 | + public $node_id; |
| 56 | + |
| 57 | + /* |
| 58 | + * Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML. |
| 59 | + */ |
| 60 | + public $load_encoding; |
| 61 | + |
| 62 | + /* |
| 63 | + * Password of protected Word document. Use the parameter to pass a password via SDK. SDK encrypts it automatically. We don't recommend to use the parameter to pass a plain password for direct call of API. |
| 64 | + */ |
| 65 | + public $password; |
| 66 | + |
| 67 | + /* |
| 68 | + * Password of protected Word document. Use the parameter to pass an encrypted password for direct calls of API. See SDK code for encyption details. |
| 69 | + */ |
| 70 | + public $encrypted_password; |
| 71 | + |
| 72 | + /* |
| 73 | + * Initializes a new instance of the TranslateNodeIdOnlineRequest class. |
| 74 | + * |
| 75 | + * @param \SplFileObject $document The document. |
| 76 | + * @param string $node_id The node identifier. Identifier examples: id0.0.0. |
| 77 | + * @param string $load_encoding Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML. |
| 78 | + * @param string $password Password of protected Word document. Use the parameter to pass a password via SDK. SDK encrypts it automatically. We don't recommend to use the parameter to pass a plain password for direct call of API. |
| 79 | + * @param string $encrypted_password Password of protected Word document. Use the parameter to pass an encrypted password for direct calls of API. See SDK code for encyption details. |
| 80 | + */ |
| 81 | + public function __construct($document, $node_id, $load_encoding = null, $password = null, $encrypted_password = null) |
| 82 | + { |
| 83 | + $this->document = $document; |
| 84 | + $this->node_id = $node_id; |
| 85 | + $this->load_encoding = $load_encoding; |
| 86 | + $this->password = $password; |
| 87 | + $this->encrypted_password = $encrypted_password; |
| 88 | + } |
| 89 | + |
| 90 | + /* |
| 91 | + * The document. |
| 92 | + */ |
| 93 | + public function get_document() |
| 94 | + { |
| 95 | + return $this->document; |
| 96 | + } |
| 97 | + |
| 98 | + /* |
| 99 | + * The document. |
| 100 | + */ |
| 101 | + public function set_document($value) |
| 102 | + { |
| 103 | + $this->document = $value; |
| 104 | + return $this; |
| 105 | + } |
| 106 | + |
| 107 | + /* |
| 108 | + * The node identifier. Identifier examples: id0.0.0. |
| 109 | + */ |
| 110 | + public function get_node_id() |
| 111 | + { |
| 112 | + return $this->node_id; |
| 113 | + } |
| 114 | + |
| 115 | + /* |
| 116 | + * The node identifier. Identifier examples: id0.0.0. |
| 117 | + */ |
| 118 | + public function set_node_id($value) |
| 119 | + { |
| 120 | + $this->node_id = $value; |
| 121 | + return $this; |
| 122 | + } |
| 123 | + |
| 124 | + /* |
| 125 | + * Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML. |
| 126 | + */ |
| 127 | + public function get_load_encoding() |
| 128 | + { |
| 129 | + return $this->load_encoding; |
| 130 | + } |
| 131 | + |
| 132 | + /* |
| 133 | + * Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML. |
| 134 | + */ |
| 135 | + public function set_load_encoding($value) |
| 136 | + { |
| 137 | + $this->load_encoding = $value; |
| 138 | + return $this; |
| 139 | + } |
| 140 | + |
| 141 | + /* |
| 142 | + * Password of protected Word document. Use the parameter to pass a password via SDK. SDK encrypts it automatically. We don't recommend to use the parameter to pass a plain password for direct call of API. |
| 143 | + */ |
| 144 | + public function get_password() |
| 145 | + { |
| 146 | + return $this->password; |
| 147 | + } |
| 148 | + |
| 149 | + /* |
| 150 | + * Password of protected Word document. Use the parameter to pass a password via SDK. SDK encrypts it automatically. We don't recommend to use the parameter to pass a plain password for direct call of API. |
| 151 | + */ |
| 152 | + public function set_password($value) |
| 153 | + { |
| 154 | + $this->password = $value; |
| 155 | + return $this; |
| 156 | + } |
| 157 | + |
| 158 | + /* |
| 159 | + * Password of protected Word document. Use the parameter to pass an encrypted password for direct calls of API. See SDK code for encyption details. |
| 160 | + */ |
| 161 | + public function get_encrypted_password() |
| 162 | + { |
| 163 | + return $this->encrypted_password; |
| 164 | + } |
| 165 | + |
| 166 | + /* |
| 167 | + * Password of protected Word document. Use the parameter to pass an encrypted password for direct calls of API. See SDK code for encyption details. |
| 168 | + */ |
| 169 | + public function set_encrypted_password($value) |
| 170 | + { |
| 171 | + $this->encrypted_password = $value; |
| 172 | + return $this; |
| 173 | + } |
| 174 | + |
| 175 | + /* |
| 176 | + * Create request data for operation 'translateNodeIdOnline' |
| 177 | + * |
| 178 | + * @throws \InvalidArgumentException |
| 179 | + * @return \GuzzleHttp\Psr7\Request |
| 180 | + */ |
| 181 | + public function createRequestData($config) |
| 182 | + { |
| 183 | + if ($this->document === null) { |
| 184 | + throw new \InvalidArgumentException('Missing the required parameter $document when calling translateNodeIdOnline'); |
| 185 | + } |
| 186 | + if ($this->node_id === null) { |
| 187 | + throw new \InvalidArgumentException('Missing the required parameter $node_id when calling translateNodeIdOnline'); |
| 188 | + } |
| 189 | + |
| 190 | + $resourcePath = '/words/online/get/translate/{nodeId}'; |
| 191 | + $formParams = []; |
| 192 | + $filesContent = []; |
| 193 | + $queryParams = []; |
| 194 | + $headerParams = []; |
| 195 | + $httpBody = ""; |
| 196 | + $filename = null; |
| 197 | + // path params |
| 198 | + if ($this->node_id !== null) { |
| 199 | + $localName = lcfirst('NodeId'); |
| 200 | + $resourcePath = str_replace('{' . $localName . '}', ObjectSerializer::toPathValue($this->node_id), $resourcePath); |
| 201 | + } |
| 202 | + else { |
| 203 | + $localName = lcfirst('NodeId'); |
| 204 | + $resourcePath = str_replace('{' . $localName . '}', '', $resourcePath); |
| 205 | + } |
| 206 | + |
| 207 | + // remove empty path parameters |
| 208 | + $resourcePath = str_replace("//", "/", $resourcePath); |
| 209 | + // query params |
| 210 | + if ($this->load_encoding !== null) { |
| 211 | + $localName = lcfirst('LoadEncoding'); |
| 212 | + $localValue = is_bool($this->load_encoding) ? ($this->load_encoding ? 'true' : 'false') : $this->load_encoding; |
| 213 | + if (strpos($resourcePath, '{' . $localName . '}') !== false) { |
| 214 | + $resourcePath = str_replace('{' . $localName . '}', ObjectSerializer::toQueryValue($localValue), $resourcePath); |
| 215 | + } else { |
| 216 | + $queryParams[$localName] = ObjectSerializer::toQueryValue($localValue); |
| 217 | + } |
| 218 | + } |
| 219 | + // query params |
| 220 | + if ($this->password !== null) { |
| 221 | + $localName = lcfirst('Password'); |
| 222 | + $localValue = is_bool($this->password) ? ($this->password ? 'true' : 'false') : $this->password; |
| 223 | + if (strpos($resourcePath, '{' . $localName . '}') !== false) { |
| 224 | + $resourcePath = str_replace('{' . $localName . '}', ObjectSerializer::toQueryValue($localValue), $resourcePath); |
| 225 | + } else { |
| 226 | + $queryParams[$localName] = ObjectSerializer::toQueryValue($localValue); |
| 227 | + } |
| 228 | + } |
| 229 | + // query params |
| 230 | + if ($this->encrypted_password !== null) { |
| 231 | + $localName = lcfirst('EncryptedPassword'); |
| 232 | + $localValue = is_bool($this->encrypted_password) ? ($this->encrypted_password ? 'true' : 'false') : $this->encrypted_password; |
| 233 | + if (strpos($resourcePath, '{' . $localName . '}') !== false) { |
| 234 | + $resourcePath = str_replace('{' . $localName . '}', ObjectSerializer::toQueryValue($localValue), $resourcePath); |
| 235 | + } else { |
| 236 | + $queryParams[$localName] = ObjectSerializer::toQueryValue($localValue); |
| 237 | + } |
| 238 | + } |
| 239 | + if (property_exists($this, 'password') && $this->password != null) |
| 240 | + { |
| 241 | + unset($queryParams['password']); |
| 242 | + $queryParams['encryptedPassword'] = $config->getEncryptor()->encrypt($this->password); |
| 243 | + } |
| 244 | + |
| 245 | + $resourcePath = ObjectSerializer::parseURL($config, $resourcePath, $queryParams); |
| 246 | + // form params |
| 247 | + if ($this->document !== null) { |
| 248 | + $filename = ObjectSerializer::toFormValue($this->document); |
| 249 | + $handle = fopen($filename, "rb"); |
| 250 | + $fsize = filesize($filename); |
| 251 | + $contents = fread($handle, $fsize); |
| 252 | + array_push($formParams, ['name' => 'Document', 'content' => $contents, 'mime' => 'application/octet-stream']); |
| 253 | + } |
| 254 | + |
| 255 | + foreach ($filesContent as $fileContent) |
| 256 | + { |
| 257 | + $fileContent->encryptPassword($config->getEncryptor()); |
| 258 | + if ($fileContent->getSource() == 'Request') { |
| 259 | + $filesContent_filename = ObjectSerializer::toFormValue($fileContent->getContent()); |
| 260 | + $filesContent_handle = fopen($filesContent_filename, "rb"); |
| 261 | + $filesContent_fsize = filesize($filesContent_filename); |
| 262 | + $filesContent_contents = fread($filesContent_handle, $filesContent_fsize); |
| 263 | + array_push($formParams, ['name' => $fileContent->getReference(), 'content' => $filesContent_contents, 'mime' => 'application/octet-stream']); |
| 264 | + } |
| 265 | + } |
| 266 | + |
| 267 | + // body params |
| 268 | + $_tempBody = null; |
| 269 | + if (count($formParams) == 1) { |
| 270 | + $_tempBody = array_shift($formParams); |
| 271 | + } |
| 272 | + |
| 273 | + $headerParams = []; |
| 274 | + // for model (json/xml) |
| 275 | + if (isset($_tempBody)) { |
| 276 | + $headerParams['Content-Type'] = $_tempBody['mime']; |
| 277 | + if ($_tempBody['mime'] == 'application/json') { |
| 278 | + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody['content'])); |
| 279 | + } else { |
| 280 | + $httpBody = ObjectSerializer::sanitizeForSerialization($_tempBody['content']); |
| 281 | + } |
| 282 | + } elseif (count($formParams) > 1) { |
| 283 | + $multipartContents = []; |
| 284 | + foreach ($formParams as $formParam) { |
| 285 | + $multipartContents[] = [ |
| 286 | + 'name' => $formParam['name'], |
| 287 | + 'contents' => $formParam['content'], |
| 288 | + 'headers' => ['Content-Type' => $formParam['mime']] |
| 289 | + ]; |
| 290 | + } |
| 291 | + // for HTTP post (form) |
| 292 | + $httpBody = new MultipartStream($multipartContents); |
| 293 | + $headerParams['Content-Type'] = "multipart/form-data; boundary=" . $httpBody->getBoundary(); |
| 294 | + } |
| 295 | + |
| 296 | + $result = array(); |
| 297 | + $result['method'] = 'PUT'; |
| 298 | + $result['url'] = $resourcePath; |
| 299 | + $result['headers'] = $headerParams; |
| 300 | + $result['body'] = $httpBody; |
| 301 | + return $result; |
| 302 | + } |
| 303 | + |
| 304 | + /* |
| 305 | + * Create request for operation 'translateNodeIdOnline' |
| 306 | + * |
| 307 | + * @throws \InvalidArgumentException |
| 308 | + * @return \GuzzleHttp\Psr7\Request |
| 309 | + */ |
| 310 | + public function createRequest($config) |
| 311 | + { |
| 312 | + $reqdata = $this->createRequestData($config); |
| 313 | + $defaultHeaders = []; |
| 314 | + |
| 315 | + if ($config->getAccessToken() !== null) { |
| 316 | + $defaultHeaders['Authorization'] = 'Bearer ' . $config->getAccessToken(); |
| 317 | + } |
| 318 | + |
| 319 | + if ($config->getUserAgent()) { |
| 320 | + $defaultHeaders['x-aspose-client'] = $config->getUserAgent(); |
| 321 | + } |
| 322 | + |
| 323 | + $defaultHeaders['x-aspose-client-version'] = $config->getClientVersion(); |
| 324 | + |
| 325 | + $reqdata['headers'] = array_merge($defaultHeaders, $reqdata['headers']); |
| 326 | + $req = new Request( |
| 327 | + $reqdata['method'], |
| 328 | + $reqdata['url'], |
| 329 | + $reqdata['headers'], |
| 330 | + $reqdata['body'] |
| 331 | + ); |
| 332 | + |
| 333 | + if ($config->getDebug()) { |
| 334 | + $this->_writeRequestLog($reqdata['method'], $reqdata['url'], $reqdata['headers'], $reqdata['body']); |
| 335 | + } |
| 336 | + |
| 337 | + return $req; |
| 338 | + } |
| 339 | + |
| 340 | + /* |
| 341 | + * Gets response type of this request. |
| 342 | + */ |
| 343 | + public function getResponseType() |
| 344 | + { |
| 345 | + return '\Aspose\Words\Model\TranslateNodeIdResponse'; |
| 346 | + } |
| 347 | + |
| 348 | + public function deserializeResponse($response) |
| 349 | + { |
| 350 | + return ObjectSerializer::deserialize($response, '\Aspose\Words\Model\TranslateNodeIdResponse', $response->getHeaders()); |
| 351 | + } |
| 352 | +} |
0 commit comments