Skip to content

Commit 37957c3

Browse files
LuborRodRodion Liuborets
andauthored
SDK-2042 Add supporting for fetching supported documents (#250)
Co-authored-by: Rodion Liuborets <[email protected]>
1 parent 2c10869 commit 37957c3

File tree

6 files changed

+55
-15
lines changed

6 files changed

+55
-15
lines changed

src/DocScan/DocScanClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ public function deleteMediaContent(string $sessionId, string $mediaId): void
129129
}
130130

131131
/**
132-
* Gets a list of supported documents.
133-
*
132+
* @param bool $isStrictlyLatin
134133
* @return SupportedDocumentsResponse
134+
* @throws Exception\DocScanException
135135
*/
136-
public function getSupportedDocuments(): SupportedDocumentsResponse
136+
public function getSupportedDocuments(bool $isStrictlyLatin = false): SupportedDocumentsResponse
137137
{
138-
return $this->docScanService->getSupportedDocuments();
138+
return $this->docScanService->getSupportedDocuments($isStrictlyLatin);
139139
}
140140

141141
/**

src/DocScan/Service.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,23 @@ public function deleteMediaContent(string $sessionId, string $mediaId): void
185185
}
186186

187187
/**
188-
* Gets a list of supported documents.
189-
*
188+
* @param bool $isStrictlyLatin
190189
* @return SupportedDocumentsResponse
190+
* @throws DocScanException
191191
*/
192-
public function getSupportedDocuments(): SupportedDocumentsResponse
192+
public function getSupportedDocuments(bool $isStrictlyLatin): SupportedDocumentsResponse
193193
{
194-
$response = (new RequestBuilder($this->config))
194+
$requestBuilder = (new RequestBuilder($this->config))
195195
->withBaseUrl($this->apiUrl)
196196
->withEndpoint('/supported-documents')
197197
->withPemFile($this->pemFile)
198-
->withGet()
198+
->withGet();
199+
200+
if ($isStrictlyLatin) {
201+
$requestBuilder->withQueryParam('includeNonLatin', '1');
202+
}
203+
204+
$response = $requestBuilder
199205
->build()
200206
->execute();
201207

src/DocScan/Support/SupportedDocument.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ class SupportedDocument
1111
*/
1212
private $type;
1313

14+
/**
15+
* @var bool|null
16+
*/
17+
private $isStrictlyLatin;
18+
1419
/**
1520
* @param array<string, mixed> $document
1621
*/
1722
public function __construct(array $document)
1823
{
1924
$this->type = $document['type'] ?? null;
25+
$this->isStrictlyLatin = $document['is_strictly_latin'] ?? null;
2026
}
2127

2228
/**
@@ -26,4 +32,12 @@ public function getType(): ?string
2632
{
2733
return $this->type;
2834
}
35+
36+
/**
37+
* @return bool|null
38+
*/
39+
public function getIsStrictlyLatin(): ?bool
40+
{
41+
return $this->isStrictlyLatin;
42+
}
2943
}

tests/DocScan/ServiceTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,9 @@ public function getSupportedDocumentsShouldReturnSupportedDocuments()
576576
$this->callback(
577577
function (RequestInterface $requestMessage) {
578578
$expectedPathPattern = sprintf(
579-
'~^%s/supported-documents.*?~',
580-
TestData::DOC_SCAN_BASE_URL
579+
'~^%s/supported-documents\?includeNonLatin=%s.*?~',
580+
TestData::DOC_SCAN_BASE_URL,
581+
TestData::INCLUDE_NON_LATIN
581582
);
582583

583584
$this->assertEquals('GET', $requestMessage->getMethod());
@@ -600,7 +601,7 @@ function (RequestInterface $requestMessage) {
600601

601602
$this->assertInstanceOf(
602603
SupportedDocumentsResponse::class,
603-
$docScanService->getSupportedDocuments()
604+
$docScanService->getSupportedDocuments(TestData::INCLUDE_NON_LATIN)
604605
);
605606
}
606607

@@ -619,8 +620,9 @@ public function getSupportedDocumentsShouldThrowExceptionOnFailedCall()
619620
$this->callback(
620621
function (RequestInterface $requestMessage) {
621622
$expectedPathPattern = sprintf(
622-
'~^%s/supported-documents.*?~',
623-
TestData::DOC_SCAN_BASE_URL
623+
'~^%s/supported-documents\?includeNonLatin=%s.*?~',
624+
TestData::DOC_SCAN_BASE_URL,
625+
TestData::INCLUDE_NON_LATIN
624626
);
625627

626628
$this->assertEquals('GET', $requestMessage->getMethod());
@@ -644,7 +646,7 @@ function (RequestInterface $requestMessage) {
644646
$this->expectException(DocScanException::class);
645647
$this->expectExceptionMessage("Server responded with 404");
646648

647-
$docScanService->getSupportedDocuments();
649+
$docScanService->getSupportedDocuments(TestData::INCLUDE_NON_LATIN);
648650
}
649651

650652
/**

tests/DocScan/Support/SupportedDocumentTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,21 @@ public function shouldHaveType()
2727

2828
$this->assertEquals(self::SOME_DOCUMENT_TYPE, $supportedDocument->getType());
2929
}
30+
31+
/**
32+
* @test
33+
* @covers ::__construct
34+
* @covers ::getType
35+
* @covers ::getIsStrictlyLatin
36+
*/
37+
public function shouldHaveIsStrictlyLatinFlag()
38+
{
39+
$supportedDocument = new SupportedDocument([
40+
'type' => self::SOME_DOCUMENT_TYPE,
41+
'is_strictly_latin' => true,
42+
]);
43+
44+
$this->assertEquals(self::SOME_DOCUMENT_TYPE, $supportedDocument->getType());
45+
$this->assertTrue($supportedDocument->getIsStrictlyLatin());
46+
}
3047
}

tests/TestData.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ class TestData
3636
public const SOME_IMAGE_CONTENT_TYPE = 'someImageContentType';
3737
public const SOME_ID = 'someId';
3838
public const SOME_FRAMES = 1;
39+
public const INCLUDE_NON_LATIN = true;
3940
}

0 commit comments

Comments
 (0)