1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DigitalCz\DigiSign\Endpoint; |
6
|
|
|
|
7
|
|
|
use DigitalCz\DigiSign\Endpoint\Traits\CRUDEndpointTrait; |
8
|
|
|
use DigitalCz\DigiSign\Resource\Envelope; |
9
|
|
|
use DigitalCz\DigiSign\Resource\EnvelopeDocument; |
10
|
|
|
use DigitalCz\DigiSign\Resource\EnvelopeTag; |
11
|
|
|
use DigitalCz\DigiSign\Resource\ListResource; |
12
|
|
|
use DigitalCz\DigiSign\Stream\FileResponse; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @extends ResourceEndpoint<EnvelopeDocument> |
16
|
|
|
* @method EnvelopeDocument get(string $id) |
17
|
|
|
* @method EnvelopeDocument create(array $body) |
18
|
|
|
* @method EnvelopeDocument update(string $id, array $body) |
19
|
|
|
*/ |
20
|
|
|
final class EnvelopeDocumentsEndpoint extends ResourceEndpoint |
21
|
|
|
{ |
22
|
|
|
/** @use CRUDEndpointTrait<EnvelopeDocument> */ |
23
|
|
|
use CRUDEndpointTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Envelope|string $envelope |
27
|
|
|
*/ |
28
|
|
|
public function __construct(EnvelopesEndpoint $parent, $envelope) |
29
|
|
|
{ |
30
|
|
|
parent::__construct($parent, '/{envelope}/documents', EnvelopeDocument::class, ['envelope' => $envelope]); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param mixed[] $body |
35
|
|
|
*/ |
36
|
|
|
public function positions(array $body): void |
37
|
|
|
{ |
38
|
|
|
$this->putRequest('/positions', ['json' => $body]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function merge(): EnvelopeDocument |
42
|
|
|
{ |
43
|
|
|
$response = $this->postRequest("/merge"); |
44
|
|
|
|
45
|
|
|
return $this->makeResource($response); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param mixed[] $query |
50
|
|
|
*/ |
51
|
|
|
public function download(string $id, array $query = []): FileResponse |
52
|
|
|
{ |
53
|
|
|
return $this->stream(self::METHOD_GET, '/{id}/download', ['id' => $id, 'query' => $query]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param mixed[] $query |
58
|
|
|
* @return ListResource<EnvelopeTag> |
59
|
|
|
*/ |
60
|
|
|
public function tags(string $id, array $query = []): ListResource |
61
|
|
|
{ |
62
|
|
|
return $this->createListResource( |
63
|
|
|
$this->getRequest('/{id}/tags', ['id' => $id, 'query' => $query]), |
64
|
|
|
EnvelopeTag::class |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param EnvelopeDocument|string $document |
70
|
|
|
* @param mixed[] $body |
71
|
|
|
*/ |
72
|
|
|
public function replaceFile($document, array $body): EnvelopeDocument |
73
|
|
|
{ |
74
|
|
|
return $this->makeResource( |
|
|
|
|
75
|
|
|
$this->postRequest('/{document}/replace-file', ['document' => $document, 'json' => $body]) |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|