Skip to content

Commit

Permalink
[DGS-2634] add BatchSendings and BatchSendingsItems endpoints
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
pavelvais committed Aug 27, 2024
1 parent 1ac1004 commit a91962b
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/DigiSign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
31 changes: 31 additions & 0 deletions src/Endpoint/BatchSendingsEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DigitalCz\DigiSign\Endpoint;

use DigitalCz\DigiSign\DigiSign;
use DigitalCz\DigiSign\Endpoint\Traits\CreateEndpointTrait;
use DigitalCz\DigiSign\Endpoint\Traits\GetEndpointTrait;
use DigitalCz\DigiSign\Endpoint\Traits\UpdateEndpointTrait;
use DigitalCz\DigiSign\Resource\BatchSending;

/**
* @extends ResourceEndpoint<BatchSending>
*/
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);
}
}
32 changes: 32 additions & 0 deletions src/Endpoint/BatchSendingsItemsEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace DigitalCz\DigiSign\Endpoint;

use DigitalCz\DigiSign\Resource\BaseResource;

/**
* @extends ResourceEndpoint<BaseResource>
*/
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,
],
],
),
);
}
}
34 changes: 34 additions & 0 deletions src/Resource/BatchSending.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace DigitalCz\DigiSign\Resource;

use DigitalCz\DigiSign\Resource\Traits\EntityResourceTrait;

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8 (prefer-stable)

Expected 1 line after last use statement, found 2.

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8 (prefer-stable)

Header blocks must be separated by a single blank line

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 (prefer-lowest)

Expected 1 line after last use statement, found 2.

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 (prefer-lowest)

Header blocks must be separated by a single blank line

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 (prefer-stable)

Expected 1 line after last use statement, found 2.

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 (prefer-stable)

Header blocks must be separated by a single blank line

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 (prefer-lowest)

Expected 1 line after last use statement, found 2.

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 (prefer-lowest)

Header blocks must be separated by a single blank line

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 (prefer-stable)

Expected 1 line after last use statement, found 2.

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 (prefer-stable)

Header blocks must be separated by a single blank line

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8 (prefer-lowest)

Expected 1 line after last use statement, found 2.

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8 (prefer-lowest)

Header blocks must be separated by a single blank line

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 (prefer-lowest)

Expected 1 line after last use statement, found 2.

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 (prefer-lowest)

Header blocks must be separated by a single blank line

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 (prefer-stable)

Expected 1 line after last use statement, found 2.

Check failure on line 7 in src/Resource/BatchSending.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 (prefer-stable)

Header blocks must be separated by a single blank line


class BatchSending extends BaseResource
{
use EntityResourceTrait;

public string $id;

public ?string $name;

public ?string $envelopeTemplateId;

public int $itemsWaitingCount;

public int $itemsSuccessCount;

public int $itemsFailedCount;

public int $itemsTotalCount;

public string $status;

/**
* @var array<BatchSendingSlug>
*/
public array $slugs;
}
15 changes: 15 additions & 0 deletions src/Resource/BatchSendingSlug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace DigitalCz\DigiSign\Resource;

class BatchSendingSlug extends BaseResource
{
public string $alias;

/**
* @var array<int, BatchSendingSlug>
*/
public array $columns;
}
33 changes: 33 additions & 0 deletions tests/Endpoint/BatchSendingEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace DigitalCz\DigiSign\Endpoint;

/**
* @covers \DigitalCz\DigiSign\Endpoint\BatchSendingsEndpoint
*/
class BatchSendingEndpointTest extends EndpointTestCase
{
public function testChildren(): void
{
self::assertDefaultEndpointPath(self::endpoint()->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();
}
}
22 changes: 22 additions & 0 deletions tests/Endpoint/BatchSendingItemsEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace DigitalCz\DigiSign\Endpoint;

/**
* @covers \DigitalCz\DigiSign\Endpoint\BatchSendingsItemsEndpoint
*/
class BatchSendingItemsEndpointTest extends EndpointTestCase
{
public function testImport(): void
{
self::endpoint()->import('bar');
self::assertLastRequest('POST', "/api/batch-sendings/foo/items/import", ['file' => 'bar']);
}

protected static function endpoint(): BatchSendingsItemsEndpoint
{
return self::dgs()->batchSendings()->items('foo');
}
}

0 comments on commit a91962b

Please sign in to comment.