@@ -29,22 +29,16 @@ public static void main(String[] args) throws Exception {
2929 requiredEnv ("TRANSLOADIT_SECRET" ),
3030 requiredEnv ("TRANSLOADIT_ENDPOINT" ));
3131
32- int fileCount = featureStep (
33- scenario ,
34- "preparations" ,
35- "createTusAssembly" ,
36- "feature-call" )
37- .getJSONObject ("input" )
38- .getInt ("file_count" );
39-
40- JSONObject uploadConfig = scenario .getJSONObject ("upload" );
41- JSONObject source = uploadConfig .getJSONObject ("source" );
42- byte [] bytes = source .getString ("value" ).getBytes (StandardCharsets .UTF_8 );
32+ JSONObject input = sdkFeatureCall (scenario , "uploadTusAssembly" ).getJSONObject ("input" );
33+ int fileCount = input .getInt ("file_count" );
34+
35+ JSONObject uploadConfig = input .getJSONObject ("upload" );
36+ byte [] bytes = uploadConfig .getString ("content" ).getBytes (StandardCharsets .UTF_8 );
4337 UploadTusAssemblyResult uploadResult = transloadit .uploadTusAssembly (
4438 fileCount ,
4539 bytes ,
46- uploadConfig .getString ("fieldName " ),
47- uploadConfig .getString ("fileName " ),
40+ uploadConfig .getString ("fieldname " ),
41+ uploadConfig .getString ("filename " ),
4842 uploadUserMeta (uploadConfig ));
4943 JSONObject status = uploadResult .getAssembly ().json ();
5044
@@ -69,27 +63,22 @@ private static JSONObject loadScenario() throws Exception {
6963 return new JSONObject (new String (contents , StandardCharsets .UTF_8 ));
7064 }
7165
72- private static JSONObject featureStep (
73- JSONObject scenario ,
74- String collectionName ,
75- String featureId ,
76- String kind ) {
77- JSONArray steps = scenario .getJSONArray (collectionName );
78- for (int index = 0 ; index < steps .length (); index += 1 ) {
79- JSONObject step = steps .getJSONObject (index );
80- if (!featureId .equals (step .getString ("featureId" ))) {
66+ private static JSONObject sdkFeatureCall (JSONObject scenario , String featureId ) {
67+ JSONArray featureCalls = scenario .getJSONArray ("sdkFeatureCalls" );
68+ for (int index = 0 ; index < featureCalls .length (); index += 1 ) {
69+ JSONObject featureCall = featureCalls .getJSONObject (index );
70+ if (!featureId .equals (featureCall .getString ("featureId" ))) {
8171 continue ;
8272 }
83- if (!kind .equals (step .getString ("kind" ))) {
84- throw new IllegalStateException (collectionName + " [" + index
85- + "] must have kind " + kind );
73+ if (!"sdk-feature-call" .equals (featureCall .getString ("kind" ))) {
74+ throw new IllegalStateException ("sdkFeatureCalls [" + index
75+ + "] must have kind sdk-feature-call" );
8676 }
8777
88- return step ;
78+ return featureCall ;
8979 }
9080
91- throw new IllegalStateException ("Scenario has no " + collectionName
92- + " step for feature " + featureId );
81+ throw new IllegalStateException ("Scenario has no SDK feature call for feature " + featureId );
9382 }
9483
9584 private static String requiredEnv (String name ) {
@@ -103,11 +92,11 @@ private static String requiredEnv(String name) {
10392
10493 private static Map <String , String > uploadUserMeta (JSONObject uploadConfig ) {
10594 Map <String , String > metadata = new HashMap <String , String >();
106- if (!uploadConfig .has ("userMeta " )) {
95+ if (!uploadConfig .has ("user_meta " )) {
10796 return metadata ;
10897 }
10998
110- JSONObject userMeta = uploadConfig .getJSONObject ("userMeta " );
99+ JSONObject userMeta = uploadConfig .getJSONObject ("user_meta " );
111100 for (Iterator <String > keys = userMeta .keys (); keys .hasNext ();) {
112101 String key = keys .next ();
113102 metadata .put (key , String .valueOf (userMeta .get (key )));
0 commit comments