Skip to content

Commit 0faaa45

Browse files
committed
Adding changes to OAuthApi to keep in line with changes in mustache files
1 parent ea2c560 commit 0faaa45

File tree

1 file changed

+93
-39
lines changed

1 file changed

+93
-39
lines changed

Api/OAuthApi.cs

Lines changed: 93 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using RestSharp;
66
using CyberSource.Client;
77
using CyberSource.Model;
8+
using NLog;
9+
using AuthenticationSdk.util;
810

911
namespace CyberSource.Api
1012
{
@@ -54,22 +56,28 @@ public interface IOAuthApi : IApiAccessor
5456
/// </summary>
5557
public partial class OAuthApi : IOAuthApi
5658
{
57-
private CyberSource.Client.ExceptionFactory _exceptionFactory = (name, response) => null;
59+
private static Logger logger;
60+
private ExceptionFactory _exceptionFactory = (name, response) => null;
5861

5962
/// <summary>
6063
/// Initializes a new instance of the <see cref="OAuthApi"/> class.
6164
/// </summary>
6265
/// <returns></returns>
6366
public OAuthApi(String basePath)
6467
{
65-
this.Configuration = new Configuration(new ApiClient(basePath));
68+
Configuration = new Configuration(new ApiClient(basePath));
6669

67-
ExceptionFactory = CyberSource.Client.Configuration.DefaultExceptionFactory;
70+
ExceptionFactory = Configuration.DefaultExceptionFactory;
6871

6972
// ensure API client has configuration ready
7073
if (Configuration.ApiClient.Configuration == null)
7174
{
72-
this.Configuration.ApiClient.Configuration = this.Configuration;
75+
Configuration.ApiClient.Configuration = Configuration;
76+
}
77+
78+
if (logger == null)
79+
{
80+
logger = LogManager.GetCurrentClassLogger();
7381
}
7482
}
7583

@@ -82,30 +90,35 @@ public OAuthApi(String basePath)
8290
public OAuthApi(Configuration configuration = null)
8391
{
8492
if (configuration == null) // use the default one in Configuration
85-
this.Configuration = Configuration.Default;
93+
Configuration = Configuration.Default;
8694
else
87-
this.Configuration = configuration;
95+
Configuration = configuration;
8896

89-
ExceptionFactory = CyberSource.Client.Configuration.DefaultExceptionFactory;
97+
ExceptionFactory = Configuration.DefaultExceptionFactory;
9098

91-
this.Configuration.ApiClient.Configuration = this.Configuration;
99+
Configuration.ApiClient.Configuration = Configuration;
100+
101+
if (logger == null)
102+
{
103+
logger = LogManager.GetCurrentClassLogger();
104+
}
92105
}
93106

94107
/// <summary>
95108
/// Gets the base path of the API client.
96109
/// </summary>
97110
/// <value>The base path</value>
98-
public String GetBasePath()
111+
public string GetBasePath()
99112
{
100-
return this.Configuration.ApiClient.RestClient.BaseUrl.ToString();
113+
return Configuration.ApiClient.RestClient.BaseUrl.ToString();
101114
}
102115

103116
/// <summary>
104117
/// Sets the base path of the API client.
105118
/// </summary>
106119
/// <value>The base path</value>
107120
[Obsolete("SetBasePath is deprecated, please do 'Configuration.ApiClient = new ApiClient(\"http://new-path\")' instead.")]
108-
public void SetBasePath(String basePath)
121+
public void SetBasePath(string basePath)
109122
{
110123
// do nothing
111124
}
@@ -125,6 +138,7 @@ public CyberSource.Client.ExceptionFactory ExceptionFactory
125138
{
126139
if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1)
127140
{
141+
logger.Error("InvalidOperationException : Multicast delegate for ExceptionFactory is unsupported.");
128142
throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported.");
129143
}
130144
return _exceptionFactory;
@@ -137,9 +151,9 @@ public CyberSource.Client.ExceptionFactory ExceptionFactory
137151
/// </summary>
138152
/// <returns>Dictionary of HTTP header</returns>
139153
[Obsolete("DefaultHeader is deprecated, please use Configuration.DefaultHeader instead.")]
140-
public Dictionary<String, String> DefaultHeader()
154+
public Dictionary<string, string> DefaultHeader()
141155
{
142-
return this.Configuration.DefaultHeader;
156+
return Configuration.DefaultHeader;
143157
}
144158

145159
/// <summary>
@@ -151,7 +165,7 @@ public Dictionary<String, String> DefaultHeader()
151165
[Obsolete("AddDefaultHeader is deprecated, please use Configuration.AddDefaultHeader instead.")]
152166
public void AddDefaultHeader(string key, string value)
153167
{
154-
this.Configuration.AddDefaultHeader(key, value);
168+
Configuration.AddDefaultHeader(key, value);
155169
}
156170

157171

@@ -160,7 +174,9 @@ public void AddDefaultHeader(string key, string value)
160174
/// <returns>AccessTokenResponse</returns>
161175
public AccessTokenResponse PostAccessTokenRequest(CreateAccessTokenRequest createAccessTokenRequest)
162176
{
177+
logger.Debug("CALLING API \"PostAccessTokenRequest\" STARTED");
163178
ApiResponse<AccessTokenResponse> localVarResponse = PostAccessTokenRequestWithHttpInfo(createAccessTokenRequest);
179+
logger.Debug("CALLING API \"PostAccessTokenRequest\" ENDED");
164180
return localVarResponse.Data;
165181
}
166182

@@ -172,29 +188,34 @@ public ApiResponse<AccessTokenResponse> PostAccessTokenRequestWithHttpInfo(Creat
172188
{
173189
// verify the required parameter 'createAccessTokenRequest' is set
174190
if (createAccessTokenRequest == null)
191+
{
192+
logger.Error("ApiException : Missing required parameter 'createAccessTokenRequest' when calling OAuthApi->PostAccessTokenRequest");
175193
throw new ApiException(400, "Missing required parameter 'createAccessTokenRequest' when calling OAuthApi->PostAccessTokenRequest");
194+
}
176195

177196
var localVarPath = $"/oauth2/v3/token";
178-
var localVarPathParams = new Dictionary<String, String>();
179-
var localVarQueryParams = new Dictionary<String, String>();
180-
var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader);
181-
var localVarFormParams = new Dictionary<String, String>();
182-
var localVarFileParams = new Dictionary<String, FileParameter>();
183-
Object localVarPostBody = null;
197+
var localVarPathParams = new Dictionary<string, string>();
198+
var localVarQueryParams = new Dictionary<string, string>();
199+
var localVarHeaderParams = new Dictionary<string, string>(Configuration.DefaultHeader);
200+
var localVarFormParams = new Dictionary<string, string>();
201+
var localVarFileParams = new Dictionary<string, FileParameter>();
202+
object localVarPostBody = null;
184203

185204
// to determine the Content-Type header
186-
String[] localVarHttpContentTypes = new String[] {
205+
string[] localVarHttpContentTypes = new string[] {
187206
"application/x-www-form-urlencoded"
188207
};
189-
String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);
208+
string localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);
190209

191210
// to determine the Accept header
192-
String[] localVarHttpHeaderAccepts = new String[] {
211+
string[] localVarHttpHeaderAccepts = new string[] {
193212
"application/json"
194213
};
195-
String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);
214+
string localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);
196215
if (localVarHttpHeaderAccept != null)
216+
{
197217
localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
218+
}
198219

199220
if (createAccessTokenRequest != null && createAccessTokenRequest.GetType() != typeof(byte[]))
200221
{
@@ -205,18 +226,31 @@ public ApiResponse<AccessTokenResponse> PostAccessTokenRequestWithHttpInfo(Creat
205226
localVarPostBody = createAccessTokenRequest; // byte array
206227
}
207228

229+
if (LogUtility.IsMaskingEnabled(logger))
230+
{
231+
logger.Debug($"HTTP Request Body :\n{LogUtility.MaskSensitiveData(localVarPostBody.ToString())}");
232+
}
233+
else
234+
{
235+
logger.Debug($"HTTP Request Body :\n{localVarPostBody}");
236+
}
237+
208238

209239
// make the HTTP request
210-
IRestResponse localVarResponse = (IRestResponse)Configuration.ApiClient.CallApi(localVarPath,
240+
IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath,
211241
Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
212242
localVarPathParams, localVarHttpContentType);
213243

214-
int localVarStatusCode = (int)localVarResponse.StatusCode;
244+
int localVarStatusCode = (int) localVarResponse.StatusCode;
215245

216246
if (ExceptionFactory != null)
217247
{
218248
Exception exception = ExceptionFactory("PostAccessTokenRequest", localVarResponse);
219-
if (exception != null) throw exception;
249+
if (exception != null)
250+
{
251+
logger.Error($"Exception : {exception.Message}");
252+
throw exception;
253+
}
220254
}
221255

222256
return new ApiResponse<AccessTokenResponse>(localVarStatusCode,
@@ -229,7 +263,9 @@ public ApiResponse<AccessTokenResponse> PostAccessTokenRequestWithHttpInfo(Creat
229263
/// <returns>Task of AccessTokenResponse</returns>
230264
public async System.Threading.Tasks.Task<AccessTokenResponse> PostAccessTokenRequestAsync(CreateAccessTokenRequest createAccessTokenRequest)
231265
{
266+
logger.Debug("CALLING API \"PostAccessTokenRequestAsync\" STARTED");
232267
ApiResponse<AccessTokenResponse> localVarResponse = await PostAccessTokenRequestAsyncWithHttpInfo(createAccessTokenRequest);
268+
logger.Debug("CALLING API \"PostAccessTokenRequestAsync\" STARTED");
233269
return localVarResponse.Data;
234270

235271
}
@@ -242,30 +278,35 @@ public async System.Threading.Tasks.Task<ApiResponse<AccessTokenResponse>> PostA
242278
{
243279
// verify the required parameter 'createAccessTokenRequest' is set
244280
if (createAccessTokenRequest == null)
281+
{
282+
logger.Error("ApiException : Missing required parameter 'createAccessTokenRequest' when calling OAuthApi->PostAccessTokenRequest");
245283
throw new ApiException(400, "Missing required parameter 'createAccessTokenRequest' when calling OAuthApi->PostAccessTokenRequest");
284+
}
246285

247286
var localVarPath = $"/oauth2/v3/token";
248-
var localVarPathParams = new Dictionary<String, String>();
249-
var localVarQueryParams = new Dictionary<String, String>();
250-
var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader);
251-
var localVarFormParams = new Dictionary<String, String>();
252-
var localVarFileParams = new Dictionary<String, FileParameter>();
253-
Object localVarPostBody = null;
287+
var localVarPathParams = new Dictionary<string, string>();
288+
var localVarQueryParams = new Dictionary<string, string>();
289+
var localVarHeaderParams = new Dictionary<string, string>(Configuration.DefaultHeader);
290+
var localVarFormParams = new Dictionary<string, string>();
291+
var localVarFileParams = new Dictionary<string, FileParameter>();
292+
object localVarPostBody = null;
254293

255294
// to determine the Content-Type header
256-
String[] localVarHttpContentTypes = new String[] {
295+
string[] localVarHttpContentTypes = new string[] {
257296
"application/x-www-form-urlencoded"
258297
};
259-
String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);
298+
string localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);
260299

261300
// to determine the Accept header
262-
String[] localVarHttpHeaderAccepts = new String[] {
301+
string[] localVarHttpHeaderAccepts = new string[] {
263302
"application/json"
264303
};
265-
String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);
304+
string localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);
266305
if (localVarHttpHeaderAccept != null)
306+
{
267307
localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
268-
308+
}
309+
269310
if (createAccessTokenRequest != null && createAccessTokenRequest.GetType() != typeof(byte[]))
270311
{
271312
localVarPostBody = Configuration.ApiClient.Serialize(createAccessTokenRequest); // http body (model) parameter
@@ -275,6 +316,15 @@ public async System.Threading.Tasks.Task<ApiResponse<AccessTokenResponse>> PostA
275316
localVarPostBody = createAccessTokenRequest; // byte array
276317
}
277318

319+
if (LogUtility.IsMaskingEnabled(logger))
320+
{
321+
logger.Debug($"HTTP Request Body :\n{LogUtility.MaskSensitiveData(localVarPostBody.ToString())}");
322+
}
323+
else
324+
{
325+
logger.Debug($"HTTP Request Body :\n{localVarPostBody}");
326+
}
327+
278328

279329
// make the HTTP request
280330
IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
@@ -286,7 +336,11 @@ public async System.Threading.Tasks.Task<ApiResponse<AccessTokenResponse>> PostA
286336
if (ExceptionFactory != null)
287337
{
288338
Exception exception = ExceptionFactory("PostAccessTokenRequest", localVarResponse);
289-
if (exception != null) throw exception;
339+
if (exception != null)
340+
{
341+
logger.Error($"Exception : {exception.Message}");
342+
throw exception;
343+
}
290344
}
291345

292346
return new ApiResponse<AccessTokenResponse>(localVarStatusCode,

0 commit comments

Comments
 (0)