|
| 1 | +/* |
| 2 | + * -------------------------------------------------------------------------------- |
| 3 | + * <copyright company="Aspose" file="CopyStylesFromTemplateRequest.swift"> |
| 4 | + * Copyright (c) 2022 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 copyStylesFromTemplate operation. |
| 31 | +@available(macOS 10.12, iOS 10.3, watchOS 3.3, tvOS 12.0, *) |
| 32 | +public class CopyStylesFromTemplateRequest : WordsApiRequest { |
| 33 | + private let name : String; |
| 34 | + private let templateName : String; |
| 35 | + private let folder : String?; |
| 36 | + private let storage : String?; |
| 37 | + private let loadEncoding : String?; |
| 38 | + private let password : String?; |
| 39 | + private let encryptedPassword : String?; |
| 40 | + private let destFileName : String?; |
| 41 | + private let revisionAuthor : String?; |
| 42 | + private let revisionDateTime : String?; |
| 43 | + |
| 44 | + private enum CodingKeys: String, CodingKey { |
| 45 | + case name; |
| 46 | + case templateName; |
| 47 | + case folder; |
| 48 | + case storage; |
| 49 | + case loadEncoding; |
| 50 | + case password; |
| 51 | + case encryptedPassword; |
| 52 | + case destFileName; |
| 53 | + case revisionAuthor; |
| 54 | + case revisionDateTime; |
| 55 | + case invalidCodingKey; |
| 56 | + } |
| 57 | + |
| 58 | + // Initializes a new instance of the CopyStylesFromTemplateRequest class. |
| 59 | + public init(name : String, templateName : String, folder : String? = nil, storage : String? = nil, loadEncoding : String? = nil, password : String? = nil, encryptedPassword : String? = nil, destFileName : String? = nil, revisionAuthor : String? = nil, revisionDateTime : String? = nil) { |
| 60 | + self.name = name; |
| 61 | + self.templateName = templateName; |
| 62 | + self.folder = folder; |
| 63 | + self.storage = storage; |
| 64 | + self.loadEncoding = loadEncoding; |
| 65 | + self.password = password; |
| 66 | + self.encryptedPassword = encryptedPassword; |
| 67 | + self.destFileName = destFileName; |
| 68 | + self.revisionAuthor = revisionAuthor; |
| 69 | + self.revisionDateTime = revisionDateTime; |
| 70 | + } |
| 71 | + |
| 72 | + // The filename of the target document. |
| 73 | + public func getName() -> String { |
| 74 | + return self.name; |
| 75 | + } |
| 76 | + |
| 77 | + // The filename of the origin document. |
| 78 | + public func getTemplateName() -> String { |
| 79 | + return self.templateName; |
| 80 | + } |
| 81 | + |
| 82 | + // Original document folder. |
| 83 | + public func getFolder() -> String? { |
| 84 | + return self.folder; |
| 85 | + } |
| 86 | + |
| 87 | + // Original document storage. |
| 88 | + public func getStorage() -> String? { |
| 89 | + return self.storage; |
| 90 | + } |
| 91 | + |
| 92 | + // Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML. |
| 93 | + public func getLoadEncoding() -> String? { |
| 94 | + return self.loadEncoding; |
| 95 | + } |
| 96 | + |
| 97 | + // 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. |
| 98 | + public func getPassword() -> String? { |
| 99 | + return self.password; |
| 100 | + } |
| 101 | + |
| 102 | + // Password of protected Word document. Use the parameter to pass an encrypted password for direct calls of API. See SDK code for encyption details. |
| 103 | + public func getEncryptedPassword() -> String? { |
| 104 | + return self.encryptedPassword; |
| 105 | + } |
| 106 | + |
| 107 | + // Result path of the document after the operation. If this parameter is omitted then result of the operation will be saved as the source document. |
| 108 | + public func getDestFileName() -> String? { |
| 109 | + return self.destFileName; |
| 110 | + } |
| 111 | + |
| 112 | + // Initials of the author to use for revisions.If you set this parameter and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions. |
| 113 | + public func getRevisionAuthor() -> String? { |
| 114 | + return self.revisionAuthor; |
| 115 | + } |
| 116 | + |
| 117 | + // The date and time to use for revisions. |
| 118 | + public func getRevisionDateTime() -> String? { |
| 119 | + return self.revisionDateTime; |
| 120 | + } |
| 121 | + |
| 122 | + // Creates the api request data |
| 123 | + public func createApiRequestData(apiInvoker : ApiInvoker, configuration : Configuration) throws -> WordsApiRequestData { |
| 124 | + var rawPath = "/words/{name}/styles/copy_from"; |
| 125 | + rawPath = rawPath.replacingOccurrences(of: "{name}", with: try ObjectSerializer.serializeToString(value: self.getName())); |
| 126 | + |
| 127 | + rawPath = rawPath.replacingOccurrences(of: "//", with: "/"); |
| 128 | + |
| 129 | + let urlPath = (try configuration.getApiRootUrl()).appendingPathComponent(rawPath); |
| 130 | + var urlBuilder = URLComponents(url: urlPath, resolvingAgainstBaseURL: false)!; |
| 131 | + var queryItems : [URLQueryItem] = []; |
| 132 | + #if os(Linux) |
| 133 | + queryItems.append(URLQueryItem(name: "templateName", value: try ObjectSerializer.serializeToString(value: self.getTemplateName()))); |
| 134 | + #else |
| 135 | + queryItems.append(URLQueryItem(name: "templateName", value: try ObjectSerializer.serializeToString(value: self.getTemplateName()))); |
| 136 | + #endif |
| 137 | + |
| 138 | + |
| 139 | + if (self.getFolder() != nil) { |
| 140 | + |
| 141 | + #if os(Linux) |
| 142 | + queryItems.append(URLQueryItem(name: "folder", value: try ObjectSerializer.serializeToString(value: self.getFolder()!))); |
| 143 | + |
| 144 | + #else |
| 145 | + queryItems.append(URLQueryItem(name: "folder", value: try ObjectSerializer.serializeToString(value: self.getFolder()!))); |
| 146 | + |
| 147 | + #endif |
| 148 | + } |
| 149 | + |
| 150 | + |
| 151 | + if (self.getStorage() != nil) { |
| 152 | + |
| 153 | + #if os(Linux) |
| 154 | + queryItems.append(URLQueryItem(name: "storage", value: try ObjectSerializer.serializeToString(value: self.getStorage()!))); |
| 155 | + |
| 156 | + #else |
| 157 | + queryItems.append(URLQueryItem(name: "storage", value: try ObjectSerializer.serializeToString(value: self.getStorage()!))); |
| 158 | + |
| 159 | + #endif |
| 160 | + } |
| 161 | + |
| 162 | + |
| 163 | + if (self.getLoadEncoding() != nil) { |
| 164 | + |
| 165 | + #if os(Linux) |
| 166 | + queryItems.append(URLQueryItem(name: "loadEncoding", value: try ObjectSerializer.serializeToString(value: self.getLoadEncoding()!))); |
| 167 | + |
| 168 | + #else |
| 169 | + queryItems.append(URLQueryItem(name: "loadEncoding", value: try ObjectSerializer.serializeToString(value: self.getLoadEncoding()!))); |
| 170 | + |
| 171 | + #endif |
| 172 | + } |
| 173 | + |
| 174 | + |
| 175 | + if (self.getPassword() != nil) { |
| 176 | + |
| 177 | + #if os(Linux) |
| 178 | + queryItems.append(URLQueryItem(name: "password", value: try ObjectSerializer.serializeToString(value: self.getPassword()!))); |
| 179 | + |
| 180 | + #else |
| 181 | + queryItems.append(URLQueryItem(name: apiInvoker.isEncryptionAllowed() ? "encryptedPassword" : "password", value: try apiInvoker.encryptString(value: self.getPassword()!))); |
| 182 | + |
| 183 | + #endif |
| 184 | + } |
| 185 | + |
| 186 | + |
| 187 | + if (self.getEncryptedPassword() != nil) { |
| 188 | + |
| 189 | + #if os(Linux) |
| 190 | + queryItems.append(URLQueryItem(name: "encryptedPassword", value: try ObjectSerializer.serializeToString(value: self.getEncryptedPassword()!))); |
| 191 | + |
| 192 | + #else |
| 193 | + queryItems.append(URLQueryItem(name: "encryptedPassword", value: try ObjectSerializer.serializeToString(value: self.getEncryptedPassword()!))); |
| 194 | + |
| 195 | + #endif |
| 196 | + } |
| 197 | + |
| 198 | + |
| 199 | + if (self.getDestFileName() != nil) { |
| 200 | + |
| 201 | + #if os(Linux) |
| 202 | + queryItems.append(URLQueryItem(name: "destFileName", value: try ObjectSerializer.serializeToString(value: self.getDestFileName()!))); |
| 203 | + |
| 204 | + #else |
| 205 | + queryItems.append(URLQueryItem(name: "destFileName", value: try ObjectSerializer.serializeToString(value: self.getDestFileName()!))); |
| 206 | + |
| 207 | + #endif |
| 208 | + } |
| 209 | + |
| 210 | + |
| 211 | + if (self.getRevisionAuthor() != nil) { |
| 212 | + |
| 213 | + #if os(Linux) |
| 214 | + queryItems.append(URLQueryItem(name: "revisionAuthor", value: try ObjectSerializer.serializeToString(value: self.getRevisionAuthor()!))); |
| 215 | + |
| 216 | + #else |
| 217 | + queryItems.append(URLQueryItem(name: "revisionAuthor", value: try ObjectSerializer.serializeToString(value: self.getRevisionAuthor()!))); |
| 218 | + |
| 219 | + #endif |
| 220 | + } |
| 221 | + |
| 222 | + |
| 223 | + if (self.getRevisionDateTime() != nil) { |
| 224 | + |
| 225 | + #if os(Linux) |
| 226 | + queryItems.append(URLQueryItem(name: "revisionDateTime", value: try ObjectSerializer.serializeToString(value: self.getRevisionDateTime()!))); |
| 227 | + |
| 228 | + #else |
| 229 | + queryItems.append(URLQueryItem(name: "revisionDateTime", value: try ObjectSerializer.serializeToString(value: self.getRevisionDateTime()!))); |
| 230 | + |
| 231 | + #endif |
| 232 | + } |
| 233 | + |
| 234 | + if (queryItems.count > 0) { |
| 235 | + urlBuilder.queryItems = queryItems; |
| 236 | + } |
| 237 | + |
| 238 | + let result = WordsApiRequestData(url: urlBuilder.url!, method: "PUT"); |
| 239 | + return result; |
| 240 | + } |
| 241 | + |
| 242 | + // Deserialize response of this request |
| 243 | + public func deserializeResponse(data : Data, headers : [String: String]) throws -> Any? { |
| 244 | + return try ObjectSerializer.deserialize(type: WordsResponse.self, from: data); |
| 245 | + } |
| 246 | +} |
0 commit comments