Skip to content

Commit f06f3e8

Browse files
committed
add get document group info
1 parent 6f40fed commit f06f3e8

File tree

7 files changed

+284
-2
lines changed

7 files changed

+284
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using SignNow.Net.Model.Requests;
4+
5+
namespace UnitTests.Requests
6+
{
7+
[TestClass]
8+
public class LimitOffsetOptionsTest
9+
{
10+
[TestMethod]
11+
public void BuildQuery()
12+
{
13+
var emptyOptions = new LimitOffsetOptions();
14+
var fullOptions = new LimitOffsetOptions
15+
{
16+
Limit = 2,
17+
Offset = 3
18+
};
19+
20+
Assert.AreEqual(String.Empty, emptyOptions.ToQueryString());
21+
Assert.AreEqual("limit=2&offset=3", fullOptions.ToQueryString());
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Linq;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using SignNow.Net.Model.Responses;
4+
5+
namespace UnitTests.Responses
6+
{
7+
[TestClass]
8+
public class DocumentGroupsResponseTests
9+
{
10+
[TestMethod]
11+
public void ShouldProperDeserialize()
12+
{
13+
var jsonResponse = @"{
14+
""document_groups"": [
15+
{
16+
""folder_id"": null,
17+
""last_updated"": ""1729535107"",
18+
""group_id"": ""03c74b3083f34ebf8ef40a3039dfb32c85a08333"",
19+
""group_name"": ""CreateDocumentGroupTest"",
20+
""invite_id"": null,
21+
""invite_status"": null,
22+
""documents"": [
23+
{
24+
""id"": ""66974a4b421546a69167ba342d1ae94af56ce333"",
25+
""name"": ""ForDocumentGroupFile-1"",
26+
""page_count"": 1,
27+
""thumbnail"": {
28+
""small"": ""https://api-eval.signnow.com/document/66974a4b421546a69167ba342d1ae94af56ce333/thumbnail?size=small"",
29+
""medium"": ""https://api-eval.signnow.com/document/66974a4b421546a69167ba342d1ae94af56ce333/thumbnail?size=medium"",
30+
""large"": ""https://api-eval.signnow.com/document/66974a4b421546a69167ba342d1ae94af56ce333/thumbnail?size=large""
31+
},
32+
""roles"": [],
33+
""settings"": {
34+
""advanced_signing_flow"": false
35+
},
36+
""has_credit_card_number"": false
37+
}
38+
],
39+
""is_full_declined"": false,
40+
""is_embedded"": false,
41+
""freeform_invite"": {
42+
""id"": null
43+
},
44+
""state"": ""created"",
45+
""has_guest_signer"": false,
46+
""has_signing_group"": false
47+
}
48+
],
49+
""document_group_total_count"": 1
50+
}";
51+
52+
var response = TestUtils.DeserializeFromJson<DocumentGroupsResponse>(jsonResponse);
53+
54+
Assert.AreEqual(1, response.TotalCount);
55+
Assert.AreEqual(1, response.Data.Count);
56+
57+
var group = response.Data.First();
58+
Assert.AreEqual("03c74b3083f34ebf8ef40a3039dfb32c85a08333", group.GroupId);
59+
Assert.AreEqual("CreateDocumentGroupTest", group.Name);
60+
Assert.AreEqual(1, group.Documents.First().Pages);
61+
Assert.AreEqual("advanced_signing_flow", group.Documents.First().Settings.First().Key);
62+
Assert.AreEqual(false, group.Documents.First().Settings.First().Value);
63+
}
64+
}
65+
}

Diff for: SignNow.Net/Interfaces/IDocumentGroup.cs

+9
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,14 @@ public interface IDocumentGroup
2828
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
2929
/// <returns></returns>
3030
Task<DocumentGroupInfoResponse> GetDocumentGroupInfoAsync(string documentGroupId, CancellationToken cancellationToken = default);
31+
32+
/// <summary>
33+
/// Returns back all document groups the user owns.
34+
/// The call is paginated by last_updated, so offset and limit query parameters are required
35+
/// </summary>
36+
/// <param name="options">Limit and offset query options</param>
37+
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
38+
/// <returns></returns>
39+
Task<DocumentGroupsResponse> GetDocumentGroupsAsync(IQueryToString options, CancellationToken cancellationToken = default);
3140
}
3241
}

Diff for: SignNow.Net/Model/Requests/LimitOffsetOptions.cs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using SignNow.Net.Interfaces;
4+
5+
namespace SignNow.Net.Model.Requests
6+
{
7+
public class LimitOffsetOptions : IQueryToString
8+
{
9+
/// <summary>
10+
/// Limit of the items in response.
11+
/// </summary>
12+
public int? Limit { get; set; }
13+
14+
/// <summary>
15+
/// Offset size for pagination.
16+
/// </summary>
17+
public int? Offset { get; set; }
18+
19+
public string ToQueryString()
20+
{
21+
if (Limit == null && Offset == null)
22+
{
23+
return String.Empty;
24+
}
25+
26+
var options = new List<string>();
27+
28+
if (Limit != null)
29+
{
30+
options.Add($"limit={Limit}");
31+
}
32+
33+
if (Offset != null)
34+
{
35+
options.Add($"offset={Offset}");
36+
}
37+
38+
return String.Join("&", options);
39+
}
40+
}
41+
}

Diff for: SignNow.Net/Model/Responses/DocumentGroupInfoResponse.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ public class GroupDocumentsInfo : IdResponse
137137
[JsonProperty("thumbnail")]
138138
public Thumbnail Thumbnail { get; set; }
139139

140+
/// <summary>
141+
/// Document settings.
142+
/// </summary>
143+
[JsonProperty("settings", NullValueHandling = NullValueHandling.Ignore)]
144+
public IReadOnlyDictionary<string, object> Settings { get; set; }
145+
140146
/// <summary>
141147
/// An ID of document origin.
142148
/// </summary>
@@ -158,13 +164,13 @@ public class GroupDocumentsInfo : IdResponse
158164
/// <summary>
159165
/// Is the document can be removed from document group.
160166
/// </summary>
161-
[JsonProperty("allow_to_remove")]
167+
[JsonProperty("allow_to_remove", NullValueHandling = NullValueHandling.Ignore)]
162168
public bool IsAllowedToRemove { get; set; }
163169
}
164170

165171
public class FreeFormInviteInfo : IdResponse
166172
{
167-
[JsonProperty("last_id")]
173+
[JsonProperty("last_id", NullValueHandling = NullValueHandling.Ignore)]
168174
public string LastId { get; set; }
169175
}
170176
}
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using SignNow.Net.Internal.Helpers.Converters;
5+
6+
namespace SignNow.Net.Model.Responses
7+
{
8+
public class DocumentGroupsResponse
9+
{
10+
[JsonProperty("document_groups")]
11+
public IReadOnlyList<DocumentGroups> Data { get; set; }
12+
13+
/// <summary>
14+
/// Total documents count in document group.
15+
/// </summary>
16+
[JsonProperty("document_group_total_count")]
17+
public int TotalCount { get; set; }
18+
}
19+
20+
public class DocumentGroups
21+
{
22+
/// <summary>
23+
/// An ID of folder with document group.
24+
/// </summary>
25+
[JsonProperty("folder_id")]
26+
public string FolderId { get; set; }
27+
28+
/// <summary>
29+
/// Timestamp of document group update.
30+
/// </summary>
31+
[JsonProperty("last_updated")]
32+
[JsonConverter(typeof(UnixTimeStampJsonConverter))]
33+
public DateTime Updated { get; set; }
34+
35+
/// <summary>
36+
/// Document Group name.
37+
/// </summary>
38+
[JsonProperty("group_name")]
39+
public string Name { get; set; }
40+
41+
/// <summary>
42+
/// An ID of document group.
43+
/// </summary>
44+
[JsonProperty("group_id")]
45+
public string GroupId { get; set; }
46+
47+
/// <summary>
48+
/// Identity of invite for Document Group.
49+
/// </summary>
50+
[JsonProperty("invite_id")]
51+
public string InviteId { get; set; }
52+
53+
/// <summary>
54+
/// Invite status
55+
/// </summary>
56+
[JsonProperty("invite_status")]
57+
public string InviteStatus { get; set; }
58+
59+
[JsonProperty("documents")]
60+
public IReadOnlyList<GroupDocumentsInfo> Documents { get; set; }
61+
62+
/// <summary>
63+
/// Is the document full declined.
64+
/// </summary>
65+
[JsonProperty("is_full_declined")]
66+
public bool IsFullDeclined { get; set; }
67+
68+
/// <summary>
69+
/// Is the document embedded.
70+
/// </summary>
71+
[JsonProperty("is_embedded")]
72+
public bool IsEmbedded { get; set; }
73+
74+
/// <summary>
75+
/// Freeform invite info.
76+
/// </summary>
77+
[JsonProperty("freeform_invite")]
78+
public FreeFormInviteInfo FreeFormInvite { get; set; }
79+
80+
/// <summary>
81+
/// Document Group state.
82+
/// </summary>
83+
[JsonProperty("state")]
84+
public string State { get; set; }
85+
86+
/// <summary>
87+
/// Is the document has guest signer.
88+
/// </summary>
89+
[JsonProperty("has_guest_signer")]
90+
public bool HasGuestSigner { get; set; }
91+
92+
/// <summary>
93+
/// Is the document has signing group.
94+
/// </summary>
95+
[JsonProperty("has_signing_group")]
96+
public bool HasSigningGroup { get; set; }
97+
}
98+
}

Diff for: SignNow.Net/Service/DocumentGroupService.cs

+39
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using SignNow.Net.Internal.Extensions;
77
using SignNow.Net.Internal.Requests;
88
using SignNow.Net.Model;
9+
using SignNow.Net.Model.Requests;
910
using SignNow.Net.Model.Responses;
1011

1112
namespace SignNow.Net.Service
@@ -52,5 +53,43 @@ public async Task<DocumentGroupInfoResponse> GetDocumentGroupInfoAsync(string do
5253
.RequestAsync<DocumentGroupInfoResponse>(requestOption, cancellationToken)
5354
.ConfigureAwait(false);
5455
}
56+
57+
/// <inheritdoc />
58+
/// <exception cref="ArgumentException">Limit must be greater than 0 but less than or equal to 50.</exception>
59+
/// <exception cref="ArgumentException">Offset must be 0 or greater.</exception>
60+
public async Task<DocumentGroupsResponse> GetDocumentGroupsAsync(IQueryToString options, CancellationToken cancellationToken = default)
61+
{
62+
if (options.GetType() != typeof(LimitOffsetOptions))
63+
{
64+
throw new ArgumentException("Query params does not have 'limit' and 'offset' options. Use \"LimitOffsetOptions\" class.", nameof(options));
65+
}
66+
67+
var opts = (LimitOffsetOptions)options;
68+
if (opts.Limit <= 0 || opts.Limit > 50)
69+
{
70+
throw new ArgumentException("Limit must be greater than 0 but less than or equal to 50.");
71+
}
72+
73+
if (opts.Offset < 0)
74+
{
75+
throw new ArgumentException("Offset must be 0 or greater.");
76+
}
77+
78+
var query = options?.ToQueryString();
79+
var filters = string.IsNullOrEmpty(query)
80+
? string.Empty
81+
: $"?{query}";
82+
83+
Token.TokenType = TokenType.Bearer;
84+
var requestOptions = new GetHttpRequestOptions
85+
{
86+
RequestUrl = new Uri(ApiBaseUrl, $"/user/documentgroups{filters}"),
87+
Token = Token
88+
};
89+
90+
return await SignNowClient
91+
.RequestAsync<DocumentGroupsResponse>(requestOptions, cancellationToken)
92+
.ConfigureAwait(false);
93+
}
5594
}
5695
}

0 commit comments

Comments
 (0)