From 83af800befb6d3c30f95ac5694de4637884ff409 Mon Sep 17 00:00:00 2001 From: Paito Anderson Date: Wed, 29 Dec 2021 17:56:48 -0500 Subject: [PATCH 1/2] Add prefill text fields --- CHANGELOG.md | 3 ++ .../Documents/PrefillTextFields.cs | 27 ++++++++++++++ SignNow.Net/Interfaces/IDocumentService.cs | 10 ++++++ SignNow.Net/Model/PrefillTextField.cs | 24 +++++++++++++ SignNow.Net/Service/DocumentService.cs | 19 ++++++++++ .../Requests/PrefillTextFieldRequest.cs | 35 +++++++++++++++++++ 6 files changed, 118 insertions(+) create mode 100644 SignNow.Net.Examples/Documents/PrefillTextFields.cs create mode 100644 SignNow.Net/Model/PrefillTextField.cs create mode 100644 SignNow.Net/_Internal/Requests/PrefillTextFieldRequest.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e38ef3..2a84194d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/SignNow.Net.Examples/Documents/PrefillTextFields.cs b/SignNow.Net.Examples/Documents/PrefillTextFields.cs new file mode 100644 index 00000000..98ee46d0 --- /dev/null +++ b/SignNow.Net.Examples/Documents/PrefillTextFields.cs @@ -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 + { + /// + /// Adds values to fields that the Signers can later edit when they receive the document for signature. + /// Works only with Text field types. + /// + /// Identity of the document to prefill values for. + /// Collection of the fields + /// Access token + /// + public static async Task PrefillTextFields(string documentId, IEnumerable fields, Token token) + { + // using token from the Authorization step + var signNowContext = new SignNowContext(token); + + await signNowContext.Documents + .PrefillTextFieldsAsync(documentId, fields) + .ConfigureAwait(false); + } + } +} diff --git a/SignNow.Net/Interfaces/IDocumentService.cs b/SignNow.Net/Interfaces/IDocumentService.cs index 93851693..41b2d259 100644 --- a/SignNow.Net/Interfaces/IDocumentService.cs +++ b/SignNow.Net/Interfaces/IDocumentService.cs @@ -117,5 +117,15 @@ public interface IDocumentService /// Propagates notification that operations should be canceled. /// Returns identity of new Document Task CreateDocumentFromTemplateAsync(string templateId, string documentName, CancellationToken cancellationToken = default); + + /// + /// Adds values to fields that the Signers can later edit when they receive the document for signature. + /// Works only with Text field types. + /// + /// Identity of the document to prefill values for. + /// Collection of the fields + /// Propagates notification that operations should be canceled. + /// + Task PrefillTextFieldsAsync(string documentId, IEnumerable fields, CancellationToken cancellationToken = default); } } diff --git a/SignNow.Net/Model/PrefillTextField.cs b/SignNow.Net/Model/PrefillTextField.cs new file mode 100644 index 00000000..090ceb5f --- /dev/null +++ b/SignNow.Net/Model/PrefillTextField.cs @@ -0,0 +1,24 @@ +using Newtonsoft.Json; + +namespace SignNow.Net.Model +{ + /// + /// Adds values to fields that the Signers can later edit when they receive the document for signature. + /// Works only with Text field types. + /// + public class PrefillTextField + { + /// + /// 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}} + /// + [JsonProperty("field_name")] + public string FieldName { get; set; } + + /// + /// The value that should appear on the document. + /// + [JsonProperty("prefilled_text")] + public string PrefilledText { get; set; } + } +} diff --git a/SignNow.Net/Service/DocumentService.cs b/SignNow.Net/Service/DocumentService.cs index 1e0df956..2018eb66 100644 --- a/SignNow.Net/Service/DocumentService.cs +++ b/SignNow.Net/Service/DocumentService.cs @@ -256,5 +256,24 @@ public async Task CreateDocumentFromTemplate .RequestAsync(requestOptions, cancellationToken) .ConfigureAwait(false); } + + /// + /// If is not valid. + /// If is null. + public async Task PrefillTextFieldsAsync(string documentId, IEnumerable fields, CancellationToken cancellationToken = default) + { + Guard.ArgumentNotNull(fields, nameof(fields)); + + var requestOptions = new PutHttpRequestOptions + { + RequestUrl = new Uri(ApiBaseUrl, $"/document/{documentId.ValidateId()}/prefill-texts"), + Content = new JsonHttpContent(new PrefillTextFieldRequest(fields)), + Token = Token + }; + + await SignNowClient + .RequestAsync(requestOptions, cancellationToken) + .ConfigureAwait(false); + } } } diff --git a/SignNow.Net/_Internal/Requests/PrefillTextFieldRequest.cs b/SignNow.Net/_Internal/Requests/PrefillTextFieldRequest.cs new file mode 100644 index 00000000..25b0a9fa --- /dev/null +++ b/SignNow.Net/_Internal/Requests/PrefillTextFieldRequest.cs @@ -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 + { + /// + /// Collections of request options. + /// + [JsonProperty("fields")] + public List Fields { get; set; } = new List(); + + public PrefillTextFieldRequest() {} + + public PrefillTextFieldRequest(IEnumerable fields) + { + Fields = fields.ToList(); + } + + /// + /// Creates Json Http Content from object + /// + /// HttpContent + public HttpContent GetHttpContent() + { + return new StringContent(JsonConvert.SerializeObject(this), Encoding.UTF8, "application/json"); + } + } +} From 7b1f6b4ecbc0d0b5649b4b502ed89a9f7e332a14 Mon Sep 17 00:00:00 2001 From: Paito Anderson Date: Wed, 29 Dec 2021 18:39:47 -0500 Subject: [PATCH 2/2] Fix endpoint --- SignNow.Net/Service/DocumentService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignNow.Net/Service/DocumentService.cs b/SignNow.Net/Service/DocumentService.cs index 2018eb66..20ab2014 100644 --- a/SignNow.Net/Service/DocumentService.cs +++ b/SignNow.Net/Service/DocumentService.cs @@ -266,7 +266,7 @@ public async Task PrefillTextFieldsAsync(string documentId, IEnumerable