Skip to content

Commit

Permalink
Merge pull request #131 from PaitoAnderson/develop
Browse files Browse the repository at this point in the history
Add support for document prefill text fields
  • Loading branch information
AlexNDRmac authored Jan 25, 2022
2 parents d51b367 + 7b1f6b4 commit 76701f7
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com)
and this project adheres to [Semantic Versioning](http://semver.org).

## [develop] - TBD
- `IDocumentService.PrefillTextFieldsAsync` that allows to prefill document fields

## [0.9.0] - 2021-07-07
### Added
- `IUserService.GetModifiedDocumentsAsync` that allows to get all modified documents for User
Expand Down
27 changes: 27 additions & 0 deletions SignNow.Net.Examples/Documents/PrefillTextFields.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using SignNow.Net.Model;

namespace SignNow.Net.Examples.Documents
{
public static partial class DocumentExamples
{
/// <summary>
/// Adds values to fields that the Signers can later edit when they receive the document for signature.
/// Works only with Text field types.
/// </summary>
/// <param name="documentId">Identity of the document to prefill values for.</param>
/// <param name="fields">Collection of the <see cref="PrefillTextField">fields</see></param>
/// <param name="token">Access token</param>
/// <returns></returns>
public static async Task PrefillTextFields(string documentId, IEnumerable<PrefillTextField> fields, Token token)
{
// using token from the Authorization step
var signNowContext = new SignNowContext(token);

await signNowContext.Documents
.PrefillTextFieldsAsync(documentId, fields)
.ConfigureAwait(false);
}
}
}
10 changes: 10 additions & 0 deletions SignNow.Net/Interfaces/IDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,15 @@ public interface IDocumentService
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
/// <returns>Returns identity of new Document</returns>
Task<CreateDocumentFromTemplateResponse> CreateDocumentFromTemplateAsync(string templateId, string documentName, CancellationToken cancellationToken = default);

/// <summary>
/// Adds values to fields that the Signers can later edit when they receive the document for signature.
/// Works only with Text field types.
/// </summary>
/// <param name="documentId">Identity of the document to prefill values for.</param>
/// <param name="fields">Collection of the <see cref="PrefillTextField">fields</see></param>
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
/// <returns></returns>
Task PrefillTextFieldsAsync(string documentId, IEnumerable<PrefillTextField> fields, CancellationToken cancellationToken = default);
}
}
24 changes: 24 additions & 0 deletions SignNow.Net/Model/PrefillTextField.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Newtonsoft.Json;

namespace SignNow.Net.Model
{
/// <summary>
/// Adds values to fields that the Signers can later edit when they receive the document for signature.
/// Works only with Text field types.
/// </summary>
public class PrefillTextField
{
/// <summary>
/// The unique field name that identifies the field.
/// Can be found in the name parameter of the field in response from GET /document/{{document_id}}
/// </summary>
[JsonProperty("field_name")]
public string FieldName { get; set; }

/// <summary>
/// The value that should appear on the document.
/// </summary>
[JsonProperty("prefilled_text")]
public string PrefilledText { get; set; }
}
}
19 changes: 19 additions & 0 deletions SignNow.Net/Service/DocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,24 @@ public async Task<CreateDocumentFromTemplateResponse> CreateDocumentFromTemplate
.RequestAsync<CreateDocumentFromTemplateResponse>(requestOptions, cancellationToken)
.ConfigureAwait(false);
}

/// <inheritdoc />
/// <exception cref="System.ArgumentException">If <see paramref="documentId"/> is not valid.</exception>
/// <exception cref="System.ArgumentNullException">If <see paramref="fields"/> is null.</exception>
public async Task PrefillTextFieldsAsync(string documentId, IEnumerable<PrefillTextField> fields, CancellationToken cancellationToken = default)
{
Guard.ArgumentNotNull(fields, nameof(fields));

var requestOptions = new PutHttpRequestOptions
{
RequestUrl = new Uri(ApiBaseUrl, $"/v2/documents/{documentId.ValidateId()}/prefill-texts"),
Content = new JsonHttpContent(new PrefillTextFieldRequest(fields)),
Token = Token
};

await SignNowClient
.RequestAsync(requestOptions, cancellationToken)
.ConfigureAwait(false);
}
}
}
35 changes: 35 additions & 0 deletions SignNow.Net/_Internal/Requests/PrefillTextFieldRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using Newtonsoft.Json;
using SignNow.Net.Interfaces;
using SignNow.Net.Model;

namespace SignNow.Net.Internal.Requests
{
internal class PrefillTextFieldRequest : IContent
{
/// <summary>
/// Collections of <see cref="PrefillTextField"/> request options.
/// </summary>
[JsonProperty("fields")]
public List<PrefillTextField> Fields { get; set; } = new List<PrefillTextField>();

public PrefillTextFieldRequest() {}

public PrefillTextFieldRequest(IEnumerable<PrefillTextField> fields)
{
Fields = fields.ToList();
}

/// <summary>
/// Creates Json Http Content from object
/// </summary>
/// <returns>HttpContent</returns>
public HttpContent GetHttpContent()
{
return new StringContent(JsonConvert.SerializeObject(this), Encoding.UTF8, "application/json");
}
}
}

0 comments on commit 76701f7

Please sign in to comment.