Skip to content

Commit 7416074

Browse files
authored
Merge pull request #87 from aspose-pdf-cloud/develop
ApiClient validation added
2 parents 2e3b220 + f982508 commit 7416074

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

src/Aspose.Pdf.Cloud.Sdk/Api/PdfApi.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
using System;
2727
using System.Collections.Generic;
28-
using System.Collections.ObjectModel;
2928
using System.Linq;
3029
using RestSharp;
3130
using Aspose.Pdf.Cloud.Sdk.Client;
@@ -20821,6 +20820,7 @@ public PdfApi(string jwtToken)
2082120820
Configuration = new Configuration("", "");
2082220821
ApiClient = new ApiClient(Configuration);
2082320822
ApiClient.AccessToken = jwtToken;
20823+
ApiClient.Validate();
2082420824
ExceptionFactory = Aspose.Pdf.Cloud.Sdk.Client.Configuration.DefaultExceptionFactory;
2082520825
}
2082620826

@@ -20843,12 +20843,10 @@ public PdfApi(string apiKey, string appSid)
2084320843
public PdfApi(Configuration configuration)
2084420844
{
2084520845
if (configuration == null)
20846-
{
2084720846
throw new ArgumentNullException("configuration");
20848-
}
20849-
2085020847
Configuration = configuration;
2085120848
ApiClient = new ApiClient(Configuration);
20849+
ApiClient.Validate();
2085220850
ExceptionFactory = Aspose.Pdf.Cloud.Sdk.Client.Configuration.DefaultExceptionFactory;
2085320851
}
2085420852

src/Aspose.Pdf.Cloud.Sdk/Client/ApiClient.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace Aspose.Pdf.Cloud.Sdk.Client
4242
/// <summary>
4343
/// API client is mainly responsible for making the HTTP call to the API backend.
4444
/// </summary>
45-
public partial class ApiClient
45+
public class ApiClient
4646
{
4747
private const int MAX_AUTH_TRIES_COUNT = 5;
4848
private int authTriesCount = 0;
@@ -164,12 +164,29 @@ private async System.Threading.Tasks.Task<bool> InterceptResponseAsync(IRestRequ
164164
/// </summary>
165165
public ApiClient(Configuration config)
166166
{
167-
Configuration = config;
168-
167+
Configuration = config;
169168
RestClient = new RestClient(config.BasePath);
170169
}
171170

172-
171+
private static bool CheckSidKey(string appSid, string apiKey)
172+
{
173+
if (appSid == apiKey)
174+
return true;
175+
string[] ssSid = appSid.Split('-');
176+
string[] ssKey = apiKey.Split('-');
177+
return ssSid.Length == 5 && ssKey.Length == 1;
178+
}
179+
180+
internal void Validate()
181+
{
182+
if (string.IsNullOrWhiteSpace(Configuration.BasePath))
183+
throw new ArgumentException("empty BasePath");
184+
if (!string.IsNullOrWhiteSpace(_accessToken))
185+
return;
186+
if (!CheckSidKey(Configuration.AppSid, Configuration.ApiKey))
187+
throw new ArgumentException("AppSid/ApiKey are messed up or have wrong format");
188+
}
189+
173190
/// <summary>
174191
/// Gets or sets the Configuration.
175192
/// </summary>

src/Aspose.Pdf.Cloud.Sdk/Client/Configuration.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
// --------------------------------------------------------------------------------------------------------------------
2525

2626
using System;
27-
using System.Reflection;
2827
using System.Collections.Generic;
2928
using System.IO;
3029
using System.Linq;
31-
using System.Text;
30+
using System.Reflection;
3231

3332
namespace Aspose.Pdf.Cloud.Sdk.Client
3433
{
@@ -57,12 +56,7 @@ public Configuration(string apiKey,
5756
int timeout = 5 * 60 * 1000,
5857
string userAgent = "aspose pdf cloud sdk"
5958
)
60-
{
61-
if (string.IsNullOrEmpty(basePath))
62-
throw new ArgumentException("basePath cannot be empty");
63-
if (!_CheckSidKey(appSid, apiKey))
64-
throw new ArgumentException("appSid and apiKey are messed up or have wrong format");
65-
59+
{
6660
ApiKey = apiKey;
6761
AppSid = appSid;
6862
BasePath = basePath;
@@ -74,13 +68,6 @@ public Configuration(string apiKey,
7468
Timeout = timeout;
7569
}
7670

77-
private static bool _CheckSidKey(string appSid, string apiKey)
78-
{
79-
var ssSid = appSid.Split('-');
80-
var ssKey = apiKey.Split('-');
81-
return ssSid.Length == 5 && ssKey.Length == 1;
82-
}
83-
8471
/// <summary>
8572
/// Default creation of exceptions for a given method name and response object
8673
/// </summary>

0 commit comments

Comments
 (0)