Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support Box Doc Gen API (box/box-codegen#644) #378

Merged
merged 2 commits into from
Jan 17, 2025
Merged
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
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "5ab9c2b", "specHash": "091b558", "version": "1.5.0" }
{ "engineHash": "ead925a", "specHash": "091b558", "version": "1.5.0" }
62 changes: 62 additions & 0 deletions Box.Sdk.Gen.Tests.Integration/Test/Docgen/DocgenManagerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Box.Sdk.Gen.Internal;
using Box.Sdk.Gen;
using Box.Sdk.Gen.Schemas;

namespace Box.Sdk.Gen.Tests.Integration {
[TestClass]
public class DocgenManagerTests {
public BoxClient client { get; }

public DocgenManagerTests() {
client = new CommonsManager().GetDefaultClient();
}
[TestMethod]
public async System.Threading.Tasks.Task TestDocgenBatchAndJobs() {
FileFull uploadedFile = await new CommonsManager().UploadNewFileAsync();
FolderFull folder = await new CommonsManager().CreateNewFolderAsync();
DocGenTemplateBaseV2025R0 createdDocgenTemplate = await client.DocgenTemplate.CreateDocgenTemplateV2025R0Async(requestBody: new DocGenTemplateCreateRequestV2025R0(file: new FileReferenceV2025R0(id: uploadedFile.Id)));
DocGenBatchBaseV2025R0 docgenBatch = await client.Docgen.CreateDocgenBatchV2025R0Async(requestBody: new DocGenBatchCreateRequestV2025R0(file: new FileReferenceV2025R0(id: uploadedFile.Id), inputSource: "api", destinationFolder: new DocGenBatchCreateRequestV2025R0DestinationFolderField(id: folder.Id), outputType: "pdf", documentGenerationData: Array.AsReadOnly(new [] {new DocGenDocumentGenerationDataV2025R0(generatedFileName: "test", userInput: new Dictionary<string, object>() { { "abc", "xyz" } })})));
Assert.IsTrue(docgenBatch.Id != "");
Assert.IsTrue(StringUtils.ToStringRepresentation(docgenBatch.Type?.Value) == "docgen_batch");
DocGenJobsV2025R0 docgenBatchJobs = await client.Docgen.GetDocgenBatchJobByIdV2025R0Async(batchId: docgenBatch.Id);
Assert.IsTrue(NullableUtils.Unwrap(docgenBatchJobs.Entries).Count >= 1);
Assert.IsTrue(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].Id != "");
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].Type) == "docgen_job");
Assert.IsTrue(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].OutputType == "pdf");
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].Status) != "");
Assert.IsTrue(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].TemplateFile.Id == uploadedFile.Id);
Assert.IsTrue(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].Batch.Id == docgenBatch.Id);
DocGenJobsFullV2025R0 docgenJobs = await client.Docgen.GetDocgenJobsV2025R0Async();
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries).Count >= 1);
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].Batch.Id != "");
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].CreatedBy.Id != "");
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].Enterprise.Id != "");
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].Id != "");
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].OutputType != "");
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].Source != "");
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenJobs.Entries)[0].Status) != "");
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenJobs.Entries)[0].TemplateFile.Type) == "file");
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].TemplateFile.Id != "");
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenJobs.Entries)[0].TemplateFileVersion.Type) == "file_version");
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].TemplateFileVersion.Id != "");
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenJobs.Entries)[0].Type) == "docgen_job");
DocGenJobV2025R0 docgenJob = await client.Docgen.GetDocgenJobByIdV2025R0Async(jobId: NullableUtils.Unwrap(docgenJobs.Entries)[0].Id);
Assert.IsTrue(docgenJob.Batch.Id != "");
Assert.IsTrue(docgenJob.Id != "");
Assert.IsTrue(docgenJob.OutputType != "");
Assert.IsTrue(StringUtils.ToStringRepresentation(docgenJob.Status?.Value) != "");
Assert.IsTrue(StringUtils.ToStringRepresentation(docgenJob.TemplateFile.Type?.Value) == "file");
Assert.IsTrue(docgenJob.TemplateFile.Id != "");
Assert.IsTrue(StringUtils.ToStringRepresentation(docgenJob.TemplateFileVersion.Type?.Value) == "file_version");
Assert.IsTrue(docgenJob.TemplateFileVersion.Id != "");
Assert.IsTrue(StringUtils.ToStringRepresentation(docgenJob.Type?.Value) == "docgen_job");
await client.Folders.DeleteFolderByIdAsync(folderId: folder.Id);
await client.Files.DeleteFileByIdAsync(fileId: uploadedFile.Id);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Box.Sdk.Gen.Internal;
using Box.Sdk.Gen;
using Box.Sdk.Gen.Schemas;

namespace Box.Sdk.Gen.Tests.Integration {
[TestClass]
public class DocgenTemplateManagerTests {
public BoxClient client { get; }

public DocgenTemplateManagerTests() {
client = new CommonsManager().GetDefaultClient();
}
[TestMethod]
public async System.Threading.Tasks.Task TestDocgenTemplateCrud() {
FileFull file = await new CommonsManager().UploadNewFileAsync();
DocGenTemplateBaseV2025R0 createdDocgenTemplate = await client.DocgenTemplate.CreateDocgenTemplateV2025R0Async(requestBody: new DocGenTemplateCreateRequestV2025R0(file: new FileReferenceV2025R0(id: file.Id)));
DocGenTemplatesV2025R0 docgenTemplates = await client.DocgenTemplate.GetDocgenTemplatesV2025R0Async();
Assert.IsTrue(NullableUtils.Unwrap(docgenTemplates.Entries).Count > 0);
DocGenTemplateV2025R0 fetchedDocgenTemplate = await client.DocgenTemplate.GetDocgenTemplateByIdV2025R0Async(templateId: NullableUtils.Unwrap(createdDocgenTemplate.File).Id);
Assert.IsTrue(NullableUtils.Unwrap(fetchedDocgenTemplate.File).Id == NullableUtils.Unwrap(createdDocgenTemplate.File).Id);
DocGenTagsV2025R0 docgenTemplateTags = await client.DocgenTemplate.GetDocgenTemplateTagsV2025R0Async(templateId: NullableUtils.Unwrap(fetchedDocgenTemplate.File).Id);
DocGenJobsV2025R0 docgenTemplateJobs = await client.DocgenTemplate.GetDocgenTemplateJobByIdV2025R0Async(templateId: NullableUtils.Unwrap(fetchedDocgenTemplate.File).Id);
Assert.IsTrue(NullableUtils.Unwrap(docgenTemplateJobs.Entries).Count == 0);
await client.DocgenTemplate.DeleteDocgenTemplateByIdV2025R0Async(templateId: NullableUtils.Unwrap(createdDocgenTemplate.File).Id);
await client.Files.DeleteFileByIdAsync(fileId: file.Id);
}

}
}
6 changes: 6 additions & 0 deletions Box.Sdk.Gen/Client/BoxClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public class BoxClient : IBoxClient {

public IAiManager Ai { get; }

public IDocgenTemplateManager DocgenTemplate { get; }

public IDocgenManager Docgen { get; }

public BoxClient(IAuthentication auth, NetworkSession? networkSession = default) {
Auth = auth;
NetworkSession = networkSession ?? new NetworkSession(baseUrls: new BaseUrls());
Expand Down Expand Up @@ -222,6 +226,8 @@ public BoxClient(IAuthentication auth, NetworkSession? networkSession = default)
SignTemplates = new SignTemplatesManager(networkSession: this.NetworkSession) { Auth = this.Auth };
IntegrationMappings = new IntegrationMappingsManager(networkSession: this.NetworkSession) { Auth = this.Auth };
Ai = new AiManager(networkSession: this.NetworkSession) { Auth = this.Auth };
DocgenTemplate = new DocgenTemplateManager(networkSession: this.NetworkSession) { Auth = this.Auth };
Docgen = new DocgenManager(networkSession: this.NetworkSession) { Auth = this.Auth };
}
/// <summary>
/// Make a custom http request using the client authentication and network session.
Expand Down
4 changes: 4 additions & 0 deletions Box.Sdk.Gen/Client/IBoxClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,9 @@ public interface IBoxClient {

public IAiManager Ai { get => throw new System.NotImplementedException("This method needs to be implemented by the derived class before calling it."); }

public IDocgenTemplateManager DocgenTemplate { get => throw new System.NotImplementedException("This method needs to be implemented by the derived class before calling it."); }

public IDocgenManager Docgen { get => throw new System.NotImplementedException("This method needs to be implemented by the derived class before calling it."); }

}
}
25 changes: 25 additions & 0 deletions Box.Sdk.Gen/Managers/Docgen/CreateDocgenBatchV2025R0Headers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Box.Sdk.Gen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Box.Sdk.Gen.Internal;
using Box.Sdk.Gen.Schemas;
using Box.Sdk.Gen.Parameters;

namespace Box.Sdk.Gen.Managers {
public class CreateDocgenBatchV2025R0Headers {
/// <summary>
/// Version header
/// </summary>
public StringEnum<BoxVersionHeaderV2025R0> BoxVersion { get; }

/// <summary>
/// Extra headers that will be included in the HTTP request.
/// </summary>
public Dictionary<string, string?> ExtraHeaders { get; }

public CreateDocgenBatchV2025R0Headers(BoxVersionHeaderV2025R0 boxVersion = BoxVersionHeaderV2025R0._20250, Dictionary<string, string?>? extraHeaders = default) {
BoxVersion = boxVersion;
ExtraHeaders = extraHeaders ?? new Dictionary<string, string?>() { };
}
}
}
103 changes: 103 additions & 0 deletions Box.Sdk.Gen/Managers/Docgen/DocgenManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using Box.Sdk.Gen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Box.Sdk.Gen.Internal;
using Box.Sdk.Gen.Schemas;
using Box.Sdk.Gen.Parameters;

namespace Box.Sdk.Gen.Managers {
public class DocgenManager : IDocgenManager {
public IAuthentication? Auth { get; init; }

public NetworkSession NetworkSession { get; }

public DocgenManager(NetworkSession? networkSession = default) {
NetworkSession = networkSession ?? new NetworkSession();
}
/// <summary>
/// Get details of the Box Doc Gen job.
/// </summary>
/// <param name="jobId">
/// Box Doc Gen job ID.
/// Example: 123
/// </param>
/// <param name="headers">
/// Headers of getDocgenJobByIdV2025R0 method
/// </param>
/// <param name="cancellationToken">
/// Token used for request cancellation.
/// </param>
public async System.Threading.Tasks.Task<DocGenJobV2025R0> GetDocgenJobByIdV2025R0Async(string jobId, GetDocgenJobByIdV2025R0Headers? headers = default, System.Threading.CancellationToken? cancellationToken = null) {
headers = headers ?? new GetDocgenJobByIdV2025R0Headers();
Dictionary<string, string> headersMap = Utils.PrepareParams(map: DictionaryUtils.MergeDictionaries(new Dictionary<string, string?>() { { "box-version", StringUtils.ToStringRepresentation(headers.BoxVersion) } }, headers.ExtraHeaders));
FetchResponse response = await this.NetworkSession.NetworkClient.FetchAsync(options: new FetchOptions(url: string.Concat(this.NetworkSession.BaseUrls.BaseUrl, "/2.0/docgen_jobs/", StringUtils.ToStringRepresentation(jobId)), method: "GET", responseFormat: Box.Sdk.Gen.ResponseFormat.Json) { Headers = headersMap, Auth = this.Auth, NetworkSession = this.NetworkSession, CancellationToken = cancellationToken }).ConfigureAwait(false);
return SimpleJsonSerializer.Deserialize<DocGenJobV2025R0>(NullableUtils.Unwrap(response.Data));
}

/// <summary>
/// Lists all Box Doc Gen jobs for a user.
/// </summary>
/// <param name="queryParams">
/// Query parameters of getDocgenJobsV2025R0 method
/// </param>
/// <param name="headers">
/// Headers of getDocgenJobsV2025R0 method
/// </param>
/// <param name="cancellationToken">
/// Token used for request cancellation.
/// </param>
public async System.Threading.Tasks.Task<DocGenJobsFullV2025R0> GetDocgenJobsV2025R0Async(GetDocgenJobsV2025R0QueryParams? queryParams = default, GetDocgenJobsV2025R0Headers? headers = default, System.Threading.CancellationToken? cancellationToken = null) {
queryParams = queryParams ?? new GetDocgenJobsV2025R0QueryParams();
headers = headers ?? new GetDocgenJobsV2025R0Headers();
Dictionary<string, string> queryParamsMap = Utils.PrepareParams(map: new Dictionary<string, string?>() { { "marker", StringUtils.ToStringRepresentation(queryParams.Marker) }, { "limit", StringUtils.ToStringRepresentation(queryParams.Limit) } });
Dictionary<string, string> headersMap = Utils.PrepareParams(map: DictionaryUtils.MergeDictionaries(new Dictionary<string, string?>() { { "box-version", StringUtils.ToStringRepresentation(headers.BoxVersion) } }, headers.ExtraHeaders));
FetchResponse response = await this.NetworkSession.NetworkClient.FetchAsync(options: new FetchOptions(url: string.Concat(this.NetworkSession.BaseUrls.BaseUrl, "/2.0/docgen_jobs"), method: "GET", responseFormat: Box.Sdk.Gen.ResponseFormat.Json) { Parameters = queryParamsMap, Headers = headersMap, Auth = this.Auth, NetworkSession = this.NetworkSession, CancellationToken = cancellationToken }).ConfigureAwait(false);
return SimpleJsonSerializer.Deserialize<DocGenJobsFullV2025R0>(NullableUtils.Unwrap(response.Data));
}

/// <summary>
/// Lists Box Doc Gen jobs in a batch
/// </summary>
/// <param name="batchId">
/// Box Doc Gen batch ID.
/// Example: 123
/// </param>
/// <param name="queryParams">
/// Query parameters of getDocgenBatchJobByIdV2025R0 method
/// </param>
/// <param name="headers">
/// Headers of getDocgenBatchJobByIdV2025R0 method
/// </param>
/// <param name="cancellationToken">
/// Token used for request cancellation.
/// </param>
public async System.Threading.Tasks.Task<DocGenJobsV2025R0> GetDocgenBatchJobByIdV2025R0Async(string batchId, GetDocgenBatchJobByIdV2025R0QueryParams? queryParams = default, GetDocgenBatchJobByIdV2025R0Headers? headers = default, System.Threading.CancellationToken? cancellationToken = null) {
queryParams = queryParams ?? new GetDocgenBatchJobByIdV2025R0QueryParams();
headers = headers ?? new GetDocgenBatchJobByIdV2025R0Headers();
Dictionary<string, string> queryParamsMap = Utils.PrepareParams(map: new Dictionary<string, string?>() { { "marker", StringUtils.ToStringRepresentation(queryParams.Marker) }, { "limit", StringUtils.ToStringRepresentation(queryParams.Limit) } });
Dictionary<string, string> headersMap = Utils.PrepareParams(map: DictionaryUtils.MergeDictionaries(new Dictionary<string, string?>() { { "box-version", StringUtils.ToStringRepresentation(headers.BoxVersion) } }, headers.ExtraHeaders));
FetchResponse response = await this.NetworkSession.NetworkClient.FetchAsync(options: new FetchOptions(url: string.Concat(this.NetworkSession.BaseUrls.BaseUrl, "/2.0/docgen_batch_jobs/", StringUtils.ToStringRepresentation(batchId)), method: "GET", responseFormat: Box.Sdk.Gen.ResponseFormat.Json) { Parameters = queryParamsMap, Headers = headersMap, Auth = this.Auth, NetworkSession = this.NetworkSession, CancellationToken = cancellationToken }).ConfigureAwait(false);
return SimpleJsonSerializer.Deserialize<DocGenJobsV2025R0>(NullableUtils.Unwrap(response.Data));
}

/// <summary>
/// Generates a document using a Box Doc Gen template.
/// </summary>
/// <param name="requestBody">
/// Request body of createDocgenBatchV2025R0 method
/// </param>
/// <param name="headers">
/// Headers of createDocgenBatchV2025R0 method
/// </param>
/// <param name="cancellationToken">
/// Token used for request cancellation.
/// </param>
public async System.Threading.Tasks.Task<DocGenBatchBaseV2025R0> CreateDocgenBatchV2025R0Async(DocGenBatchCreateRequestV2025R0 requestBody, CreateDocgenBatchV2025R0Headers? headers = default, System.Threading.CancellationToken? cancellationToken = null) {
headers = headers ?? new CreateDocgenBatchV2025R0Headers();
Dictionary<string, string> headersMap = Utils.PrepareParams(map: DictionaryUtils.MergeDictionaries(new Dictionary<string, string?>() { { "box-version", StringUtils.ToStringRepresentation(headers.BoxVersion) } }, headers.ExtraHeaders));
FetchResponse response = await this.NetworkSession.NetworkClient.FetchAsync(options: new FetchOptions(url: string.Concat(this.NetworkSession.BaseUrls.BaseUrl, "/2.0/docgen_batches"), method: "POST", contentType: "application/json", responseFormat: Box.Sdk.Gen.ResponseFormat.Json) { Headers = headersMap, Data = SimpleJsonSerializer.Serialize(requestBody), Auth = this.Auth, NetworkSession = this.NetworkSession, CancellationToken = cancellationToken }).ConfigureAwait(false);
return SimpleJsonSerializer.Deserialize<DocGenBatchBaseV2025R0>(NullableUtils.Unwrap(response.Data));
}

}
}
25 changes: 25 additions & 0 deletions Box.Sdk.Gen/Managers/Docgen/GetDocgenBatchJobByIdV2025R0Headers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Box.Sdk.Gen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Box.Sdk.Gen.Internal;
using Box.Sdk.Gen.Schemas;
using Box.Sdk.Gen.Parameters;

namespace Box.Sdk.Gen.Managers {
public class GetDocgenBatchJobByIdV2025R0Headers {
/// <summary>
/// Version header
/// </summary>
public StringEnum<BoxVersionHeaderV2025R0> BoxVersion { get; }

/// <summary>
/// Extra headers that will be included in the HTTP request.
/// </summary>
public Dictionary<string, string?> ExtraHeaders { get; }

public GetDocgenBatchJobByIdV2025R0Headers(BoxVersionHeaderV2025R0 boxVersion = BoxVersionHeaderV2025R0._20250, Dictionary<string, string?>? extraHeaders = default) {
BoxVersion = boxVersion;
ExtraHeaders = extraHeaders ?? new Dictionary<string, string?>() { };
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Box.Sdk.Gen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Box.Sdk.Gen.Internal;
using Box.Sdk.Gen.Schemas;
using Box.Sdk.Gen.Parameters;

namespace Box.Sdk.Gen.Managers {
public class GetDocgenBatchJobByIdV2025R0QueryParams {
/// <summary>
/// Defines the position marker at which to begin returning results. This is
/// used when paginating using marker-based pagination.
///
/// This requires `usemarker` to be set to `true`.
/// </summary>
public string? Marker { get; init; }

/// <summary>
/// The maximum number of items to return per page.
/// </summary>
public long? Limit { get; init; }

public GetDocgenBatchJobByIdV2025R0QueryParams() {

}
}
}
Loading
Loading