-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBatchDeleteResult.cs
More file actions
46 lines (39 loc) · 1.66 KB
/
Copy pathBatchDeleteResult.cs
File metadata and controls
46 lines (39 loc) · 1.66 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
using System.Collections.Generic;
using System.Text.Json.Nodes;
using Apify.Client.Internal;
namespace Apify.Client.Models;
/// <summary>
/// The result of a batch request-delete: the requests that were successfully removed and the ones that
/// could not be (and can be retried).
/// </summary>
public sealed class BatchDeleteResult
{
private BatchDeleteResult(IReadOnlyList<RequestQueueRequest> processed, IReadOnlyList<RequestQueueRequest> unprocessed)
{
ProcessedRequests = processed;
UnprocessedRequests = unprocessed;
}
/// <summary>Builds a result from the decoded response object.</summary>
/// <param name="data">The decoded response object.</param>
public static BatchDeleteResult FromData(JsonNode? data)
{
var obj = JsonValues.AsObject(data);
return new BatchDeleteResult(Hydrate(obj, "processedRequests"), Hydrate(obj, "unprocessedRequests"));
}
private static List<RequestQueueRequest> Hydrate(JsonObject obj, string key)
{
var items = new List<RequestQueueRequest>();
if (obj.TryGetPropertyValue(key, out var node) && node is JsonArray array)
{
foreach (var item in array)
{
items.Add(RequestQueueRequest.FromJsonObject(item as JsonObject ?? new JsonObject()));
}
}
return items;
}
/// <summary>The requests that were successfully deleted from the queue.</summary>
public IReadOnlyList<RequestQueueRequest> ProcessedRequests { get; }
/// <summary>The requests that failed to be deleted and can be retried.</summary>
public IReadOnlyList<RequestQueueRequest> UnprocessedRequests { get; }
}