Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

<groupId>com.signnow</groupId>
<artifactId>api-client-lib</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
Expand Down
8 changes: 7 additions & 1 deletion client-lib/src/main/java/com/signnow/library/SNClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,16 @@ public <E, T> T delete(String path, Map<String, String> parameters, Class<T> ret
return response.readEntity(returnType);
}

public int delete(String path, Map<String, String> parameters) throws SNException {
Response response = buildRequest(path, parameters).delete();
checkAPIException(response);
return response.getStatus();
}

private Invocation.Builder buildRequest(String path, Map<String, String> parameters) {
WebTarget target = apiWebTarget.path(path);
if (parameters != null) {
for (String key : parameters.keySet()){
for (String key : parameters.keySet()) {
WebTarget targetUpd = target.resolveTemplate(key, parameters.get(key));
if (!targetUpd.toString().equals(target.toString())) {
target = targetUpd;
Expand Down
159 changes: 158 additions & 1 deletion client-lib/src/main/java/com/signnow/library/dto/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ public class Document extends GenericId {
public String updated;
@JsonProperty("original_filename")
public String originalFilename;
@JsonProperty("origin_document_id")
public String originDocumentId;
public String owner;
@JsonProperty(value = "template", defaultValue = "false")
public boolean template;
public Thumbnail thumbnail;
public List<Signature> signatures;
public List<Tag> tags;
public List<DocumentField> fields;
@JsonProperty("version_time")
public String versionTime;
/**
Expand All @@ -28,6 +37,7 @@ public class Document extends GenericId {
* Free form invites info
*/
public List<DocumentSignRequestInfo> requests;
public List<Role> roles;

public static class SigningLinkRequest {
@JsonProperty("document_id")
Expand All @@ -38,6 +48,62 @@ public SigningLinkRequest(String documentId) {
}
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class Thumbnail {
public String small;
public String medium;
public String large;
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class Signature extends GenericId {
@JsonProperty("user_id")
public String userId;
public String email;
@JsonProperty("page_number")
public String pageNumber;
public String width;
public String height;
public String x;
public String y;
public String created;
public String data;
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class DocumentField extends GenericId {
public FieldType type;
@JsonProperty("role_id")
public String roleId;
public String role;
public String originator;
public String fulfiller;
@JsonProperty("field_request_id")
public String fieldRequestId;
@JsonProperty("element_id")
public String elementId;
@JsonProperty("field_request_canceled")
public String fieldRequestCanceled;
@JsonProperty("template_field_id")
public String fieldTemplateId;
@JsonProperty("field_id")
public String fieldId;
}

public static class Role {
@JsonProperty("unique_id")
public String uniqueId;
@JsonProperty("signing_order")
public String signingOrder;
public String name;
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class Tag {
public String type;
public String name;
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class SigningLinkResponce {
public String url;
Expand Down Expand Up @@ -110,7 +176,6 @@ public enum FieldType {
this.name = name;
}

@JsonSetter
public static FieldType typeOf(String name) {
for (FieldType type : values()) {
if (type.name.equalsIgnoreCase(name)) {
Expand All @@ -120,6 +185,11 @@ public static FieldType typeOf(String name) {
throw new IllegalArgumentException(name + " field not supported.");
}

@JsonValue
public String getType() {
return name;
}

@JsonCreator
@Override
public String toString() {
Expand Down Expand Up @@ -175,4 +245,91 @@ public static class DocumentDownloadLink {
public String link;
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class EmbeddedInviteResponse {
public List<EmbeddedInviteResult> data = new ArrayList<>();
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class EmbeddedInviteResult {
public String id;
public String email;
public String role_id;
public int order;
public String status;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
public static class EmbeddedInviteRequest {
public List<EmbeddedInvite> invites = new ArrayList<>();
}

@JsonInclude(JsonInclude.Include.NON_NULL)
public static class EmbeddedInvite {
public String email;
public String role_id;
public int order;
public String auth_method;

public EmbeddedInvite() {
}

public EmbeddedInvite(String email, String role_id, int order, String auth_method) {
this.email = email;
this.role_id = role_id;
this.order = order;
this.auth_method = auth_method;
}
}

@JsonInclude(JsonInclude.Include.NON_NULL)
public static class GenerateEmbeddedSigningLinkRequest {
public String auth_method;
public int link_expiration;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
public static class GenerateEmbeddedSigningLinkResponse {
public LinkData data;
}

public static class LinkData {
public String link;
}

public enum AuthMethod {
PASSWORD("password"),
EMAIL("email"),
MFA("mfa"),
SOCIAL("social"),
BIOMETRIC("biometric"),
OTHER("other"),
NONE("none");

private final String method;

AuthMethod(String method) {
this.method = method;
}

public static AuthMethod getAuthMethod(final String authMethod) {
for (AuthMethod value : values()) {
if (value.method.equalsIgnoreCase(authMethod)) {
return value;
}
}
throw new EnumConstantNotPresentException(AuthMethod.class, authMethod);
}

@JsonValue
public String getAuthMethod() {
return method;
}

@JsonCreator
@Override
public String toString() {
return method;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,20 @@ public interface Documents {
void deleteDocument(String documentId) throws SNException;

String getDownloadLink(String documentId) throws SNException;

Document.EmbeddedInviteResponse createEmbeddedInvites(final String documentId,
final Document.EmbeddedInviteRequest request) throws SNException;

Document.GenerateEmbeddedSigningLinkResponse generateEmbeddedInviteLink(final String documentId,
final String fieldId,
final Document.GenerateEmbeddedSigningLinkRequest request) throws SNException;

/**
* All embedded invites created for the document will be deleted.
*
* @param documentId the documentId of the document containing embedded invites.
* @return the 204 status code will be returned if the embedded invites have been deleted successfully.
* @throws SNException
*/
int deleteEmbeddedInvite(final String documentId) throws SNException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class DocumentsService extends ApiService implements Documents {
public DocumentsService(SNClient client) {
Expand Down Expand Up @@ -109,4 +110,32 @@ public String getDownloadLink(String documentId) throws SNException {
Document.DocumentDownloadLink.class
).link;
}

@Override
public Document.EmbeddedInviteResponse createEmbeddedInvites(String documentId, Document.EmbeddedInviteRequest request) throws SNException {
return client.post(
"/v2/documents/{documentUniqueId}/embedded-invites",
Collections.singletonMap("documentUniqueId", documentId),
request,
Document.EmbeddedInviteResponse.class
);
}

@Override
public Document.GenerateEmbeddedSigningLinkResponse generateEmbeddedInviteLink(String documentId, String fieldId, Document.GenerateEmbeddedSigningLinkRequest request) throws SNException {
return client.post(
"/v2/documents/{document_id}/embedded-invites/{fieldInviteUniqueId}/link",
Map.of("document_id", documentId, "fieldInviteUniqueId", fieldId),
request,
Document.GenerateEmbeddedSigningLinkResponse.class
);
}

@Override
public int deleteEmbeddedInvite(String documentId) throws SNException {
return client.delete(
"/v2/documents/{document_id}/embedded-invites",
Collections.singletonMap("document_id", documentId)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Matchers;

import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
Expand All @@ -19,7 +18,7 @@
import java.util.List;
import java.util.Random;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;

class DocumentsServiceTest extends CommonServiceTestCase {
Expand Down Expand Up @@ -162,6 +161,16 @@ void getDownloadLink() throws SNException {
, eq(Document.DocumentDownloadLink.class));
}

@Test
void createEmbeddedInvites() throws SNException {
Document.EmbeddedInviteResponse response = mock(Document.EmbeddedInviteResponse.class);
Document.EmbeddedInviteRequest request = mock(Document.EmbeddedInviteRequest.class);
when(clientMock.post(anyString(), anyMap(), eq(request), eq(Document.EmbeddedInviteResponse.class))).thenReturn(response);
service.createEmbeddedInvites("1", request);
verify(clientMock, times(1))
.post(anyString(), anyMap(), eq(request), eq(Document.EmbeddedInviteResponse.class));
}

private InputStream getSomeInputStream() {
byte[] bytes = new byte[25];
Random rnd = new Random();
Expand Down Expand Up @@ -204,4 +213,4 @@ private void verify_uploadDocument() {
verify(builderMock, times(1)).header(anyString(), any());
verify(builderMock, times(1)).post(any());
}
}
}
15 changes: 13 additions & 2 deletions example-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.signnow</groupId>
<artifactId>api-example-app</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
Expand All @@ -17,7 +17,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<java.version>11</java.version>
</properties>

<dependencies>
Expand All @@ -40,6 +40,17 @@
<version>${project.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.webjars/highlightjs -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>highlightjs</artifactId>
<version>10.1.2</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
Loading