Skip to content

Commit

Permalink
add get document group info
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNDRmac committed Oct 22, 2024
1 parent 6f40fed commit f06f3e8
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 2 deletions.
24 changes: 24 additions & 0 deletions SignNow.Net.Test/UnitTests/Requests/LimitOffsetOptionsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SignNow.Net.Model.Requests;

namespace UnitTests.Requests
{
[TestClass]
public class LimitOffsetOptionsTest
{
[TestMethod]
public void BuildQuery()
{
var emptyOptions = new LimitOffsetOptions();
var fullOptions = new LimitOffsetOptions
{
Limit = 2,
Offset = 3
};

Assert.AreEqual(String.Empty, emptyOptions.ToQueryString());
Assert.AreEqual("limit=2&offset=3", fullOptions.ToQueryString());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SignNow.Net.Model.Responses;

namespace UnitTests.Responses
{
[TestClass]
public class DocumentGroupsResponseTests
{
[TestMethod]
public void ShouldProperDeserialize()
{
var jsonResponse = @"{
""document_groups"": [
{
""folder_id"": null,
""last_updated"": ""1729535107"",
""group_id"": ""03c74b3083f34ebf8ef40a3039dfb32c85a08333"",
""group_name"": ""CreateDocumentGroupTest"",
""invite_id"": null,
""invite_status"": null,
""documents"": [
{
""id"": ""66974a4b421546a69167ba342d1ae94af56ce333"",
""name"": ""ForDocumentGroupFile-1"",
""page_count"": 1,
""thumbnail"": {
""small"": ""https://api-eval.signnow.com/document/66974a4b421546a69167ba342d1ae94af56ce333/thumbnail?size=small"",
""medium"": ""https://api-eval.signnow.com/document/66974a4b421546a69167ba342d1ae94af56ce333/thumbnail?size=medium"",
""large"": ""https://api-eval.signnow.com/document/66974a4b421546a69167ba342d1ae94af56ce333/thumbnail?size=large""
},
""roles"": [],
""settings"": {
""advanced_signing_flow"": false
},
""has_credit_card_number"": false
}
],
""is_full_declined"": false,
""is_embedded"": false,
""freeform_invite"": {
""id"": null
},
""state"": ""created"",
""has_guest_signer"": false,
""has_signing_group"": false
}
],
""document_group_total_count"": 1
}";

var response = TestUtils.DeserializeFromJson<DocumentGroupsResponse>(jsonResponse);

Assert.AreEqual(1, response.TotalCount);
Assert.AreEqual(1, response.Data.Count);

var group = response.Data.First();
Assert.AreEqual("03c74b3083f34ebf8ef40a3039dfb32c85a08333", group.GroupId);
Assert.AreEqual("CreateDocumentGroupTest", group.Name);
Assert.AreEqual(1, group.Documents.First().Pages);
Assert.AreEqual("advanced_signing_flow", group.Documents.First().Settings.First().Key);
Assert.AreEqual(false, group.Documents.First().Settings.First().Value);
}
}
}
9 changes: 9 additions & 0 deletions SignNow.Net/Interfaces/IDocumentGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ public interface IDocumentGroup
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
/// <returns></returns>
Task<DocumentGroupInfoResponse> GetDocumentGroupInfoAsync(string documentGroupId, CancellationToken cancellationToken = default);

/// <summary>
/// Returns back all document groups the user owns.
/// The call is paginated by last_updated, so offset and limit query parameters are required
/// </summary>
/// <param name="options">Limit and offset query options</param>
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
/// <returns></returns>
Task<DocumentGroupsResponse> GetDocumentGroupsAsync(IQueryToString options, CancellationToken cancellationToken = default);
}
}
41 changes: 41 additions & 0 deletions SignNow.Net/Model/Requests/LimitOffsetOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using SignNow.Net.Interfaces;

namespace SignNow.Net.Model.Requests
{
public class LimitOffsetOptions : IQueryToString
{
/// <summary>
/// Limit of the items in response.
/// </summary>
public int? Limit { get; set; }

/// <summary>
/// Offset size for pagination.
/// </summary>
public int? Offset { get; set; }

public string ToQueryString()
{
if (Limit == null && Offset == null)
{
return String.Empty;
}

var options = new List<string>();

if (Limit != null)
{
options.Add($"limit={Limit}");
}

if (Offset != null)
{
options.Add($"offset={Offset}");
}

return String.Join("&", options);
}
}
}
10 changes: 8 additions & 2 deletions SignNow.Net/Model/Responses/DocumentGroupInfoResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ public class GroupDocumentsInfo : IdResponse
[JsonProperty("thumbnail")]
public Thumbnail Thumbnail { get; set; }

/// <summary>
/// Document settings.
/// </summary>
[JsonProperty("settings", NullValueHandling = NullValueHandling.Ignore)]
public IReadOnlyDictionary<string, object> Settings { get; set; }

/// <summary>
/// An ID of document origin.
/// </summary>
Expand All @@ -158,13 +164,13 @@ public class GroupDocumentsInfo : IdResponse
/// <summary>
/// Is the document can be removed from document group.
/// </summary>
[JsonProperty("allow_to_remove")]
[JsonProperty("allow_to_remove", NullValueHandling = NullValueHandling.Ignore)]
public bool IsAllowedToRemove { get; set; }
}

public class FreeFormInviteInfo : IdResponse
{
[JsonProperty("last_id")]
[JsonProperty("last_id", NullValueHandling = NullValueHandling.Ignore)]
public string LastId { get; set; }
}
}
98 changes: 98 additions & 0 deletions SignNow.Net/Model/Responses/DocumentGroupsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using SignNow.Net.Internal.Helpers.Converters;

namespace SignNow.Net.Model.Responses
{
public class DocumentGroupsResponse
{
[JsonProperty("document_groups")]
public IReadOnlyList<DocumentGroups> Data { get; set; }

/// <summary>
/// Total documents count in document group.
/// </summary>
[JsonProperty("document_group_total_count")]
public int TotalCount { get; set; }
}

public class DocumentGroups
{
/// <summary>
/// An ID of folder with document group.
/// </summary>
[JsonProperty("folder_id")]
public string FolderId { get; set; }

/// <summary>
/// Timestamp of document group update.
/// </summary>
[JsonProperty("last_updated")]
[JsonConverter(typeof(UnixTimeStampJsonConverter))]
public DateTime Updated { get; set; }

/// <summary>
/// Document Group name.
/// </summary>
[JsonProperty("group_name")]
public string Name { get; set; }

/// <summary>
/// An ID of document group.
/// </summary>
[JsonProperty("group_id")]
public string GroupId { get; set; }

/// <summary>
/// Identity of invite for Document Group.
/// </summary>
[JsonProperty("invite_id")]
public string InviteId { get; set; }

/// <summary>
/// Invite status
/// </summary>
[JsonProperty("invite_status")]
public string InviteStatus { get; set; }

[JsonProperty("documents")]
public IReadOnlyList<GroupDocumentsInfo> Documents { get; set; }

/// <summary>
/// Is the document full declined.
/// </summary>
[JsonProperty("is_full_declined")]
public bool IsFullDeclined { get; set; }

/// <summary>
/// Is the document embedded.
/// </summary>
[JsonProperty("is_embedded")]
public bool IsEmbedded { get; set; }

/// <summary>
/// Freeform invite info.
/// </summary>
[JsonProperty("freeform_invite")]
public FreeFormInviteInfo FreeFormInvite { get; set; }

/// <summary>
/// Document Group state.
/// </summary>
[JsonProperty("state")]
public string State { get; set; }

/// <summary>
/// Is the document has guest signer.
/// </summary>
[JsonProperty("has_guest_signer")]
public bool HasGuestSigner { get; set; }

/// <summary>
/// Is the document has signing group.
/// </summary>
[JsonProperty("has_signing_group")]
public bool HasSigningGroup { get; set; }
}
}
39 changes: 39 additions & 0 deletions SignNow.Net/Service/DocumentGroupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SignNow.Net.Internal.Extensions;
using SignNow.Net.Internal.Requests;
using SignNow.Net.Model;
using SignNow.Net.Model.Requests;
using SignNow.Net.Model.Responses;

namespace SignNow.Net.Service
Expand Down Expand Up @@ -52,5 +53,43 @@ public async Task<DocumentGroupInfoResponse> GetDocumentGroupInfoAsync(string do
.RequestAsync<DocumentGroupInfoResponse>(requestOption, cancellationToken)
.ConfigureAwait(false);
}

/// <inheritdoc />
/// <exception cref="ArgumentException">Limit must be greater than 0 but less than or equal to 50.</exception>
/// <exception cref="ArgumentException">Offset must be 0 or greater.</exception>
public async Task<DocumentGroupsResponse> GetDocumentGroupsAsync(IQueryToString options, CancellationToken cancellationToken = default)
{
if (options.GetType() != typeof(LimitOffsetOptions))
{
throw new ArgumentException("Query params does not have 'limit' and 'offset' options. Use \"LimitOffsetOptions\" class.", nameof(options));
}

var opts = (LimitOffsetOptions)options;
if (opts.Limit <= 0 || opts.Limit > 50)
{
throw new ArgumentException("Limit must be greater than 0 but less than or equal to 50.");
}

if (opts.Offset < 0)
{
throw new ArgumentException("Offset must be 0 or greater.");
}

var query = options?.ToQueryString();
var filters = string.IsNullOrEmpty(query)
? string.Empty
: $"?{query}";

Token.TokenType = TokenType.Bearer;
var requestOptions = new GetHttpRequestOptions
{
RequestUrl = new Uri(ApiBaseUrl, $"/user/documentgroups{filters}"),
Token = Token
};

return await SignNowClient
.RequestAsync<DocumentGroupsResponse>(requestOptions, cancellationToken)
.ConfigureAwait(false);
}
}
}

0 comments on commit f06f3e8

Please sign in to comment.