Skip to content

Commit da578c7

Browse files
committed
added FolderApi and FileApi
1 parent 792a229 commit da578c7

File tree

13 files changed

+1419
-6
lines changed

13 files changed

+1419
-6
lines changed
Lines changed: 357 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,357 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright company="Aspose" file="FileApi.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
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 FileApi
38+
{
39+
private readonly ApiInvoker apiInvoker;
40+
private readonly Configuration configuration;
41+
42+
/// <summary>
43+
/// Initializes a new instance of the <see cref="FileApi"/> 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 FileApi(string apiKey, string appSid)
52+
: this(new Configuration { AppKey = apiKey, AppSid = appSid })
53+
{
54+
}
55+
56+
public FileApi(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="FileApi"/> class.
63+
/// </summary>
64+
/// <param name="configuration">Configuration settings</param>
65+
public FileApi(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+
/// Copy file
93+
/// </summary>
94+
/// <param name="request">Request. <see cref="CopyFileRequest" /></param>
95+
/// <returns><see cref=""/></returns>
96+
public void CopyFile(CopyFileRequest request)
97+
{
98+
// verify the required parameter 'srcPath' is set
99+
if (request.srcPath == null)
100+
{
101+
throw new ApiException(400, "Missing required parameter 'srcPath' when calling CopyFile");
102+
}
103+
104+
// verify the required parameter 'destPath' is set
105+
if (request.destPath == null)
106+
{
107+
throw new ApiException(400, "Missing required parameter 'destPath' when calling CopyFile");
108+
}
109+
110+
// create path and map variables
111+
var resourcePath = this.configuration.GetApiRootUrl() + "/omr/storage/file/copy/{srcPath}";
112+
resourcePath = Regex
113+
.Replace(resourcePath, "\\*", string.Empty)
114+
.Replace("&amp;", "&")
115+
.Replace("/?", "?");
116+
resourcePath = UrlHelper.AddPathParameter(resourcePath, "srcPath", request.srcPath);
117+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "destPath", request.destPath);
118+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "srcStorageName", request.srcStorageName);
119+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "destStorageName", request.destStorageName);
120+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "versionId", request.versionId);
121+
122+
try
123+
{
124+
var response = this.apiInvoker.InvokeApi(
125+
resourcePath,
126+
"PUT",
127+
null,
128+
null,
129+
null);
130+
if (response != null)
131+
{
132+
return;
133+
}
134+
135+
return;
136+
}
137+
catch (ApiException ex)
138+
{
139+
if (ex.ErrorCode == 404)
140+
{
141+
return;
142+
}
143+
144+
throw;
145+
}
146+
}
147+
148+
/// <summary>
149+
/// Delete file
150+
/// </summary>
151+
/// <param name="request">Request. <see cref="DeleteFileRequest" /></param>
152+
/// <returns><see cref=""/></returns>
153+
public void DeleteFile(DeleteFileRequest request)
154+
{
155+
// verify the required parameter 'path' is set
156+
if (request.path == null)
157+
{
158+
throw new ApiException(400, "Missing required parameter 'path' when calling DeleteFile");
159+
}
160+
161+
// create path and map variables
162+
var resourcePath = this.configuration.GetApiRootUrl() + "/omr/storage/file/{path}";
163+
resourcePath = Regex
164+
.Replace(resourcePath, "\\*", string.Empty)
165+
.Replace("&amp;", "&")
166+
.Replace("/?", "?");
167+
resourcePath = UrlHelper.AddPathParameter(resourcePath, "path", request.path);
168+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storageName", request.storageName);
169+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "versionId", request.versionId);
170+
171+
try
172+
{
173+
var response = this.apiInvoker.InvokeApi(
174+
resourcePath,
175+
"DELETE",
176+
null,
177+
null,
178+
null);
179+
if (response != null)
180+
{
181+
return;
182+
}
183+
184+
return;
185+
}
186+
catch (ApiException ex)
187+
{
188+
if (ex.ErrorCode == 404)
189+
{
190+
return;
191+
}
192+
193+
throw;
194+
}
195+
}
196+
197+
/// <summary>
198+
/// Download file
199+
/// </summary>
200+
/// <param name="request">Request. <see cref="DownloadFileRequest" /></param>
201+
/// <returns><see cref="System.IO.Stream"/></returns>
202+
public System.IO.Stream DownloadFile(DownloadFileRequest request)
203+
{
204+
// verify the required parameter 'path' is set
205+
if (request.path == null)
206+
{
207+
throw new ApiException(400, "Missing required parameter 'path' when calling DownloadFile");
208+
}
209+
210+
// create path and map variables
211+
var resourcePath = this.configuration.GetApiRootUrl() + "/omr/storage/file/{path}";
212+
resourcePath = Regex
213+
.Replace(resourcePath, "\\*", string.Empty)
214+
.Replace("&amp;", "&")
215+
.Replace("/?", "?");
216+
resourcePath = UrlHelper.AddPathParameter(resourcePath, "path", request.path);
217+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storageName", request.storageName);
218+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "versionId", request.versionId);
219+
220+
try
221+
{
222+
return this.apiInvoker.InvokeBinaryApi(
223+
resourcePath,
224+
"GET",
225+
null,
226+
null,
227+
null);
228+
}
229+
catch (ApiException ex)
230+
{
231+
if (ex.ErrorCode == 404)
232+
{
233+
return null;
234+
}
235+
236+
throw;
237+
}
238+
}
239+
240+
/// <summary>
241+
/// Move file
242+
/// </summary>
243+
/// <param name="request">Request. <see cref="MoveFileRequest" /></param>
244+
/// <returns><see cref=""/></returns>
245+
public void MoveFile(MoveFileRequest request)
246+
{
247+
// verify the required parameter 'srcPath' is set
248+
if (request.srcPath == null)
249+
{
250+
throw new ApiException(400, "Missing required parameter 'srcPath' when calling MoveFile");
251+
}
252+
253+
// verify the required parameter 'destPath' is set
254+
if (request.destPath == null)
255+
{
256+
throw new ApiException(400, "Missing required parameter 'destPath' when calling MoveFile");
257+
}
258+
259+
// create path and map variables
260+
var resourcePath = this.configuration.GetApiRootUrl() + "/omr/storage/file/move/{srcPath}";
261+
resourcePath = Regex
262+
.Replace(resourcePath, "\\*", string.Empty)
263+
.Replace("&amp;", "&")
264+
.Replace("/?", "?");
265+
resourcePath = UrlHelper.AddPathParameter(resourcePath, "srcPath", request.srcPath);
266+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "destPath", request.destPath);
267+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "srcStorageName", request.srcStorageName);
268+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "destStorageName", request.destStorageName);
269+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "versionId", request.versionId);
270+
271+
try
272+
{
273+
var response = this.apiInvoker.InvokeApi(
274+
resourcePath,
275+
"PUT",
276+
null,
277+
null,
278+
null);
279+
if (response != null)
280+
{
281+
return;
282+
}
283+
284+
return;
285+
}
286+
catch (ApiException ex)
287+
{
288+
if (ex.ErrorCode == 404)
289+
{
290+
return;
291+
}
292+
293+
throw;
294+
}
295+
}
296+
297+
/// <summary>
298+
/// Upload file
299+
/// </summary>
300+
/// <param name="request">Request. <see cref="UploadFileRequest" /></param>
301+
/// <returns><see cref="FilesUploadResult"/></returns>
302+
public FilesUploadResult UploadFile(UploadFileRequest request)
303+
{
304+
// verify the required parameter 'path' is set
305+
if (request.path == null)
306+
{
307+
throw new ApiException(400, "Missing required parameter 'path' when calling UploadFile");
308+
}
309+
310+
// verify the required parameter 'file' is set
311+
if (request.File == null)
312+
{
313+
throw new ApiException(400, "Missing required parameter 'file' when calling UploadFile");
314+
}
315+
316+
// create path and map variables
317+
var resourcePath = this.configuration.GetApiRootUrl() + "/omr/storage/file/{path}";
318+
resourcePath = Regex
319+
.Replace(resourcePath, "\\*", string.Empty)
320+
.Replace("&amp;", "&")
321+
.Replace("/?", "?");
322+
var formParams = new Dictionary<string, object>();
323+
resourcePath = UrlHelper.AddPathParameter(resourcePath, "path", request.path);
324+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storageName", request.storageName);
325+
326+
if (request.File != null)
327+
{
328+
formParams.Add("file", this.apiInvoker.ToFileInfo(request.File, "File"));
329+
}
330+
331+
try
332+
{
333+
var response = this.apiInvoker.InvokeApi(
334+
resourcePath,
335+
"PUT",
336+
null,
337+
null,
338+
formParams);
339+
if (response != null)
340+
{
341+
return (FilesUploadResult)SerializationHelper.Deserialize(response, typeof(FilesUploadResult));
342+
}
343+
344+
return null;
345+
}
346+
catch (ApiException ex)
347+
{
348+
if (ex.ErrorCode == 404)
349+
{
350+
return null;
351+
}
352+
353+
throw;
354+
}
355+
}
356+
}
357+
}

0 commit comments

Comments
 (0)