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,83 @@ 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+ return getResult (InferenceResponse .class , inferenceId );
95+ }
96+
6697 /**
6798 * Get the result of an inference that was previously enqueued.
6899 * The inference will only be available after it has finished processing.
69100 */
70- public InferenceResponse getInference (String inferenceId ) {
101+ public <TResponse extends CommonResponse > TResponse getResult (
102+ Class <TResponse > responseClass ,
103+ String inferenceId
104+ ) {
71105 if (inferenceId == null || inferenceId .trim ().isEmpty ()) {
72106 throw new IllegalArgumentException ("inferenceId must not be null or blank." );
73107 }
74- return mindeeApi .reqGetInference (inferenceId );
108+ return mindeeApi .reqGetResult (responseClass , inferenceId );
109+ }
110+
111+ /**
112+ * @deprecated use `enqueueAndGetResult` instead.
113+ */
114+ public InferenceResponse enqueueAndGetInference (
115+ LocalInputSource inputSource ,
116+ InferenceParameters options
117+ ) throws IOException , InterruptedException {
118+ return enqueueAndGetResult (InferenceResponse .class , inputSource , options );
119+ }
120+
121+ /**
122+ * @deprecated use `enqueueAndGetResult` instead.
123+ */
124+ public InferenceResponse enqueueAndGetInference (
125+ URLInputSource inputSource ,
126+ InferenceParameters options
127+ ) throws IOException , InterruptedException {
128+ return enqueueAndGetResult (InferenceResponse .class , inputSource , options );
75129 }
76130
77131 /**
78132 * Send a local file to an async queue, poll, and parse when complete.
79133 *
80- * @param inputSource The input source to send.
81- * @param options The options to send along with the file.
134+ * @param inputSource The local input source to send.
135+ * @param params The parameters to send along with the file.
82136 * @return an instance of {@link InferenceResponse}.
83137 * @throws IOException Throws if the file can't be accessed.
84138 * @throws InterruptedException Throws if the thread is interrupted.
85139 */
86- public InferenceResponse enqueueAndGetInference (
140+ public <TResponse extends CommonResponse > TResponse enqueueAndGetResult (
141+ Class <TResponse > responseClass ,
87142 LocalInputSource inputSource ,
88- BaseParameters options
143+ BaseParameters params
89144 ) throws IOException , InterruptedException {
90- validatePollingOptions (options .getPollingOptions ());
91- JobResponse job = enqueueInference (inputSource , options );
92- return pollAndFetch (job , options );
145+ validatePollingOptions (params .getPollingOptions ());
146+ JobResponse job = enqueue (inputSource , params );
147+ return pollAndFetch (responseClass , job , params );
93148 }
94149
95150 /**
96- * Send a local file to an async queue, poll, and parse when complete.
151+ * Send a remote file to an async queue, poll, and parse when complete.
97152 *
98- * @param inputSource The input source to send.
99- * @param options The options to send along with the file.
153+ * @param inputSource The URL input source to send.
154+ * @param params The parameters to send along with the file.
100155 * @return an instance of {@link InferenceResponse}.
101156 * @throws IOException Throws if the file can't be accessed.
102157 * @throws InterruptedException Throws if the thread is interrupted.
103158 */
104- public InferenceResponse enqueueAndGetInference (
159+ public <TResponse extends CommonResponse > TResponse enqueueAndGetResult (
160+ Class <TResponse > responseClass ,
105161 URLInputSource inputSource ,
106- BaseParameters options
162+ BaseParameters params
107163 ) throws IOException , InterruptedException {
108- validatePollingOptions (options .getPollingOptions ());
109- JobResponse job = enqueueInference (inputSource , options );
110- return pollAndFetch (job , options );
164+ validatePollingOptions (params .getPollingOptions ());
165+ JobResponse job = enqueue (inputSource , params );
166+ return pollAndFetch (responseClass , job , params );
111167 }
112168
113169 /**
@@ -117,7 +173,8 @@ public InferenceResponse enqueueAndGetInference(
117173 * @return an instance of {@link InferenceResponse}.
118174 * @throws InterruptedException Throws if interrupted.
119175 */
120- private InferenceResponse pollAndFetch (
176+ private <TResponse extends CommonResponse > TResponse pollAndFetch (
177+ Class <TResponse > responseClass ,
121178 JobResponse initialJob ,
122179 BaseParameters options
123180 ) throws InterruptedException {
@@ -135,7 +192,7 @@ private InferenceResponse pollAndFetch(
135192 attempts = max ;
136193 }
137194 if (resp .getJob ().getStatus ().equals ("Processed" )) {
138- return getInference ( resp .getJob ().getId ());
195+ return getResult ( responseClass , resp .getJob ().getId ());
139196 }
140197 attempts ++;
141198 }
0 commit comments