|
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
|
|
|
public function assignments(): EnvelopeDocumentAssignmentsEndpoint |
|
34
|
|
|
{ |
|
35
|
|
|
return new EnvelopeDocumentAssignmentsEndpoint($this); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param mixed[] $body |
|
40
|
|
|
*/ |
|
41
|
|
|
public function positions(array $body): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->putRequest('/positions', ['json' => $body]); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function merge(): EnvelopeDocument |
|
47
|
|
|
{ |
|
48
|
|
|
$response = $this->postRequest("/merge"); |
|
49
|
|
|
|
|
50
|
|
|
return $this->makeResource($response); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param mixed[] $query |
|
55
|
|
|
*/ |
|
56
|
|
|
public function download(string $id, array $query = []): FileResponse |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->stream(self::METHOD_GET, '/{id}/download', ['id' => $id, 'query' => $query]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param mixed[] $query |
|
63
|
|
|
* @return ListResource<EnvelopeTag> |
|
64
|
|
|
*/ |
|
65
|
|
|
public function tags(string $id, array $query = []): ListResource |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->createListResource( |
|
68
|
|
|
$this->getRequest('/{id}/tags', ['id' => $id, 'query' => $query]), |
|
69
|
|
|
EnvelopeTag::class |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param EnvelopeDocument|string $document |
|
75
|
|
|
* @param mixed[] $body |
|
76
|
|
|
*/ |
|
77
|
|
|
public function replaceFile($document, array $body): EnvelopeDocument |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->makeResource( |
|
|
|
|
|
|
80
|
|
|
$this->postRequest('/{document}/replace-file', ['document' => $document, 'json' => $body]) |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|