|
| 1 | +/* |
| 2 | + * -------------------------------------------------------------------------------- |
| 3 | + * <copyright company="Aspose" file="TranslateNodeIdOnlineRequest.swift"> |
| 4 | + * Copyright (c) 2024 Aspose.Words for Cloud |
| 5 | + * </copyright> |
| 6 | + * <summary> |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in all |
| 15 | + * copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | + * SOFTWARE. |
| 24 | + * </summary> |
| 25 | + * -------------------------------------------------------------------------------- |
| 26 | + */ |
| 27 | + |
| 28 | +import Foundation |
| 29 | + |
| 30 | +// Request model for translateNodeIdOnline operation. |
| 31 | +@available(macOS 10.12, iOS 10.3, watchOS 3.3, tvOS 12.0, *) |
| 32 | +public class TranslateNodeIdOnlineRequest : WordsApiRequest { |
| 33 | + private let document : InputStream; |
| 34 | + private let nodeId : String; |
| 35 | + private let loadEncoding : String?; |
| 36 | + private let password : String?; |
| 37 | + private let encryptedPassword : String?; |
| 38 | + |
| 39 | + private enum CodingKeys: String, CodingKey { |
| 40 | + case document; |
| 41 | + case nodeId; |
| 42 | + case loadEncoding; |
| 43 | + case password; |
| 44 | + case encryptedPassword; |
| 45 | + case invalidCodingKey; |
| 46 | + } |
| 47 | + |
| 48 | + // Initializes a new instance of the TranslateNodeIdOnlineRequest class. |
| 49 | + public init(document : InputStream, nodeId : String, loadEncoding : String? = nil, password : String? = nil, encryptedPassword : String? = nil) { |
| 50 | + self.document = document; |
| 51 | + self.nodeId = nodeId; |
| 52 | + self.loadEncoding = loadEncoding; |
| 53 | + self.password = password; |
| 54 | + self.encryptedPassword = encryptedPassword; |
| 55 | + } |
| 56 | + |
| 57 | + // The document. |
| 58 | + public func getDocument() -> InputStream { |
| 59 | + return self.document; |
| 60 | + } |
| 61 | + |
| 62 | + // The node identifier. Identifier examples: id0.0.0. |
| 63 | + public func getNodeId() -> String { |
| 64 | + return self.nodeId; |
| 65 | + } |
| 66 | + |
| 67 | + // Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML. |
| 68 | + public func getLoadEncoding() -> String? { |
| 69 | + return self.loadEncoding; |
| 70 | + } |
| 71 | + |
| 72 | + // 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. |
| 73 | + public func getPassword() -> String? { |
| 74 | + return self.password; |
| 75 | + } |
| 76 | + |
| 77 | + // Password of protected Word document. Use the parameter to pass an encrypted password for direct calls of API. See SDK code for encyption details. |
| 78 | + public func getEncryptedPassword() -> String? { |
| 79 | + return self.encryptedPassword; |
| 80 | + } |
| 81 | + |
| 82 | + // Creates the api request data |
| 83 | + public func createApiRequestData(apiInvoker : ApiInvoker, configuration : Configuration) throws -> WordsApiRequestData { |
| 84 | + var rawPath = "/words/online/get/translate/{nodeId}"; |
| 85 | + rawPath = rawPath.replacingOccurrences(of: "{nodeId}", with: try ObjectSerializer.serializeToString(value: self.getNodeId())); |
| 86 | + |
| 87 | + rawPath = rawPath.replacingOccurrences(of: "//", with: "/"); |
| 88 | + |
| 89 | + let urlPath = (try configuration.getApiRootUrl()).appendingPathComponent(rawPath); |
| 90 | + var urlBuilder = URLComponents(url: urlPath, resolvingAgainstBaseURL: false)!; |
| 91 | + var queryItems : [URLQueryItem] = []; |
| 92 | + if (self.getLoadEncoding() != nil) { |
| 93 | + |
| 94 | + #if os(Linux) |
| 95 | + queryItems.append(URLQueryItem(name: "loadEncoding", value: try ObjectSerializer.serializeToString(value: self.getLoadEncoding()!))); |
| 96 | + |
| 97 | + #else |
| 98 | + queryItems.append(URLQueryItem(name: "loadEncoding", value: try ObjectSerializer.serializeToString(value: self.getLoadEncoding()!))); |
| 99 | + |
| 100 | + #endif |
| 101 | + } |
| 102 | + |
| 103 | + |
| 104 | + if (self.getPassword() != nil) { |
| 105 | + |
| 106 | + #if os(Linux) |
| 107 | + queryItems.append(URLQueryItem(name: "password", value: try ObjectSerializer.serializeToString(value: self.getPassword()!))); |
| 108 | + |
| 109 | + #else |
| 110 | + queryItems.append(URLQueryItem(name: "encryptedPassword", value: try apiInvoker.encryptString(value: self.getPassword()!))); |
| 111 | + |
| 112 | + #endif |
| 113 | + } |
| 114 | + |
| 115 | + |
| 116 | + if (self.getEncryptedPassword() != nil) { |
| 117 | + |
| 118 | + #if os(Linux) |
| 119 | + queryItems.append(URLQueryItem(name: "encryptedPassword", value: try ObjectSerializer.serializeToString(value: self.getEncryptedPassword()!))); |
| 120 | + |
| 121 | + #else |
| 122 | + queryItems.append(URLQueryItem(name: "encryptedPassword", value: try ObjectSerializer.serializeToString(value: self.getEncryptedPassword()!))); |
| 123 | + |
| 124 | + #endif |
| 125 | + } |
| 126 | + |
| 127 | + if (queryItems.count > 0) { |
| 128 | + urlBuilder.queryItems = queryItems; |
| 129 | + } |
| 130 | + var formParams = [RequestFormParam](); |
| 131 | + var requestFilesContent = [FileReference](); |
| 132 | + formParams.append(RequestFormParam(name: "document", body: try ObjectSerializer.serializeFile(value: self.getDocument()), contentType: "application/octet-stream")); |
| 133 | + |
| 134 | + try apiInvoker.prepareFilesContent(&requestFilesContent); |
| 135 | + for requestFileReference in requestFilesContent { |
| 136 | + if (requestFileReference.source == "Request") { |
| 137 | + formParams.append(RequestFormParam(name: requestFileReference.reference, body: try ObjectSerializer.serializeFile(value: requestFileReference.content), contentType: "application/octet-stream")); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + var result = WordsApiRequestData(url: urlBuilder.url!, method: "PUT"); |
| 142 | + if (formParams.count > 0) { |
| 143 | + result.setBody(formParams: formParams); |
| 144 | + } |
| 145 | + return result; |
| 146 | + } |
| 147 | + |
| 148 | + // Deserialize response of this request |
| 149 | + public func deserializeResponse(data : Data, headers : [String: String]) throws -> Any? { |
| 150 | + return try ObjectSerializer.deserialize(type: TranslateNodeIdResponse.self, from: data); |
| 151 | + } |
| 152 | +} |
0 commit comments