Issues (49)

src/Endpoint/EnvelopesEndpoint.php (4 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace DigitalCz\DigiSign\Endpoint;
6
7
use DigitalCz\DigiSign\DigiSign;
8
use DigitalCz\DigiSign\Endpoint\Traits\CRUDEndpointTrait;
9
use DigitalCz\DigiSign\Resource\BaseResource;
10
use DigitalCz\DigiSign\Resource\Envelope;
11
use DigitalCz\DigiSign\Resource\EnvelopeTemplate;
12
use DigitalCz\DigiSign\Stream\FileResponse;
13
14
/**
15
 * @extends ResourceEndpoint<Envelope>
16
 * @method Envelope get(string $id)
17
 * @method Envelope create(array $body)
18
 * @method Envelope update(string $id, array $body)
19
 */
20
final class EnvelopesEndpoint extends ResourceEndpoint
21
{
22
    /** @use CRUDEndpointTrait<Envelope> */
23
    use CRUDEndpointTrait;
24
25
    public function __construct(DigiSign $parent)
26
    {
27
        parent::__construct($parent, '/api/envelopes', Envelope::class);
28
    }
29
30
    /**
31
     * @param Envelope|string $envelope
32
     */
33
    public function documents($envelope): EnvelopeDocumentsEndpoint
34
    {
35
        return new EnvelopeDocumentsEndpoint($this, $envelope);
36
    }
37
38
    /**
39
     * @param Envelope|string $envelope
40
     */
41
    public function recipients($envelope): EnvelopeRecipientsEndpoint
42
    {
43
        return new EnvelopeRecipientsEndpoint($this, $envelope);
44
    }
45
46
    /**
47
     * @param Envelope|string $envelope
48
     */
49
    public function tags($envelope): EnvelopeTagsEndpoint
50
    {
51
        return new EnvelopeTagsEndpoint($this, $envelope);
52
    }
53
54
    /**
55
     * @param Envelope|string $envelope
56
     */
57
    public function notifications($envelope): EnvelopeNotificationsEndpoint
58
    {
59
        return new EnvelopeNotificationsEndpoint($this, $envelope);
60
    }
61
62
    /**
63
     * @param Envelope|string $envelope
64
     */
65
    public function labels($envelope): EnvelopeLabelsEndpoint
66
    {
67
        return new EnvelopeLabelsEndpoint($this, $envelope);
68
    }
69
70
    public function cancel(string $id): BaseResource
71
    {
72
        return $this->createResource($this->postRequest('/{id}/cancel', ['id' => $id]));
73
    }
74
75
    public function count(): BaseResource
76
    {
77
        return $this->createResource($this->getRequest('/count'));
78
    }
79
80
    /**
81
     * @param mixed[] $query
82
     */
83
    public function download(string $id, array $query = []): FileResponse
84
    {
85
        return $this->stream(self::METHOD_GET, '/{id}/download', ['id' => $id, 'query' => $query]);
86
    }
87
88
    /**
89
     * @param mixed[] $body
90
     */
91
    public function embedEdit(string $id, array $body = []): BaseResource
92
    {
93
        return $this->createResource($this->postRequest('/{id}/embed/edit', ['id' => $id, 'json' => $body]));
94
    }
95
96
    /**
97
     * @param mixed[] $body
98
     */
99
    public function embedSigning(string $id, array $body = []): BaseResource
100
    {
101
        return $this->createResource($this->postRequest('/{id}/embed/signing', ['id' => $id, 'json' => $body]));
102
    }
103
104
    /**
105
     * @param mixed[] $body
106
     */
107
    public function extend(string $id, array $body): Envelope
108
    {
109
        return $this->makeResource($this->putRequest('/{id}/extend', ['id' => $id, 'json' => $body]));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->makeResour...$id, 'json' => $body))) returns the type DigitalCz\DigiSign\Resource\ResourceInterface which includes types incompatible with the type-hinted return DigitalCz\DigiSign\Resource\Envelope.
Loading history...
110
    }
111
112
    public function send(string $id): BaseResource
113
    {
114
        return $this->createResource($this->postRequest('/{id}/send', ['id' => $id]));
115
    }
116
117
    public function resend(string $id): BaseResource
118
    {
119
        return $this->createResource($this->postRequest('/{id}/resend', ['id' => $id]));
120
    }
121
122
    /**
123
     * @param Envelope|string $id
124
     */
125
    public function template($id): EnvelopeTemplate
126
    {
127
        return $this->createResource($this->getRequest('/{id}/template', ['id' => $id]), EnvelopeTemplate::class);
128
    }
129
130
    /**
131
     * @param Envelope|string $id
132
     */
133
    public function clone($id): Envelope
134
    {
135
        return $this->makeResource($this->postRequest('/{id}/clone', ['id' => $id]));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->makeResour...', array('id' => $id))) returns the type DigitalCz\DigiSign\Resource\ResourceInterface which includes types incompatible with the type-hinted return DigitalCz\DigiSign\Resource\Envelope.
Loading history...
136
    }
137
138
    /**
139
     * @param Envelope|string $id
140
     * @param mixed[] $body
141
     */
142
    public function discard($id, array $body = []): Envelope
143
    {
144
        return $this->makeResource($this->postRequest('/{id}/discard', ['id' => $id, 'json' => $body]));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->makeResour...$id, 'json' => $body))) returns the type DigitalCz\DigiSign\Resource\ResourceInterface which includes types incompatible with the type-hinted return DigitalCz\DigiSign\Resource\Envelope.
Loading history...
145
    }
146
147
    /**
148
     * @param Envelope|string $id
149
     */
150
    public function restore($id): Envelope
151
    {
152
        return $this->makeResource($this->postRequest('/{id}/restore', ['id' => $id]));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->makeResour...', array('id' => $id))) returns the type DigitalCz\DigiSign\Resource\ResourceInterface which includes types incompatible with the type-hinted return DigitalCz\DigiSign\Resource\Envelope.
Loading history...
153
    }
154
155
    /**
156
     * @param Envelope|string $id
157
     */
158
    public function validate($id): void
159
    {
160
        $this->getRequest('/{id}/validate', ['id' => $id]);
161
    }
162
163
    /**
164
     * @param Envelope|string $id
165
     */
166
    public function startCorrection($id): void
167
    {
168
        $this->postRequest('/{id}/start-correction', ['id' => $id]);
169
    }
170
171
    /**
172
     * @param Envelope|string $id
173
     * @param mixed[] $body
174
     */
175
    public function finishCorrection($id, array $body = []): void
176
    {
177
        $this->postRequest('/{id}/finish-correction', ['id' => $id, 'json' => $body]);
178
    }
179
}
180