generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaravelDocparser.php
executable file
·166 lines (151 loc) · 5.07 KB
/
LaravelDocparser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
declare(strict_types=1);
namespace Ziming\LaravelDocparser;
use Carbon\CarbonInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
final readonly class LaravelDocparser
{
public static function make(): self
{
return new self;
}
/**
* @see https://docparser.com/api/#list-document-parsers?ref=iavng
*
* @throws ConnectionException
*/
public function listDocumentParsers(): PromiseInterface|Response
{
return Http::docparser()
->get('/v1/parsers');
}
/**
* @see https://docparser.com/api/#list-parser-model-layouts?ref=iavng
*
* @throws ConnectionException
*/
public function listParserModelLayouts(string $parserId): PromiseInterface|Response
{
return Http::docparser()
->get("/v1/parser/models/{$parserId}");
}
/**
* @see https://docparser.com/api/#import-documents?ref=iavng
*
* @throws ConnectionException
*/
public function uploadDocumentFromLocalPath(string $parserId, string $filePath, ?string $remoteId = null): PromiseInterface|Response
{
return Http::docparser()
->post("/v1/document/upload/{$parserId}", [
'file' => $filePath,
'remote_id' => $remoteId,
]);
}
/**
* @see https://docparser.com/api/#import-documents?ref=iavng
*
* @throws ConnectionException
*/
public function uploadDocumentByContent(string $parserId, string $fileContent, ?string $fileName = null, ?string $remoteId = null): PromiseInterface|Response
{
return Http::docparser()
->post("/v1/document/upload/{$parserId}", [
'file_content' => $fileContent,
'file_name' => $fileName,
'remote_id' => $remoteId,
]);
}
/**
* @see https://docparser.com/api/#import-documents?ref=iavng
*
* @throws ConnectionException
*/
public function fetchDocumentFromUrl(string $parserId, string $url, ?string $remoteId = null): PromiseInterface|Response
{
return Http::docparser()
->post("/v2/document/fetch/{$parserId}", [
'url' => $url,
'remote_id' => $remoteId,
]);
}
/**
* @see https://docparser.com/api/#document-status?ref=iavng
*
* @throws ConnectionException
*/
public function documentStatus(string $parserId, string $documentId): PromiseInterface|Response
{
return Http::docparser()
->get("/v2/document/status/{$parserId}/{$documentId}");
}
/**
* @see https://docparser.com/api/#get-data-of-one-document?ref=iavng
*
* @throws ConnectionException
*/
public function getDataOfOneDocument(string $parserId, string $documentId, ?string $format = null, ?bool $includeChildren = null): PromiseInterface|Response
{
return Http::docparser()
->get("/v1/results/{$parserId}/{$documentId}", [
'format' => $format,
'include_children' => $includeChildren,
]);
}
/**
* @see https://docparser.com/api/#get-data-of-multiple-documents?ref=iavng
*
* @throws ConnectionException
*/
public function getDataOfMultipleDocuments(string $parserId, ?string $format = null, ?string $list = null, ?int $limit = null, ?CarbonInterface $date = null, ?string $remoteId = null, ?bool $includeProcessingQueue = null, ?string $sortBy = null, ?string $sortOrder = null): PromiseInterface|Response
{
return Http::docparser()
->get("/v1/results/{$parserId}", [
'format' => $format,
'list' => $list,
'limit' => $limit,
'date' => $date?->toIso8601String(),
'remote_id' => $remoteId,
'include_processing_queue' => $includeProcessingQueue,
'sort_by' => $sortBy,
'sort_order' => $sortOrder,
]);
}
/**
* @see https://docparser.com/api/#re-parse-data?ref=iavng
*
* @throws ConnectionException
*/
public function reparseData(string $parserId, array $documentIds): PromiseInterface|Response
{
return Http::docparser()
->post("/v1/document/reparse/{$parserId}", [
'document_ids' => $documentIds,
]);
}
/**
* @see https://docparser.com/api/#re-integrate-data?ref=iavng
*
* @throws ConnectionException
*/
public function reIntegrateData(string $parserId, array $documentIds): PromiseInterface|Response
{
return Http::docparser()
->post("/v1/document/reintegrate/{$parserId}", [
'document_ids' => $documentIds,
]);
}
/**
* @see https://docparser.com/api/#authentication?ref=iavng
*
* @throws ConnectionException
*/
public function ping(): PromiseInterface|Response
{
return Http::docparser()
->get('/v1/ping');
}
}