|
| 1 | +// -------------------------------------------------------------------------------------------------------------------- |
| 2 | +// <copyright company="Aspose" file="StorageApi.cs"> |
| 3 | +// Copyright (c) 2020 Aspose.Omr for Cloud |
| 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 Aspose.Omr.Cloud.Sdk.Api |
| 27 | +{ |
| 28 | + using System.Collections.Generic; |
| 29 | + using System.Text.RegularExpressions; |
| 30 | + using Aspose.Omr.Cloud.Sdk.Model; |
| 31 | + using Aspose.Omr.Cloud.Sdk.Model.Requests; |
| 32 | + using Aspose.Omr.Cloud.Sdk.RequestHandlers; |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Aspose.Omr for Cloud API. |
| 36 | + /// </summary> |
| 37 | + public class StorageApi |
| 38 | + { |
| 39 | + private readonly ApiInvoker apiInvoker; |
| 40 | + private readonly Configuration configuration; |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Initializes a new instance of the <see cref="StorageApi"/> class. |
| 44 | + /// </summary> |
| 45 | + /// <param name="apiKey"> |
| 46 | + /// The api Key. |
| 47 | + /// </param> |
| 48 | + /// <param name="appSid"> |
| 49 | + /// The app Sid. |
| 50 | + /// </param> |
| 51 | + public StorageApi(string apiKey, string appSid) |
| 52 | + : this(new Configuration { AppKey = apiKey, AppSid = appSid }) |
| 53 | + { |
| 54 | + } |
| 55 | + |
| 56 | + public StorageApi(string jwtToken) |
| 57 | + : this(new Configuration { JwtToken = jwtToken, ApiVersion = ApiVersion.V3, AuthType = AuthType.ExternalAuth }) |
| 58 | + { |
| 59 | + } |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// Initializes a new instance of the <see cref="StorageApi"/> class. |
| 63 | + /// </summary> |
| 64 | + /// <param name="configuration">Configuration settings</param> |
| 65 | + public StorageApi(Configuration configuration) |
| 66 | + { |
| 67 | + this.configuration = configuration; |
| 68 | + |
| 69 | + var requestHandlers = new List<IRequestHandler>(); |
| 70 | + switch (this.configuration.AuthType) |
| 71 | + { |
| 72 | + case AuthType.RequestSignature: |
| 73 | + requestHandlers.Add(new AuthWithSignatureRequestHandler(this.configuration)); |
| 74 | + break; |
| 75 | + case AuthType.OAuth2: |
| 76 | + requestHandlers.Add(new OAuthRequestHandler(this.configuration)); |
| 77 | + break; |
| 78 | + case AuthType.ExternalAuth: |
| 79 | + requestHandlers.Add(new ExternalAuthorizationRequestHandler(this.configuration)); |
| 80 | + break; |
| 81 | + case AuthType.JWT: |
| 82 | + requestHandlers.Add(new JwtRequestHandler(this.configuration)); |
| 83 | + break; |
| 84 | + } |
| 85 | + |
| 86 | + requestHandlers.Add(new DebugLogRequestHandler(this.configuration)); |
| 87 | + requestHandlers.Add(new ApiExceptionRequestHandler()); |
| 88 | + this.apiInvoker = new ApiInvoker(requestHandlers); |
| 89 | + } |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// Get disc usage |
| 93 | + /// </summary> |
| 94 | + /// <param name="request">Request. <see cref="GetDiscUsageRequest" /></param> |
| 95 | + /// <returns><see cref="DiscUsage"/></returns> |
| 96 | + public DiscUsage GetDiscUsage(GetDiscUsageRequest request) |
| 97 | + { |
| 98 | + // create path and map variables |
| 99 | + var resourcePath = this.configuration.GetApiRootUrl() + "/omr/storage/disc"; |
| 100 | + resourcePath = Regex |
| 101 | + .Replace(resourcePath, "\\*", string.Empty) |
| 102 | + .Replace("&", "&") |
| 103 | + .Replace("/?", "?"); |
| 104 | + resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storageName", request.storageName); |
| 105 | + |
| 106 | + try |
| 107 | + { |
| 108 | + var response = this.apiInvoker.InvokeApi( |
| 109 | + resourcePath, |
| 110 | + "GET", |
| 111 | + null, |
| 112 | + null, |
| 113 | + null); |
| 114 | + if (response != null) |
| 115 | + { |
| 116 | + return (DiscUsage)SerializationHelper.Deserialize(response, typeof(DiscUsage)); |
| 117 | + } |
| 118 | + |
| 119 | + return null; |
| 120 | + } |
| 121 | + catch (ApiException ex) |
| 122 | + { |
| 123 | + if (ex.ErrorCode == 404) |
| 124 | + { |
| 125 | + return null; |
| 126 | + } |
| 127 | + |
| 128 | + throw; |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + /// <summary> |
| 133 | + /// Get file versions |
| 134 | + /// </summary> |
| 135 | + /// <param name="request">Request. <see cref="GetFileVersionsRequest" /></param> |
| 136 | + /// <returns><see cref="FileVersions"/></returns> |
| 137 | + public FileVersions GetFileVersions(GetFileVersionsRequest request) |
| 138 | + { |
| 139 | + // verify the required parameter 'path' is set |
| 140 | + if (request.path == null) |
| 141 | + { |
| 142 | + throw new ApiException(400, "Missing required parameter 'path' when calling GetFileVersions"); |
| 143 | + } |
| 144 | + |
| 145 | + // create path and map variables |
| 146 | + var resourcePath = this.configuration.GetApiRootUrl() + "/omr/storage/version/{path}"; |
| 147 | + resourcePath = Regex |
| 148 | + .Replace(resourcePath, "\\*", string.Empty) |
| 149 | + .Replace("&", "&") |
| 150 | + .Replace("/?", "?"); |
| 151 | + resourcePath = UrlHelper.AddPathParameter(resourcePath, "path", request.path); |
| 152 | + resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storageName", request.storageName); |
| 153 | + |
| 154 | + try |
| 155 | + { |
| 156 | + var response = this.apiInvoker.InvokeApi( |
| 157 | + resourcePath, |
| 158 | + "GET", |
| 159 | + null, |
| 160 | + null, |
| 161 | + null); |
| 162 | + if (response != null) |
| 163 | + { |
| 164 | + return (FileVersions)SerializationHelper.Deserialize(response, typeof(FileVersions)); |
| 165 | + } |
| 166 | + |
| 167 | + return null; |
| 168 | + } |
| 169 | + catch (ApiException ex) |
| 170 | + { |
| 171 | + if (ex.ErrorCode == 404) |
| 172 | + { |
| 173 | + return null; |
| 174 | + } |
| 175 | + |
| 176 | + throw; |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + /// <summary> |
| 181 | + /// Check if file or folder exists |
| 182 | + /// </summary> |
| 183 | + /// <param name="request">Request. <see cref="ObjectExistsRequest" /></param> |
| 184 | + /// <returns><see cref="ObjectExist"/></returns> |
| 185 | + public ObjectExist ObjectExists(ObjectExistsRequest request) |
| 186 | + { |
| 187 | + // verify the required parameter 'path' is set |
| 188 | + if (request.path == null) |
| 189 | + { |
| 190 | + throw new ApiException(400, "Missing required parameter 'path' when calling ObjectExists"); |
| 191 | + } |
| 192 | + |
| 193 | + // create path and map variables |
| 194 | + var resourcePath = this.configuration.GetApiRootUrl() + "/omr/storage/exist/{path}"; |
| 195 | + resourcePath = Regex |
| 196 | + .Replace(resourcePath, "\\*", string.Empty) |
| 197 | + .Replace("&", "&") |
| 198 | + .Replace("/?", "?"); |
| 199 | + resourcePath = UrlHelper.AddPathParameter(resourcePath, "path", request.path); |
| 200 | + resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storageName", request.storageName); |
| 201 | + resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "versionId", request.versionId); |
| 202 | + |
| 203 | + try |
| 204 | + { |
| 205 | + var response = this.apiInvoker.InvokeApi( |
| 206 | + resourcePath, |
| 207 | + "GET", |
| 208 | + null, |
| 209 | + null, |
| 210 | + null); |
| 211 | + if (response != null) |
| 212 | + { |
| 213 | + return (ObjectExist)SerializationHelper.Deserialize(response, typeof(ObjectExist)); |
| 214 | + } |
| 215 | + |
| 216 | + return null; |
| 217 | + } |
| 218 | + catch (ApiException ex) |
| 219 | + { |
| 220 | + if (ex.ErrorCode == 404) |
| 221 | + { |
| 222 | + return null; |
| 223 | + } |
| 224 | + |
| 225 | + throw; |
| 226 | + } |
| 227 | + } |
| 228 | + |
| 229 | + /// <summary> |
| 230 | + /// Check if storage exists |
| 231 | + /// </summary> |
| 232 | + /// <param name="request">Request. <see cref="StorageExistsRequest" /></param> |
| 233 | + /// <returns><see cref="StorageExist"/></returns> |
| 234 | + public StorageExist StorageExists(StorageExistsRequest request) |
| 235 | + { |
| 236 | + // verify the required parameter 'storageName' is set |
| 237 | + if (request.storageName == null) |
| 238 | + { |
| 239 | + throw new ApiException(400, "Missing required parameter 'storageName' when calling StorageExists"); |
| 240 | + } |
| 241 | + |
| 242 | + // create path and map variables |
| 243 | + var resourcePath = this.configuration.GetApiRootUrl() + "/omr/storage/{storageName}/exist"; |
| 244 | + resourcePath = Regex |
| 245 | + .Replace(resourcePath, "\\*", string.Empty) |
| 246 | + .Replace("&", "&") |
| 247 | + .Replace("/?", "?"); |
| 248 | + resourcePath = UrlHelper.AddPathParameter(resourcePath, "storageName", request.storageName); |
| 249 | + |
| 250 | + try |
| 251 | + { |
| 252 | + var response = this.apiInvoker.InvokeApi( |
| 253 | + resourcePath, |
| 254 | + "GET", |
| 255 | + null, |
| 256 | + null, |
| 257 | + null); |
| 258 | + if (response != null) |
| 259 | + { |
| 260 | + return (StorageExist)SerializationHelper.Deserialize(response, typeof(StorageExist)); |
| 261 | + } |
| 262 | + |
| 263 | + return null; |
| 264 | + } |
| 265 | + catch (ApiException ex) |
| 266 | + { |
| 267 | + if (ex.ErrorCode == 404) |
| 268 | + { |
| 269 | + return null; |
| 270 | + } |
| 271 | + |
| 272 | + throw; |
| 273 | + } |
| 274 | + } |
| 275 | + } |
| 276 | +} |
0 commit comments