Skip to content

Commit bfa74e8

Browse files
committed
Adding a missed 'else' and Auto Property for the file name, to the ApiClient
1 parent 5f74993 commit bfa74e8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

generator/cybersource-csharp-template/ApiClient.mustache

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ namespace {{packageName}}.Client
115115
/// <value>An instance of the RestClient</value>
116116
public RestClient RestClient { get; set; }
117117

118+
/// <summary>
119+
/// Gets or sets the file name, in which the response to be downloaded.
120+
/// </summary>
121+
/// <value>An instance of the Configuration.</value>
122+
public string DownloadReponseFileName { get; set; }
123+
118124
// Creates and sets up a RestRequest prior to a call.
119125
private RestRequest PrepareRequest(
120126
String path, {{^netStandard}}RestSharp.{{/netStandard}}Method method, Dictionary<String, String> queryParams, Object postBody,
@@ -331,7 +337,7 @@ namespace {{packageName}}.Client
331337
String path, {{^netStandard}}RestSharp.{{/netStandard}}Method method, Dictionary<String, String> queryParams, Object postBody,
332338
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
333339
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams,
334-
String contentType, bool downloadResponseAsFile = false)
340+
String contentType)
335341
{
336342
//declared separately to handle both regular call and download file calls
337343
int httpResponseStatusCode;
@@ -341,7 +347,7 @@ namespace {{packageName}}.Client
341347
var response = new RestResponse();
342348
343349
//check if the Response is to be downloaded as a file, this value to be set by the calling API class
344-
if (!downloadResponseAsFile)
350+
if (string.IsNullOrEmpty(DownloadReponseFileName))
345351
{
346352
var request = PrepareRequest(
347353
path, method, queryParams, postBody, headerParams, formParams, fileParams,
@@ -374,10 +380,8 @@ namespace {{packageName}}.Client
374380
{{/netStandard}}
375381
InterceptResponse(request, response);
376382
}
383+
else
377384
{
378-
//setting file name
379-
string downloadReponseFileName = path.Split('/')[path.Split('/').Length - 1] + "_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".csv";
380-
381385
//prepare a HttpWebRequest request object
382386
var requestT = PrepareHttpWebRequest(path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, contentType);
383387
@@ -388,7 +392,7 @@ namespace {{packageName}}.Client
388392
//setting high timeout to accomodate large files till 2GB, need to revisit for a dynamic approach
389393
responseStream.ReadTimeout = 8000000;
390394
responseStream.WriteTimeout = 9000000;
391-
using (Stream fileStream = File.OpenWrite(@downloadReponseFileName))
395+
using (Stream fileStream = File.OpenWrite(@DownloadReponseFileName))
392396
{
393397
byte[] buffer = new byte[4096];
394398
int bytesRead = responseStream.Read(buffer, 0, 4096);
@@ -410,7 +414,7 @@ namespace {{packageName}}.Client
410414
response.StatusCode = responseT.StatusCode;
411415
if (responseT.StatusCode == HttpStatusCode.OK)
412416
{
413-
response.Content = "Custom Message: Response downloaded to file " + downloadReponseFileName;
417+
response.Content = "Custom Message: Response downloaded to file " + DownloadReponseFileName;
414418
}
415419
else if (responseT.StatusCode == HttpStatusCode.NotFound)
416420
{

0 commit comments

Comments
 (0)