Skip to content

Commit a713c48

Browse files
authored
Merge pull request #29 from signnow/move-document
Fix issue #18 implemented move document
2 parents 21a581e + 328c2fe commit a713c48

File tree

7 files changed

+262
-0
lines changed

7 files changed

+262
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
## [v2.2.5] - 2022-11-22
8+
### Added
9+
- Support move document
10+
711
## [v2.2.4] - 2022-10-19
812
### Added
913
- Support filling smart fields of document

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,26 @@ $smartFields->addField('key', 'value');
383383

384384
$prefill->fill($documentUniqueId, $smartFields);
385385
```
386+
#### <a name="move-document"></a>Move document
387+
```php
388+
use SignNow\Api\Action\OAuth as SignNowOAuth;
389+
use SignNow\Api\Action\MoveDocumentAction;
390+
use SignNow\Api\Entity\Document\MoveDocument\MoveDocument;
391+
392+
$auth = new SignNowOAuth(HOST);
393+
$entityManager = $auth->bearerByPassword(
394+
BASIC_TOKEN,
395+
USER,
396+
PASSWORD
397+
);
398+
399+
$moveDocumentEntity = new MoveDocument();
400+
$moveDocumentEntity->setFolderId($folderId);
401+
402+
$moveDocumentAction = new MoveDocumentAction($entityManager);
403+
$moveDocumentAction->move($documentUniqueId, $moveDocumentEntity);
404+
```
405+
386406
### <a name="template"></a>Template
387407
#### <a name="create-template"></a>Create a template
388408
```php

src/Action/MoveDocumentAction.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SignNow\Api\Action;
6+
7+
use ReflectionException;
8+
use SignNow\Api\Entity\Document\MoveDocument\MoveDocument;
9+
use SignNow\Api\Entity\Document\MoveDocument\MoveDocumentResponse;
10+
use SignNow\Rest\EntityManager;
11+
use SignNow\Rest\EntityManager\Exception\EntityManagerException;
12+
use SignNow\Rest\Http\Request;
13+
14+
/**
15+
* Class MoveDocumentAction
16+
*
17+
* @package SignNow\Api\Action
18+
*/
19+
class MoveDocumentAction
20+
{
21+
/**
22+
* @var EntityManager
23+
*/
24+
private $entityManager;
25+
26+
/**
27+
* MoveDocument constructor.
28+
*
29+
* @param EntityManager $entityManager
30+
*/
31+
public function __construct(EntityManager $entityManager)
32+
{
33+
$this->entityManager = $entityManager;
34+
}
35+
36+
/**
37+
* @param string $documentUid
38+
* @param MoveDocument $moveDocument
39+
*
40+
* @return MoveDocumentResponse|object
41+
*
42+
* @throws EntityManagerException
43+
* @throws ReflectionException
44+
*/
45+
public function move(string $documentUid, MoveDocument $moveDocument): MoveDocumentResponse
46+
{
47+
$this->entityManager->setUpdateHttpMethod(Request::METHOD_POST);
48+
49+
return $this->entityManager->create(
50+
$moveDocument,
51+
[
52+
'documentUniqueId' => $documentUid,
53+
]
54+
);
55+
}
56+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SignNow\Api\Entity\Document\MoveDocument;
6+
7+
use JMS\Serializer\Annotation as Serializer;
8+
use SignNow\Rest\Entity\Entity;
9+
use SignNow\Rest\EntityManager\Annotation\HttpEntity;
10+
use SignNow\Rest\EntityManager\Annotation\ResponseType;
11+
12+
/**
13+
* Class MoveDocument
14+
*
15+
* @HttpEntity("/document/{documentUniqueId}/move", idProperty="")
16+
* @ResponseType("SignNow\Api\Entity\Document\MoveDocument\MoveDocumentResponse")
17+
*
18+
* @package SignNow\Api\Entity\Document
19+
*/
20+
class MoveDocument extends Entity
21+
{
22+
/**
23+
* @var string|null
24+
* @Serializer\Type("string")
25+
*/
26+
protected $folderId;
27+
28+
/**
29+
* @return string|null
30+
*/
31+
public function getFolderId(): ?string
32+
{
33+
return $this->folderId;
34+
}
35+
36+
/**
37+
* @param string $folderId
38+
*
39+
* @return $this
40+
*/
41+
public function setFolderId(string $folderId): self
42+
{
43+
$this->folderId = $folderId;
44+
45+
return $this;
46+
}
47+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SignNow\Api\Entity\Document\MoveDocument;
6+
7+
use JMS\Serializer\Annotation as Serializer;
8+
9+
/**
10+
* Class MoveDocumentResponse
11+
*
12+
* @package SignNow\Api\Entity\Document\Move
13+
*/
14+
class MoveDocumentResponse
15+
{
16+
/**
17+
* @var string|null
18+
* @Serializer\Type("string")
19+
*/
20+
protected $result;
21+
22+
/**
23+
* @return string|null
24+
*/
25+
public function getResult(): ?string
26+
{
27+
return $this->result;
28+
}
29+
30+
/**
31+
* @param string $result
32+
*
33+
* @return MoveDocumentResponse
34+
*/
35+
public function setResult(string $result): self
36+
{
37+
$this->result = $result;
38+
39+
return $this;
40+
}
41+
}

tests/_support/Module/Mock/ApiDocumentMock.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ApiDocumentMock extends Module implements DependsOnModule
2929
private const DOWNLOAD_DOCUMENT_LINK_URL_PATTERN = '/document/{documentUniqueId}/download/link';
3030
private const PREFILL_TEXT_FIELDS_URL_PATTERN = '/v2/documents/{documentUniqueId}/prefill-texts';
3131
private const FILL_SMART_FIELDS_URL_PATTERN = '/document/{documentUniqueId}/integration/object/smartfields';
32+
private const MOVE_DOCUMENT_URL_PATTERN = '/document/{documentUniqueId}/move';
3233

3334
/**
3435
* @var PhiremockModule
@@ -366,6 +367,33 @@ public function mockFillDocumentSmartFieldsRequest(string $documentUniqueId): vo
366367
)
367368
);
368369
}
370+
371+
/**
372+
* @param string $documentUniqueId
373+
*
374+
* @throws ClientExceptionInterface
375+
* @throws Exception
376+
*/
377+
public function mockMoveDocumentRequest(string $documentUniqueId): void
378+
{
379+
$this->phiremock->expectARequestToRemoteServiceWithAResponse(
380+
Phiremock::on(
381+
A::postRequest()
382+
->andHeader('Content-Type', Is::equalTo('application/json'))
383+
->andUrl(Is::equalTo($this->moveDocumentUrl($documentUniqueId)))
384+
)->then(
385+
Respond::withStatusCode(200)
386+
->andHeader('Content-Type', 'application/json')
387+
->andBody(
388+
json_encode(
389+
[
390+
'result' => 'success',
391+
]
392+
)
393+
)
394+
)
395+
);
396+
}
369397

370398
/**
371399
* @return string
@@ -432,4 +460,14 @@ private function fillDocumentSmartFieldsUrl(string $documentUniqueId): string
432460
{
433461
return strtr(self::FILL_SMART_FIELDS_URL_PATTERN, ['{documentUniqueId}' => $documentUniqueId]);
434462
}
463+
464+
/**
465+
* @param string $documentUniqueId
466+
*
467+
* @return string
468+
*/
469+
private function moveDocumentUrl(string $documentUniqueId): string
470+
{
471+
return strtr(self::MOVE_DOCUMENT_URL_PATTERN, ['{documentUniqueId}' => $documentUniqueId]);
472+
}
435473
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SignNow\Tests\Functional\Document;
6+
7+
use FunctionalTester;
8+
use ReflectionException;
9+
use SignNow\Api\Entity\Document\MoveDocument\MoveDocument;
10+
use SignNow\Api\Action\MoveDocumentAction as MoveDocumentAction;
11+
use SignNow\Rest\EntityManager;
12+
use SignNow\Rest\EntityManager\Exception\EntityManagerException;
13+
use SignNow\Tests\Functional\BaseCest;
14+
15+
/**
16+
* Class MoveDocumentCest
17+
*
18+
* @package SignNow\Tests\Functional\Document
19+
*/
20+
class MoveDocumentCest extends BaseCest
21+
{
22+
/**
23+
* @var EntityManager
24+
*/
25+
private $auth;
26+
27+
/**
28+
* @param FunctionalTester $I
29+
*/
30+
public function _before(FunctionalTester $I): void
31+
{
32+
$this->auth = $this->createSignNowBearerTokenAuth($I);
33+
}
34+
35+
/**
36+
* @param FunctionalTester $I
37+
*
38+
* @throws EntityManagerException
39+
* @throws ReflectionException
40+
*/
41+
public function testMoveDocument(FunctionalTester $I): void
42+
{
43+
$documentUniqueId = $I->createUniqueId();
44+
45+
$moveDocumentEntity = new MoveDocument();
46+
$moveDocumentEntity->setFolderId($I->createUniqueId());
47+
48+
$moveDocumentAction = new MoveDocumentAction($this->auth);
49+
50+
$I->mockMoveDocumentRequest($documentUniqueId);
51+
52+
$response = $moveDocumentAction->move($documentUniqueId, $moveDocumentEntity);
53+
54+
$I->assertSame('success', $response->getResult());
55+
}
56+
}

0 commit comments

Comments
 (0)