-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathScanApi.cs
More file actions
199 lines (175 loc) · 8.73 KB
/
ScanApi.cs
File metadata and controls
199 lines (175 loc) · 8.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Aspose" file="ScanApi.cs">
// Copyright (c) 2026 Aspose.BarCode for Cloud
// </copyright>
// <summary>
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
using System.Collections.Generic;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Aspose.BarCode.Cloud.Sdk.Interfaces;
using Aspose.BarCode.Cloud.Sdk.Internal;
using Aspose.BarCode.Cloud.Sdk.Internal.RequestHandlers;
using Aspose.BarCode.Cloud.Sdk.Model;
namespace Aspose.BarCode.Cloud.Sdk.Api
{
/// <summary>
/// ScanApi
/// </summary>
public class ScanApi : IScanApi
{
private readonly ApiInvoker _apiInvoker;
private readonly Configuration _configuration;
/// <summary>
/// Initializes a new instance of the <see cref="ScanApi" /> class.
/// </summary>
/// <param name="configuration">Configuration settings</param>
public ScanApi(Configuration configuration)
{
_configuration = configuration;
List<IRequestHandler> requestHandlers = new List<IRequestHandler>();
switch (_configuration.AuthType)
{
case AuthType.JWT:
requestHandlers.Add(new JwtRequestHandler(_configuration));
break;
case AuthType.ExternalAuth:
requestHandlers.Add(new ExternalAuthorizationRequestHandler(_configuration));
break;
default:
throw new System.ArgumentOutOfRangeException($"Unknown AuthType={_configuration.AuthType}.");
}
requestHandlers.Add(new DebugLogRequestHandler(_configuration));
requestHandlers.Add(new ApiExceptionRequestHandler());
_apiInvoker = new ApiInvoker(configuration, requestHandlers);
}
/// <summary>
/// Initializes a new instance of the <see cref="ScanApi" /> class.
/// </summary>
/// <param name="clientSecret">
/// The Client Secret.
/// </param>
/// <param name="clientId">
/// The Client Id.
/// </param>
public ScanApi(string clientSecret, string clientId)
: this(new Configuration { ClientSecret = clientSecret, ClientId = clientId })
{
}
/// <summary>
/// Scan barcode from file on server in the Internet using GET requests with parameter in query string. For scaning files from your hard drive use `scan-body` or `scan-multipart` endpoints instead.
/// </summary>
/// <param name="fileUrl">Url to barcode image</param>
/// <param name="cancellationToken"></param>
/// <returns>
/// A task that represents the asynchronous operation. Task result type is <see cref="BarcodeResponseList" />
/// </returns>
public async Task<BarcodeResponseList> ScanAsync(string fileUrl, System.Threading.CancellationToken cancellationToken = default)
{
// verify the required parameter 'fileUrl' is set
if (fileUrl == null)
{
throw new ApiException(400, "Missing required parameter 'fileUrl' when calling Scan");
}
// create path and map variables
string resourcePath = _configuration.GetApiRootUrl() + "/barcode/scan";
resourcePath = Regex
.Replace(resourcePath, "\\*", string.Empty)
.Replace("&", "&")
.Replace("/?", "?");
#pragma warning disable CS0618 // Type or member is obsolete
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "fileUrl", fileUrl);
#pragma warning restore CS0618 // Type or member is obsolete
string response = await _apiInvoker.InvokeApiAsync(
resourcePath,
"GET",
null,
null,
null);
return response != null ? (BarcodeResponseList)SerializationHelper.Deserialize(response, typeof(BarcodeResponseList)) : null;
}
/// <summary>
/// Scan barcode from file in request body using POST requests with parameter in body in json or xml format.
/// </summary>
/// <param name="scanBase64Request">Barcode scan request</param>
/// <param name="cancellationToken"></param>
/// <returns>
/// A task that represents the asynchronous operation. Task result type is <see cref="BarcodeResponseList" />
/// </returns>
public async Task<BarcodeResponseList> ScanBase64Async(ScanBase64Request scanBase64Request, System.Threading.CancellationToken cancellationToken = default)
{
// verify the required parameter 'scanBase64Request' is set
if (scanBase64Request == null)
{
throw new ApiException(400, "Missing required parameter 'scanBase64Request' when calling ScanBase64");
}
// create path and map variables
string resourcePath = _configuration.GetApiRootUrl() + "/barcode/scan-body";
resourcePath = Regex
.Replace(resourcePath, "\\*", string.Empty)
.Replace("&", "&")
.Replace("/?", "?");
string postBody = SerializationHelper.Serialize(scanBase64Request); // http body (model) parameter
string response = await _apiInvoker.InvokeApiAsync(
resourcePath,
"POST",
postBody,
null,
null);
return response != null ? (BarcodeResponseList)SerializationHelper.Deserialize(response, typeof(BarcodeResponseList)) : null;
}
/// <summary>
/// Scan barcode from file in request body using POST requests with parameter in multipart form.
/// </summary>
/// <param name="file">Barcode image file</param>
/// <param name="cancellationToken"></param>
/// <returns>
/// A task that represents the asynchronous operation. Task result type is <see cref="BarcodeResponseList" />
/// </returns>
public async Task<BarcodeResponseList> ScanMultipartAsync(System.IO.Stream file, System.Threading.CancellationToken cancellationToken = default)
{
// verify the required parameter 'file' is set
if (file == null)
{
throw new ApiException(400, "Missing required parameter 'file' when calling ScanMultipart");
}
// create path and map variables
string resourcePath = _configuration.GetApiRootUrl() + "/barcode/scan-multipart";
resourcePath = Regex
.Replace(resourcePath, "\\*", string.Empty)
.Replace("&", "&")
.Replace("/?", "?");
MultipartFormDataContent multipartContent = new MultipartFormDataContent();
if (file != null)
{
multipartContent.Add(new StreamContent(file), "file", "file.png");
}
string response = await _apiInvoker.InvokeApiAsync(
resourcePath,
"POST",
null,
null,
multipartContent);
return response != null ? (BarcodeResponseList)SerializationHelper.Deserialize(response, typeof(BarcodeResponseList)) : null;
}
}
}