Skip to content

Commit f5d296c

Browse files
fixes
1 parent 1d32449 commit f5d296c

4 files changed

Lines changed: 71 additions & 40 deletions

File tree

src/ClientV2.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,28 @@ public function getInference(string $inferenceId): InferenceResponse
8080
* @template T of BaseResponse
8181
* @param string $responseClass The response class to construct.
8282
* @phpstan-param class-string<T> $responseClass
83-
* @param string $jobUrl URL of the job.
83+
* @param string $resultUrl URL of the result.
8484
* @return T A response containing parsing results.
8585
*/
8686
public function getResultFromUrl(
8787
string $responseClass,
88-
string $jobUrl
88+
string $resultUrl
8989
): BaseResponse {
90-
return $this->mindeeApi->reqGetResultFromUrl($responseClass, $jobUrl);
90+
return $this->mindeeApi->reqGetResultFromUrl($responseClass, $resultUrl);
91+
}
92+
93+
/**
94+
* @template T of BaseResponse
95+
* @param string $responseClass The response class to construct.
96+
* @phpstan-param class-string<T> $responseClass
97+
* @param string $resultId ID of the result.
98+
* @return T A response containing parsing results.
99+
*/
100+
public function getResult(
101+
string $responseClass,
102+
string $resultId
103+
): BaseResponse {
104+
return $this->mindeeApi->reqGetResult($responseClass, $resultId);
91105
}
92106

93107
/**

src/Http/MindeeApiV2.php

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -372,49 +372,14 @@ private function documentEnqueuePost(
372372
): array {
373373
/** @var CurlHandle $ch */
374374
$ch = $this->initChannel();
375-
$postFields = ['model_id' => $params->modelId];
375+
$postFields = $params->asHash();
376+
376377
if ($inputSource instanceof URLInputSource) {
377378
$postFields['url'] = $inputSource->url;
378379
} elseif ($inputSource instanceof LocalInputSource) {
379380
$inputSource->checkNeedsFix();
380381
$postFields['file'] = $inputSource->fileObject;
381382
}
382-
383-
if (is_a($params, InferenceParameters::class)) {
384-
if (isset($params->rawText)) {
385-
$postFields['raw_text'] = $params->rawText ? 'true' : 'false';
386-
}
387-
if (isset($params->polygon)) {
388-
$postFields['polygon'] = $params->polygon ? 'true' : 'false';
389-
}
390-
if (isset($params->confidence)) {
391-
$postFields['confidence'] = $params->confidence ? 'true' : 'false';
392-
}
393-
if (isset($params->rag)) {
394-
$postFields['rag'] = $params->rag ? 'true' : 'false';
395-
}
396-
if (isset($params->textContext)) {
397-
$postFields['text_context'] = $params->textContext;
398-
}
399-
if (isset($params->dataSchema)) {
400-
$postFields['data_schema'] = strval($params->dataSchema);
401-
}
402-
}
403-
if (isset($params->webhooksIds) && count($params->webhooksIds) > 0) {
404-
if (PHP_VERSION_ID < 80200 && count($params->webhooksIds) > 1) {
405-
// NOTE: see https://bugs.php.net/bug.php?id=51634
406-
error_log("PHP version is too low to support webbook array destructuring.
407-
\nOnly the first webhook ID will be sent to the server.");
408-
$postFields['webhook_ids'] = $params->webhooksIds[0];
409-
} else {
410-
foreach ($params->webhooksIds as $webhookId) {
411-
$postFields['webhook_ids[]'] = $webhookId;
412-
}
413-
}
414-
}
415-
if (isset($params->alias)) {
416-
$postFields['alias'] = $params->alias;
417-
}
418383
$url = $this->baseUrl . "/products/{$params::$slug}/enqueue";
419384
curl_setopt($ch, CURLOPT_URL, $url);
420385
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

src/Input/InferenceParameters.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,31 @@ public function __construct(
8888
$this->dataSchema = new DataSchema($dataSchema);
8989
}
9090
}
91+
92+
/**
93+
* @return array Hash representation.
94+
*/
95+
public function asHash(): array
96+
{
97+
$outHash = parent::asHash();
98+
if (isset($this->rag)) {
99+
$outHash['rag'] = $this->rag;
100+
}
101+
if (isset($this->rawText)) {
102+
$outHash['raw_text'] = $this->rawText;
103+
}
104+
if (isset($this->polygon)) {
105+
$outHash['polygon'] = $this->polygon;
106+
}
107+
if (isset($this->confidence)) {
108+
$outHash['confidence'] = $this->confidence;
109+
}
110+
if (isset($this->textContext)) {
111+
$outHash['text_context'] = $this->textContext;
112+
}
113+
if (isset($this->dataSchema)) {
114+
$outHash['data_schema'] = strval($this->dataSchema);
115+
}
116+
return $outHash;
117+
}
91118
}

src/V2/ClientOptions/BaseParameters.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,29 @@ public function __construct(string $modelId, ?string $alias, ?array $webhooksIds
5252
}
5353
$this->pollingOptions = $pollingOptions;
5454
}
55+
56+
/**
57+
* @return array Hash representation.
58+
*/
59+
public function asHash(): array
60+
{
61+
$outHash = ['model_id' => $this->modelId];
62+
if (isset($this->alias)) {
63+
$outHash['alias'] = $this->alias;
64+
}
65+
66+
if (isset($this->webhooksIds) && count($this->webhooksIds) > 0) {
67+
if (PHP_VERSION_ID < 80200 && count($this->webhooksIds) > 1) {
68+
// NOTE: see https://bugs.php.net/bug.php?id=51634
69+
error_log("PHP version is too low to support webbook array destructuring.
70+
\nOnly the first webhook ID will be sent to the server.");
71+
$outHash['webhook_ids'] = $this->webhooksIds[0];
72+
} else {
73+
foreach ($this->webhooksIds as $webhookId) {
74+
$outHash['webhook_ids[]'] = $webhookId;
75+
}
76+
}
77+
}
78+
return $outHash;
79+
}
5580
}

0 commit comments

Comments
 (0)