55import com .mindee .http .MindeeHttpExceptionV2 ;
66import com .mindee .input .LocalInputSource ;
77import com .mindee .input .URLInputSource ;
8+ import com .mindee .parsing .v2 .CommonResponse ;
89import com .mindee .parsing .v2 .ErrorResponse ;
910import com .mindee .parsing .v2 .InferenceResponse ;
1011import com .mindee .parsing .v2 .JobResponse ;
@@ -33,23 +34,46 @@ public MindeeClientV2(MindeeApiV2 mindeeApi) {
3334 }
3435
3536 /**
36- * Enqueue a document in the asynchronous queue .
37+ * @deprecated use `enqueue` instead .
3738 */
3839 public JobResponse enqueueInference (
3940 LocalInputSource inputSource ,
40- BaseParameters params
41+ InferenceParameters params
4142 ) throws IOException {
42- return mindeeApi . reqPostInferenceEnqueue (inputSource , params );
43+ return enqueue (inputSource , params );
4344 }
4445
4546 /**
46- * Enqueue a document in the asynchronous queue .
47+ * @deprecated use `enqueue` instead .
4748 */
4849 public JobResponse enqueueInference (
4950 URLInputSource inputSource ,
5051 BaseParameters params
5152 ) throws IOException {
52- return mindeeApi .reqPostInferenceEnqueue (inputSource , params );
53+ return enqueue (inputSource , params );
54+ }
55+
56+ /**
57+ * Enqueue a document in the asynchronous queue.
58+ *
59+ * @param inputSource The local input source to send.
60+ * @param params The parameters to send along with the file.
61+ */
62+ public JobResponse enqueue (
63+ LocalInputSource inputSource ,
64+ BaseParameters params
65+ ) throws IOException {
66+ return mindeeApi .reqPostEnqueue (inputSource , params );
67+ }
68+
69+ /**
70+ * Enqueue a document in the asynchronous queue.
71+ *
72+ * @param inputSource The URL input source to send.
73+ * @param params The parameters to send along with the file.
74+ */
75+ public JobResponse enqueue (URLInputSource inputSource , BaseParameters params ) throws IOException {
76+ return mindeeApi .reqPostEnqueue (inputSource , params );
5377 }
5478
5579 /**
@@ -63,51 +87,86 @@ public JobResponse getJob(String jobId) {
6387 return mindeeApi .reqGetJob (jobId );
6488 }
6589
90+ /**
91+ * @deprecated use `getResult` instead.
92+ */
93+ public InferenceResponse getInference (String inferenceId ) {
94+ if (inferenceId == null || inferenceId .trim ().isEmpty ()) {
95+ throw new IllegalArgumentException ("inferenceId must not be null or blank." );
96+ }
97+ return getResult (InferenceResponse .class , inferenceId );
98+ }
99+
66100 /**
67101 * Get the result of an inference that was previously enqueued.
68102 * The inference will only be available after it has finished processing.
69103 */
70- public InferenceResponse getInference (String inferenceId ) {
104+ public <TResponse extends CommonResponse > TResponse getResult (
105+ Class <TResponse > responseClass ,
106+ String inferenceId
107+ ) {
71108 if (inferenceId == null || inferenceId .trim ().isEmpty ()) {
72109 throw new IllegalArgumentException ("inferenceId must not be null or blank." );
73110 }
74- return mindeeApi .reqGetInference (inferenceId );
111+ return mindeeApi .reqGetResult (responseClass , inferenceId );
112+ }
113+
114+ /**
115+ * @deprecated use `enqueueAndGetResult` instead.
116+ */
117+ public InferenceResponse enqueueAndGetInference (
118+ LocalInputSource inputSource ,
119+ InferenceParameters options
120+ ) throws IOException , InterruptedException {
121+ return enqueueAndGetResult (InferenceResponse .class , inputSource , options );
122+ }
123+
124+ /**
125+ * @deprecated use `enqueueAndGetResult` instead.
126+ */
127+ public InferenceResponse enqueueAndGetInference (
128+ URLInputSource inputSource ,
129+ InferenceParameters options
130+ ) throws IOException , InterruptedException {
131+ return enqueueAndGetResult (InferenceResponse .class , inputSource , options );
75132 }
76133
77134 /**
78135 * Send a local file to an async queue, poll, and parse when complete.
79136 *
80- * @param inputSource The input source to send.
81- * @param options The options to send along with the file.
137+ * @param inputSource The local input source to send.
138+ * @param params The parameters to send along with the file.
82139 * @return an instance of {@link InferenceResponse}.
83140 * @throws IOException Throws if the file can't be accessed.
84141 * @throws InterruptedException Throws if the thread is interrupted.
85142 */
86- public InferenceResponse enqueueAndGetInference (
143+ public <TResponse extends CommonResponse > TResponse enqueueAndGetResult (
144+ Class <TResponse > responseClass ,
87145 LocalInputSource inputSource ,
88- BaseParameters options
146+ BaseParameters params
89147 ) throws IOException , InterruptedException {
90- validatePollingOptions (options .getPollingOptions ());
91- JobResponse job = enqueueInference (inputSource , options );
92- return pollAndFetch (job , options );
148+ validatePollingOptions (params .getPollingOptions ());
149+ JobResponse job = enqueue (inputSource , params );
150+ return pollAndFetch (responseClass , job , params );
93151 }
94152
95153 /**
96- * Send a local file to an async queue, poll, and parse when complete.
154+ * Send a remote file to an async queue, poll, and parse when complete.
97155 *
98- * @param inputSource The input source to send.
99- * @param options The options to send along with the file.
156+ * @param inputSource The URL input source to send.
157+ * @param params The parameters to send along with the file.
100158 * @return an instance of {@link InferenceResponse}.
101159 * @throws IOException Throws if the file can't be accessed.
102160 * @throws InterruptedException Throws if the thread is interrupted.
103161 */
104- public InferenceResponse enqueueAndGetInference (
162+ public <TResponse extends CommonResponse > TResponse enqueueAndGetResult (
163+ Class <TResponse > responseClass ,
105164 URLInputSource inputSource ,
106- BaseParameters options
165+ BaseParameters params
107166 ) throws IOException , InterruptedException {
108- validatePollingOptions (options .getPollingOptions ());
109- JobResponse job = enqueueInference (inputSource , options );
110- return pollAndFetch (job , options );
167+ validatePollingOptions (params .getPollingOptions ());
168+ JobResponse job = enqueue (inputSource , params );
169+ return pollAndFetch (responseClass , job , params );
111170 }
112171
113172 /**
@@ -117,7 +176,8 @@ public InferenceResponse enqueueAndGetInference(
117176 * @return an instance of {@link InferenceResponse}.
118177 * @throws InterruptedException Throws if interrupted.
119178 */
120- private InferenceResponse pollAndFetch (
179+ private <TResponse extends CommonResponse > TResponse pollAndFetch (
180+ Class <TResponse > responseClass ,
121181 JobResponse initialJob ,
122182 BaseParameters options
123183 ) throws InterruptedException {
@@ -135,7 +195,7 @@ private InferenceResponse pollAndFetch(
135195 attempts = max ;
136196 }
137197 if (resp .getJob ().getStatus ().equals ("Processed" )) {
138- return getInference ( resp .getJob ().getId ());
198+ return getResult ( responseClass , resp .getJob ().getId ());
139199 }
140200 attempts ++;
141201 }
0 commit comments