Skip to content

Commit 232609c

Browse files
committed
feat: improve upload methods
1 parent 103b6c3 commit 232609c

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

Fossology.Rest.Dotnet/FossologyClientUpload.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ namespace Fossology.Rest.Dotnet
2525

2626
using RestSharp;
2727

28-
using Tethys.Logging;
29-
3028
using JsonSerializer = RestSharp.Serialization.Json.JsonSerializer;
3129

3230
/// <summary>
@@ -277,20 +275,29 @@ public bool IsUploadUnpacked(int id)
277275
NullValueHandling = NullValueHandling.Ignore,
278276
});
279277

280-
return jobs.All(job => job.Status == "Completed");
278+
return jobs != null && jobs.All(job => job.Status == "Completed");
281279
} // IsUploadUnpacked()
282280

283281
/// <summary>
284282
/// Gets the upload with the specified id.
285283
/// </summary>
286284
/// <param name="id">The identifier.</param>
285+
/// <param name="groupName">The group name to choose.</param>
287286
/// <returns>A <see cref="Upload"/> object.</returns>
288-
public Upload GetUpload(int id)
287+
public Upload GetUpload(int id, string groupName = "")
289288
{
290289
Log.Debug($"Getting upload {id}...");
291290

292-
var response = this.api.Get(this.Url + $"/uploads/{id}", true);
291+
var request = new RestRequest(this.Url + $"/uploads/{id}", Method.GET);
292+
request.RequestFormat = DataFormat.Json;
293+
request.JsonSerializer = new JsonSerializer();
294+
request.Parameters.Clear();
295+
if (!string.IsNullOrEmpty(groupName))
296+
{
297+
request.AddHeader("groupName", groupName);
298+
} // if
293299

300+
var response = this.api.Execute(request);
294301
if (response.StatusCode == HttpStatusCode.OK)
295302
{
296303
var upload = JsonConvert.DeserializeObject<Upload>(
@@ -316,12 +323,22 @@ public Upload GetUpload(int id)
316323
/// Gets the summary for the upload with the specified id.
317324
/// </summary>
318325
/// <param name="id">The identifier.</param>
326+
/// <param name="groupName">The group name to choose.</param>
319327
/// <returns>A <see cref="UploadSummary"/> object.</returns>
320-
public UploadSummary GetUploadSummary(int id)
328+
public UploadSummary GetUploadSummary(int id, string groupName = "")
321329
{
322330
Log.Debug($"Getting upload summary {id}...");
323331

324-
var response = this.api.Get(this.Url + $"/uploads/{id}/summary");
332+
var request = new RestRequest(this.Url + $"/uploads/{id}/summary", Method.GET);
333+
request.RequestFormat = DataFormat.Json;
334+
request.JsonSerializer = new JsonSerializer();
335+
request.Parameters.Clear();
336+
if (!string.IsNullOrEmpty(groupName))
337+
{
338+
request.AddHeader("groupName", groupName);
339+
} // if
340+
341+
var response = this.api.Execute(request);
325342
var summary = JsonConvert.DeserializeObject<UploadSummary>(
326343
response.Content,
327344
new JsonSerializerSettings

0 commit comments

Comments
 (0)