Skip to content

Commit b8cf715

Browse files
authored
Merge pull request #33 from signnow/add-update-document-name-action-v1
Add update document name action (v1)
2 parents ad1b49c + c5e7f43 commit b8cf715

File tree

4 files changed

+70
-7
lines changed

4 files changed

+70
-7
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+
## [v1.5.6] - 2023-02-28
8+
### Added
9+
- Action to modify document name
10+
711
## [v1.5.5] - 2022-11-22
812
### Added
913
- Support move document

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Simple API Client to integrate SignNow with your application or website. Sign do
2121
* [Retrieve document](#retrieve-document)
2222
* [Delete document](#delete-document)
2323
* [Download document](#download-document)
24+
* [Modify document name](#modify-document-name)
2425
* [Create a single-use link for document downloading](#document-download-link)
2526
* [Create a role-based invite to sign a document](#role-invite-document)
2627
* [Create a simple free form invite to sign a document](#free-form-invite-document)
@@ -212,6 +213,24 @@ $entityManager->get(new DocumentDownload(), ['id' => $documentUniqueId], ['type'
212213
// if need table containing the document's history set with_history=1
213214
$entityManager->get(new DocumentDownload(), ['id' => $documentUniqueId], ['type' => 'collapsed', 'with_history' => 1]);
214215
```
216+
#### <a name="modify-document-name"></a>Modify document name
217+
```php
218+
use SignNow\Api\Action\Document;
219+
use SignNow\Api\Action\OAuth as SignNowOAuth;
220+
221+
$auth = new SignNowOAuth(HOST);
222+
$entityManager = $auth->bearerByPassword(
223+
BASIC_TOKEN,
224+
USER,
225+
PASSWORD
226+
);
227+
228+
$documentUniqueId = 'd136ce0211a74a808de9fefe7249446fe452e566';
229+
$documentName = 'Your document name to be modified';
230+
231+
$document = new Document($entityManager);
232+
$documentEntity = $document->modifyName($documentUniqueId, $documentName);
233+
```
215234
#### <a name="document-download-link"></a>Create a single-use link for document downloading
216235
```php
217236
use SignNow\Api\Entity\Document\DownloadLink;

src/Action/Document.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace SignNow\Api\Action;
@@ -42,7 +43,7 @@ public function __construct(EntityManager $entityManager)
4243

4344
/**
4445
* @param string $filePath
45-
*
46+
*
4647
* @return DocumentEntity|object
4748
* @throws ReflectionException
4849
* @throws EntityManagerException
@@ -70,7 +71,7 @@ public function uploadWithTags(string $filePath, array $textTags): DocumentEntit
7071
foreach ($textTags as $textTag) {
7172
$tags[] = $textTag->toArray();
7273
}
73-
74+
7475
return $this->entityManager->create(new DocumentUploadFieldExtract(new SplFileInfo($filePath), $tags));
7576
}
7677

@@ -106,12 +107,12 @@ public function addFields(string $documentUniqueId, array $fields): DocumentEnti
106107
$document = new DocumentEntity();
107108
$document->setId($documentUniqueId);
108109
$document->setFields($fields);
109-
110+
110111
$this->entityManager->setUpdateHttpMethod(Request::METHOD_PUT);
111-
112+
112113
return $this->entityManager->update($document);
113114
}
114-
115+
115116
/**
116117
* @param string $documentUniqueId
117118
*
@@ -128,7 +129,7 @@ public function delete(string $documentUniqueId): void
128129
]
129130
);
130131
}
131-
132+
132133
/**
133134
* @param string $documentUniqueId
134135
* @param DocumentDownloadLinkParams|null $queryParams
@@ -150,7 +151,7 @@ public function download(string $documentUniqueId, ?DocumentDownloadLinkParams $
150151

151152
/**
152153
* Create a single-use link for document downloading
153-
*
154+
*
154155
* @param string $documentUniqueId
155156
*
156157
* @return object|DocumentDownloadLink
@@ -166,4 +167,22 @@ public function createDownloadLink(string $documentUniqueId): DocumentDownloadLi
166167
]
167168
);
168169
}
170+
171+
/**
172+
* @param string $newDocumentName
173+
* @param string $documentUniqueId
174+
*
175+
* @return DocumentEntity|object
176+
* @throws EntityManagerException
177+
* @throws ReflectionException
178+
*/
179+
public function modifyName(string $documentUniqueId, string $newDocumentName): DocumentEntity
180+
{
181+
$document = new DocumentEntity();
182+
$document->setId($documentUniqueId);
183+
$document->setDocumentName($newDocumentName);
184+
$this->entityManager->setUpdateHttpMethod(Request::METHOD_PUT);
185+
186+
return $this->entityManager->update($document);
187+
}
169188
}

tests/functional/Document/UpdateDocumentCest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace SignNow\Tests\Functional\Document;
@@ -89,4 +90,24 @@ public function testAddFields(FunctionalTester $I): void
8990

9091
$I->assertSame($documentUniqueId, $documentEntity->getId());
9192
}
93+
94+
/**
95+
* @param FunctionalTester $I
96+
*
97+
* @return void
98+
* @throws EntityManagerException
99+
* @throws ReflectionException
100+
*/
101+
public function testUpdateDocumentName(FunctionalTester $I): void
102+
{
103+
$document = new Document($this->auth);
104+
105+
$documentUniqueId = $I->createUniqueId();
106+
107+
$I->mockUpdateDocumentRequest($documentUniqueId);
108+
109+
$documentEntity = $document->modifyName($documentUniqueId, 'Updated Cool Name');
110+
111+
$I->assertSame($documentUniqueId, $documentEntity->getId());
112+
}
92113
}

0 commit comments

Comments
 (0)