|
| 1 | +// -------------------------------------------------------------------------------------------------------------------- |
| 2 | +// <copyright company="Aspose Pty Ltd" file="ConvertApi.cs"> |
| 3 | +// Copyright (c) 2003-2019 Aspose Pty Ltd |
| 4 | +// </copyright> |
| 5 | +// <summary> |
| 6 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +// of this software and associated documentation files (the "Software"), to deal |
| 8 | +// in the Software without restriction, including without limitation the rights |
| 9 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +// copies of the Software, and to permit persons to whom the Software is |
| 11 | +// furnished to do so, subject to the following conditions: |
| 12 | +// |
| 13 | +// The above copyright notice and this permission notice shall be included in all |
| 14 | +// copies or substantial portions of the Software. |
| 15 | +// |
| 16 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +// SOFTWARE. |
| 23 | +// </summary> |
| 24 | +// -------------------------------------------------------------------------------------------------------------------- |
| 25 | + |
| 26 | +namespace GroupDocs.Conversion.Cloud.Sdk.Api |
| 27 | +{ |
| 28 | + using System.IO; |
| 29 | + using System.Collections.Generic; |
| 30 | + using System.Text.RegularExpressions; |
| 31 | + using GroupDocs.Conversion.Cloud.Sdk.Client; |
| 32 | + using GroupDocs.Conversion.Cloud.Sdk.Client.RequestHandlers; |
| 33 | + using GroupDocs.Conversion.Cloud.Sdk.Model; |
| 34 | + using GroupDocs.Conversion.Cloud.Sdk.Model.Requests; |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// GroupDocs.Conversion Cloud API. |
| 38 | + /// </summary> |
| 39 | + public class ConvertApi |
| 40 | + { |
| 41 | + private readonly ApiInvoker apiInvoker; |
| 42 | + private readonly Configuration configuration; |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Initializes a new instance of the <see cref="ConvertApi"/> class. |
| 46 | + /// </summary> |
| 47 | + /// <param name="appSid">Application identifier (App SID)</param> |
| 48 | + /// <param name="appKey">Application private key (App Key)</param> |
| 49 | + public ConvertApi(string appSid, string appKey) |
| 50 | + : this(new Configuration(appSid, appKey)) |
| 51 | + { |
| 52 | + } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Initializes a new instance of the <see cref="ConvertApi"/> class. |
| 56 | + /// </summary> |
| 57 | + /// <param name="configuration">Configuration settings</param> |
| 58 | + public ConvertApi(Configuration configuration) |
| 59 | + { |
| 60 | + this.configuration = configuration; |
| 61 | + |
| 62 | + var requestHandlers = new List<IRequestHandler>(); |
| 63 | + requestHandlers.Add(new AuthRequestHandler(this.configuration)); |
| 64 | + requestHandlers.Add(new DebugLogRequestHandler(this.configuration)); |
| 65 | + requestHandlers.Add(new ApiExceptionRequestHandler()); |
| 66 | + this.apiInvoker = new ApiInvoker(requestHandlers, this.configuration.Timeout); |
| 67 | + } |
| 68 | + |
| 69 | + /// <summary> |
| 70 | + /// Converts specified input document to format specified in the convertSettings with specified options |
| 71 | + /// </summary> |
| 72 | + /// <param name="request">Request. <see cref="ConvertDocumentRequest" /></param> |
| 73 | + public List<StoredConvertedResult> ConvertDocument(ConvertDocumentRequest request) |
| 74 | + { |
| 75 | + // verify the required parameter 'convertSettings' is set |
| 76 | + if (request.convertSettings == null) |
| 77 | + { |
| 78 | + throw new ApiException(400, |
| 79 | + "Missing required parameter 'convertSettings' when calling ConvertDocument"); |
| 80 | + } |
| 81 | + |
| 82 | + // create path and map variables |
| 83 | + var resourcePath = this.configuration.GetServerUrl() + "/conversion"; |
| 84 | + resourcePath = Regex |
| 85 | + .Replace(resourcePath, "\\*", string.Empty) |
| 86 | + .Replace("&", "&") |
| 87 | + .Replace("/?", "?"); |
| 88 | + var postBody = SerializationHelper.Serialize(request.convertSettings); // http body (model) parameter |
| 89 | + var response = this.apiInvoker.InvokeApi( |
| 90 | + resourcePath, |
| 91 | + "POST", |
| 92 | + postBody, |
| 93 | + null, |
| 94 | + null); |
| 95 | + |
| 96 | + if (response != null) |
| 97 | + { |
| 98 | + return (List<StoredConvertedResult>) SerializationHelper.Deserialize(response, typeof(List<StoredConvertedResult>)); |
| 99 | + } |
| 100 | + |
| 101 | + return null; |
| 102 | + } |
| 103 | + |
| 104 | + /// <summary> |
| 105 | + /// Converts specified input document to format specified in the convertSettings with specified options and return result as stream |
| 106 | + /// </summary> |
| 107 | + /// <param name="request">Request. <see cref="ConvertDocumentRequest" /></param> |
| 108 | + public Stream ConvertDocumentDownload(ConvertDocumentRequest request) |
| 109 | + { |
| 110 | + // verify the required parameter 'convertSettings' is set |
| 111 | + if (request.convertSettings == null) |
| 112 | + { |
| 113 | + throw new ApiException(400, |
| 114 | + "Missing required parameter 'convertSettings' when calling ConvertDocument"); |
| 115 | + } |
| 116 | + |
| 117 | + // create path and map variables |
| 118 | + var resourcePath = this.configuration.GetServerUrl() + "/conversion"; |
| 119 | + resourcePath = Regex |
| 120 | + .Replace(resourcePath, "\\*", string.Empty) |
| 121 | + .Replace("&", "&") |
| 122 | + .Replace("/?", "?"); |
| 123 | + var postBody = SerializationHelper.Serialize(request.convertSettings); // http body (model) parameter |
| 124 | + return this.apiInvoker.InvokeBinaryApi( |
| 125 | + resourcePath, |
| 126 | + "POST", |
| 127 | + postBody, |
| 128 | + null, |
| 129 | + null); |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | +// -------------------------------------------------------------------------------------------------------------------- |
| 134 | +// <copyright company="Aspose Pty Ltd" file="ConvertDocumentRequest.cs"> |
| 135 | +// Copyright (c) 2003-2019 Aspose Pty Ltd |
| 136 | +// </copyright> |
| 137 | +// <summary> |
| 138 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 139 | +// of this software and associated documentation files (the "Software"), to deal |
| 140 | +// in the Software without restriction, including without limitation the rights |
| 141 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 142 | +// copies of the Software, and to permit persons to whom the Software is |
| 143 | +// furnished to do so, subject to the following conditions: |
| 144 | +// |
| 145 | +// The above copyright notice and this permission notice shall be included in all |
| 146 | +// copies or substantial portions of the Software. |
| 147 | +// |
| 148 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 149 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 150 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 151 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 152 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 153 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 154 | +// SOFTWARE. |
| 155 | +// </summary> |
| 156 | +// -------------------------------------------------------------------------------------------------------------------- |
| 157 | + |
| 158 | +namespace GroupDocs.Conversion.Cloud.Sdk.Model.Requests |
| 159 | +{ |
| 160 | + using GroupDocs.Conversion.Cloud.Sdk.Model; |
| 161 | + |
| 162 | + /// <summary> |
| 163 | + /// Request model for <see cref="GroupDocs.Conversion.Cloud.Sdk.Api.ConvertApi.ConvertDocument" /> operation. |
| 164 | + /// </summary> |
| 165 | + public class ConvertDocumentRequest |
| 166 | + { |
| 167 | + /// <summary> |
| 168 | + /// Initializes a new instance of the <see cref="ConvertDocumentRequest"/> class. |
| 169 | + /// </summary> |
| 170 | + public ConvertDocumentRequest() |
| 171 | + { |
| 172 | + } |
| 173 | + |
| 174 | + /// <summary> |
| 175 | + /// Initializes a new instance of the <see cref="ConvertDocumentRequest"/> class. |
| 176 | + /// </summary> |
| 177 | + /// <param name="convertSettings"></param> |
| 178 | + public ConvertDocumentRequest(ConvertSettings convertSettings) |
| 179 | + { |
| 180 | + this.convertSettings = convertSettings; |
| 181 | + } |
| 182 | + |
| 183 | + /// <summary> |
| 184 | + /// Gets or sets convertSettings |
| 185 | + /// </summary> |
| 186 | + public ConvertSettings convertSettings { get; set; } |
| 187 | + } |
| 188 | +} |
0 commit comments