From a91962b99749d1b16824e4288d9cf3e65aafbb63 Mon Sep 17 00:00:00 2001 From: pavelvais Date: Tue, 27 Aug 2024 14:11:59 +0200 Subject: [PATCH] [DGS-2634] add BatchSendings and BatchSendingsItems endpoints - Implement BatchSendingsEndpoint for managing batch sendings. - Implement BatchSendingsItemsEndpoint for handling items within a batch. - Create BatchSending resource to represent batch sending data. - Add tests for BatchSendings and BatchSendingsItems endpoints. - Update DigiSign class to include batchSendings method. --- CHANGELOG.md | 1 + src/DigiSign.php | 6 ++++ src/Endpoint/BatchSendingsEndpoint.php | 31 +++++++++++++++++ src/Endpoint/BatchSendingsItemsEndpoint.php | 32 +++++++++++++++++ src/Resource/BatchSending.php | 34 +++++++++++++++++++ src/Resource/BatchSendingSlug.php | 15 ++++++++ tests/Endpoint/BatchSendingEndpointTest.php | 33 ++++++++++++++++++ .../BatchSendingItemsEndpointTest.php | 22 ++++++++++++ 8 files changed, 174 insertions(+) create mode 100644 src/Endpoint/BatchSendingsEndpoint.php create mode 100644 src/Endpoint/BatchSendingsItemsEndpoint.php create mode 100644 src/Resource/BatchSending.php create mode 100644 src/Resource/BatchSendingSlug.php create mode 100644 tests/Endpoint/BatchSendingEndpointTest.php create mode 100644 tests/Endpoint/BatchSendingItemsEndpointTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index a3c0755..de2ca12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip - Add `IdentifyScenarioVersion.restrictedCountries` - Add `EnvelopeTemplateDocumentAssignments` endpoint - Add `Envelope.createdBy` and `Envelope.sentBy` +- Add `BatchSendings` and `BatchSendingsItems` endpoints ## [2.4.0] - 2024-05-14 ### Added diff --git a/src/DigiSign.php b/src/DigiSign.php index 43da060..4ab3100 100644 --- a/src/DigiSign.php +++ b/src/DigiSign.php @@ -9,6 +9,7 @@ use DigitalCz\DigiSign\Auth\Credentials; use DigitalCz\DigiSign\Endpoint\AccountEndpoint; use DigitalCz\DigiSign\Endpoint\AuthEndpoint; +use DigitalCz\DigiSign\Endpoint\BatchSendingsEndpoint; use DigitalCz\DigiSign\Endpoint\DeliveriesEndpoint; use DigitalCz\DigiSign\Endpoint\EndpointInterface; use DigitalCz\DigiSign\Endpoint\EnumsEndpoint; @@ -243,6 +244,11 @@ public function deliveries(): DeliveriesEndpoint return new DeliveriesEndpoint($this); } + public function batchSendings(): BatchSendingsEndpoint + { + return new BatchSendingsEndpoint($this); + } + public function identifications(): IdentificationsEndpoint { return new IdentificationsEndpoint($this); diff --git a/src/Endpoint/BatchSendingsEndpoint.php b/src/Endpoint/BatchSendingsEndpoint.php new file mode 100644 index 0000000..d885af7 --- /dev/null +++ b/src/Endpoint/BatchSendingsEndpoint.php @@ -0,0 +1,31 @@ + + */ +final class BatchSendingsEndpoint extends ResourceEndpoint +{ + use GetEndpointTrait; + use UpdateEndpointTrait; + use CreateEndpointTrait; + + public function __construct(DigiSign $parent) + { + parent::__construct($parent, '/api/batch-sendings'); + } + + public function items(string $id): BatchSendingsItemsEndpoint + { + return new BatchSendingsItemsEndpoint($this, $id); + } +} diff --git a/src/Endpoint/BatchSendingsItemsEndpoint.php b/src/Endpoint/BatchSendingsItemsEndpoint.php new file mode 100644 index 0000000..1bea913 --- /dev/null +++ b/src/Endpoint/BatchSendingsItemsEndpoint.php @@ -0,0 +1,32 @@ + + */ +final class BatchSendingsItemsEndpoint extends ResourceEndpoint +{ + public function __construct(BatchSendingsEndpoint $parent, string $batchSending) + { + parent::__construct($parent, '/{id}/items', BaseResource::class, ['id' => $batchSending]); + } + + public function import(string $fileId): BaseResource + { + return $this->createResource( + $this->postRequest( + '/import', + [ + 'json' => [ + 'file' => $fileId, + ], + ], + ), + ); + } +} diff --git a/src/Resource/BatchSending.php b/src/Resource/BatchSending.php new file mode 100644 index 0000000..dc09bf3 --- /dev/null +++ b/src/Resource/BatchSending.php @@ -0,0 +1,34 @@ + + */ + public array $slugs; +} diff --git a/src/Resource/BatchSendingSlug.php b/src/Resource/BatchSendingSlug.php new file mode 100644 index 0000000..20e1bcc --- /dev/null +++ b/src/Resource/BatchSendingSlug.php @@ -0,0 +1,15 @@ + + */ + public array $columns; +} diff --git a/tests/Endpoint/BatchSendingEndpointTest.php b/tests/Endpoint/BatchSendingEndpointTest.php new file mode 100644 index 0000000..a8537eb --- /dev/null +++ b/tests/Endpoint/BatchSendingEndpointTest.php @@ -0,0 +1,33 @@ +items('foo'), '/api/batch-sendings/foo/items'); + } + + public function testCRUD(): void + { + self::endpoint()->get('foo'); + self::assertLastRequest('GET', "/api/batch-sendings/foo"); + + self::endpoint()->create([]); + self::assertLastRequest('POST', "/api/batch-sendings"); + + self::endpoint()->update('foo', []); + self::assertLastRequest('PUT', "/api/batch-sendings/foo"); + } + + protected static function endpoint(): BatchSendingsEndpoint + { + return self::dgs()->batchSendings(); + } +} diff --git a/tests/Endpoint/BatchSendingItemsEndpointTest.php b/tests/Endpoint/BatchSendingItemsEndpointTest.php new file mode 100644 index 0000000..c4808df --- /dev/null +++ b/tests/Endpoint/BatchSendingItemsEndpointTest.php @@ -0,0 +1,22 @@ +import('bar'); + self::assertLastRequest('POST', "/api/batch-sendings/foo/items/import", ['file' => 'bar']); + } + + protected static function endpoint(): BatchSendingsItemsEndpoint + { + return self::dgs()->batchSendings()->items('foo'); + } +}