Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
163e235
Mark generated API2 endpoint blocks
kvz Jun 2, 2026
06a79b7
Add API2 template lifecycle example
kvz Jun 2, 2026
13f4bb7
Add API2 TUS assembly example
kvz Jun 2, 2026
449c229
Generate createTusAssembly feature
kvz Jun 2, 2026
0013732
Generate waitForAssembly feature
kvz Jun 2, 2026
9dd6431
Read TUS scenario preparations generically
kvz Jun 2, 2026
381ef81
Generate TUS assembly upload helper
kvz Jun 2, 2026
8df12db
Use header-derived TUS offset variable
kvz Jun 2, 2026
df3c8e3
Read TUS example input from SDK feature call
kvz Jun 3, 2026
174fcac
Read SDK example input projection
kvz Jun 3, 2026
355533f
Regenerate contract-owned TUS Assembly surfaces
kvz Jun 5, 2026
559231c
Regenerate required feature value guards
kvz Jun 5, 2026
60989a9
Add assembly lifecycle devdock example
kvz Jun 10, 2026
7ac3073
Use SSL Assembly URL for TUS metadata
kvz Jun 10, 2026
7015953
Prove TUS resume upload via generated SDK method
kvz Jun 11, 2026
9f8c5ad
Generate all supported API endpoint methods
kvz Jul 11, 2026
0ab5e7e
Generate bearer token issuance
kvz Jul 11, 2026
673eda6
Correct generated endpoint clients
kvz Jul 11, 2026
2af81df
Generate invoice bill endpoint
kvz Jul 11, 2026
7f115d1
Generate exact-one-file TUS helper
kvz Jul 11, 2026
5362701
Protect Assembly URL requests
kvz Jul 11, 2026
80473eb
Merge remote-tracking branch 'origin/main' into sdk-gen-java
kvz Jul 12, 2026
e4af120
Encode generated request paths
kvz Jul 12, 2026
1713190
Allow HTTPS polling on configured hosts
kvz Jul 12, 2026
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
22 changes: 22 additions & 0 deletions examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
jcenter()
}

dependencies {
implementation rootProject
implementation 'io.tus.java.client:tus-java-client:0.5.1'
implementation 'org.json:json:20231013'
}
buildscript {
Expand All @@ -37,3 +39,23 @@ compileTestKotlin {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}

tasks.register('api2DevdockTemplateLifecycle', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'com.transloadit.examples.Api2DevdockTemplateLifecycle'
}

tasks.register('api2DevdockAssemblyLifecycle', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'com.transloadit.examples.Api2DevdockAssemblyLifecycle'
}

tasks.register('api2DevdockTusAssembly', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'com.transloadit.examples.Api2DevdockTusAssembly'
}

tasks.register('api2DevdockTusResumeUpload', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'com.transloadit.examples.Api2DevdockTusResumeUpload'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.transloadit.examples;

import com.transloadit.sdk.Transloadit;
import com.transloadit.sdk.response.AssemblyResponse;
import com.transloadit.sdk.response.ListResponse;
import org.json.JSONArray;
import org.json.JSONObject;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

/**
* Runs API2's contract-owned Assembly lifecycle scenario against devdock.
*/
public final class Api2DevdockAssemblyLifecycle {
/**
* Runs the Assembly lifecycle scenario.
*
* @param args ignored
* @throws Exception if the scenario cannot be completed
*/
public static void main(String[] args) throws Exception {
JSONObject scenario = loadScenario();
Transloadit transloadit = new Transloadit(
requiredEnv("TRANSLOADIT_KEY"),
requiredEnv("TRANSLOADIT_SECRET"),
requiredEnv("TRANSLOADIT_ENDPOINT"));

AssemblyResponse created = transloadit.createTusAssembly(
scenario.getJSONObject("assembly").getInt("fileCount"));
String createdAssemblySslUrl = created.getSslUrl();
boolean cancelAssembly = true;

try {
AssemblyResponse fetched = transloadit.getAssemblyByUrl(createdAssemblySslUrl);

Map<String, Object> listOptions = new HashMap<String, Object>();
listOptions.put("assembly_id", created.getId());
listOptions.put("pagesize", scenario.getJSONObject("list").getInt("pageSize"));
// The Assembly list is eventually consistent: the API acknowledges creation before
// the list storage row lands, so poll briefly until the created Assembly shows up.
ListResponse listed = transloadit.listAssemblies(listOptions);
for (int attempt = 0; attempt < 20; attempt += 1) {
if (listContainsAssembly(listed.getItems(), created.getId())) {
break;
}
Thread.sleep(500);
listed = transloadit.listAssemblies(listOptions);
}

AssemblyResponse cancelled = transloadit.cancelAssembly(createdAssemblySslUrl);
cancelAssembly = false;

JSONObject result = new JSONObject();
result.put("cancelled", assemblyResult(cancelled));
result.put("created", assemblyResult(created));
result.put("fetched", assemblyResult(fetched));
result.put("listContainsCreated", listContainsAssembly(listed.getItems(), created.getId()));
result.put("listCount", listed.size());
writeResult(result);
} finally {
if (cancelAssembly) {
transloadit.cancelAssembly(createdAssemblySslUrl);
}
}

System.out.println("Java SDK devdock scenario " + scenario.getString("scenarioId")
+ " canceled Assembly " + created.getId());
}

private static JSONObject assemblyResult(AssemblyResponse response) {
JSONObject result = new JSONObject();
result.put("assemblyId", response.getId());
result.put("assemblySslUrl", response.getSslUrl());
result.put("assemblyUrl", response.getUrl());
result.put("ok", response.json().optString("ok", ""));
return result;
}

private static boolean listContainsAssembly(JSONArray items, String assemblyId) {
for (int index = 0; index < items.length(); index += 1) {
if (assemblyId.equals(items.getJSONObject(index).optString("id"))) {
return true;
}
}

return false;
}

private static JSONObject loadScenario() throws Exception {
String scenarioPath = System.getenv("API2_SDK_EXAMPLE_SCENARIO");
if (scenarioPath == null || scenarioPath.isEmpty()) {
scenarioPath = "examples/api2-devdock-assembly-lifecycle/api2-scenario.json";
}

byte[] contents = Files.readAllBytes(Paths.get(scenarioPath));
return new JSONObject(new String(contents, StandardCharsets.UTF_8));
}

private static String requiredEnv(String name) {
String value = System.getenv(name);
if (value == null || value.isEmpty()) {
throw new IllegalStateException(name + " must be set");
}

return value;
}

private static void writeResult(JSONObject result) throws Exception {
String resultPath = System.getenv("API2_SDK_EXAMPLE_RESULT");
if (resultPath == null || resultPath.isEmpty()) {
return;
}

Files.write(
Paths.get(resultPath),
(result.toString(2) + "\n").getBytes(StandardCharsets.UTF_8));
}

private Api2DevdockAssemblyLifecycle() {
throw new IllegalStateException("Utility class");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package com.transloadit.examples;

import com.transloadit.sdk.Transloadit;
import com.transloadit.sdk.response.ListResponse;
import com.transloadit.sdk.response.Response;
import org.json.JSONArray;
import org.json.JSONObject;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
* Runs API2's contract-owned Template lifecycle scenario against devdock.
*/
public final class Api2DevdockTemplateLifecycle {
/**
* Runs the Template lifecycle scenario.
*
* @param args ignored
* @throws Exception if the scenario cannot be completed
*/
public static void main(String[] args) throws Exception {
JSONObject scenario = loadScenario();
Transloadit transloadit = new Transloadit(
requiredEnv("TRANSLOADIT_KEY"),
requiredEnv("TRANSLOADIT_SECRET"),
requiredEnv("TRANSLOADIT_ENDPOINT"));

JSONObject templateConfig = scenario.getJSONObject("template");
JSONObject updateConfig = scenario.getJSONObject("update");
String templateName = templateConfig.getString("namePrefix") + "-" + System.currentTimeMillis();

Response created = transloadit.createTemplate(templatePayload(templateName, templateConfig));
String templateId = created.json().getString("id");
boolean deleteTemplate = true;

try {
Response fetched = transloadit.getTemplate(templateId);

Map<String, Object> listOptions = new HashMap<String, Object>();
listOptions.put("pagesize", scenario.getJSONObject("list").getInt("pageSize"));
ListResponse listed = transloadit.listTemplates(listOptions);

String updatedTemplateName = templateName + updateConfig.getString("nameSuffix");
transloadit.updateTemplate(templateId, templatePayload(updatedTemplateName, updateConfig));
Response updated = transloadit.getTemplate(templateId);

transloadit.deleteTemplate(templateId);
deleteTemplate = false;

JSONObject result = new JSONObject();
JSONObject deletedGet = deletedGetResult(transloadit, templateId);
for (Iterator<String> keys = deletedGet.keys(); keys.hasNext();) {
String key = keys.next();
result.put(key, deletedGet.get(key));
}
result.put("fetched", templateResult(fetched.json()));
result.put("listCount", listed.size());
result.put("templateId", templateId);
result.put("templateName", templateName);
result.put("updated", templateResult(updated.json()));
result.put("updatedTemplateName", updatedTemplateName);
writeResult(result);
} finally {
if (deleteTemplate) {
transloadit.deleteTemplate(templateId);
}
}

System.out.println("Java SDK devdock scenario " + scenario.getString("scenarioId")
+ " passed for " + templateId);
}

private static JSONObject deletedGetResult(Transloadit transloadit, String templateId) throws Exception {
Response response = transloadit.getTemplate(templateId);
JSONObject body = response.json();
boolean succeeded = response.status() >= 200 && response.status() < 300 && !body.has("error");

JSONObject result = new JSONObject();
result.put("deletedGetSucceeded", succeeded);
result.put("deletedErrorCode", body.optString("error", body.optString("ok", "")));
return result;
}

private static JSONObject loadScenario() throws Exception {
String scenarioPath = System.getenv("API2_SDK_EXAMPLE_SCENARIO");
if (scenarioPath == null || scenarioPath.isEmpty()) {
scenarioPath = "examples/api2-devdock-template-lifecycle/api2-scenario.json";
}

byte[] contents = Files.readAllBytes(Paths.get(scenarioPath));
return new JSONObject(new String(contents, StandardCharsets.UTF_8));
}

private static String requiredEnv(String name) {
String value = System.getenv(name);
if (value == null || value.isEmpty()) {
throw new IllegalStateException(name + " must be set");
}

return value;
}

private static Map<String, Object> templatePayload(String name, JSONObject config) {
JSONObject content = config.getJSONObject("content");
Map<String, Object> template = jsonObjectToMap(content.getJSONObject("additionalProperties"));
template.put("steps", jsonObjectToMap(content.getJSONObject("steps")));

Map<String, Object> payload = new HashMap<String, Object>();
payload.put("name", name);
payload.put("require_signature_auth", config.getBoolean("requireSignatureAuth") ? 1 : 0);
payload.put("template", template);
return payload;
}

private static JSONObject templateResult(JSONObject template) {
JSONObject result = new JSONObject();
result.put("content", template.getJSONObject("content"));
result.put("id", template.getString("id"));
result.put("name", template.getString("name"));
result.put("requireSignatureAuth", template.getInt("require_signature_auth") != 0);
return result;
}

private static Map<String, Object> jsonObjectToMap(JSONObject object) {
Map<String, Object> map = new HashMap<String, Object>();
for (Iterator<String> keys = object.keys(); keys.hasNext();) {
String key = keys.next();
map.put(key, jsonValueToJava(object.get(key)));
}

return map;
}

private static Object jsonValueToJava(Object value) {
if (value == JSONObject.NULL) {
return null;
}

if (value instanceof JSONObject) {
return jsonObjectToMap((JSONObject) value);
}

if (value instanceof JSONArray) {
JSONArray array = (JSONArray) value;
List<Object> list = new ArrayList<Object>();
for (int index = 0; index < array.length(); index += 1) {
list.add(jsonValueToJava(array.get(index)));
}

return list;
}

return value;
}

private static void writeResult(JSONObject result) throws Exception {
String resultPath = System.getenv("API2_SDK_EXAMPLE_RESULT");
if (resultPath == null || resultPath.isEmpty()) {
return;
}

Files.write(
Paths.get(resultPath),
(result.toString(2) + "\n").getBytes(StandardCharsets.UTF_8));
}

private Api2DevdockTemplateLifecycle() {
throw new IllegalStateException("Utility class");
}
}
Loading
Loading