From f9862853644c9a5c09bbd1cbd773dd8b79fe9519 Mon Sep 17 00:00:00 2001 From: Cherkashyn Ihor Date: Tue, 28 Feb 2023 12:16:52 +0100 Subject: [PATCH] Added action to modify document name --- CHANGELOG.md | 4 ++++ README.md | 19 ++++++++++++++++++ src/Action/Document.php | 18 +++++++++++++++++ .../Document/UpdateDocumentCest.php | 20 +++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f81af8..dae23c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v2.2.6] - 2023-02-28 +### Added +- Support modify document name + ## [v2.2.5] - 2022-11-22 ### Added - Support move document diff --git a/README.md b/README.md index e1dbf89..1f9efc1 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Simple API Client to integrate SignNow with your application or website. Sign do * [Retrieve document](#retrieve-document) * [Delete document](#delete-document) * [Download document](#download-document) + * [Modify document name](#modify-document-name) * [Create a single-use link for document downloading](#document-download-link) * [Create a role-based invite to sign a document](#role-invite-document) * [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' // if need table containing the document's history set with_history=1 $entityManager->get(new DocumentDownload(), ['id' => $documentUniqueId], ['type' => 'collapsed', 'with_history' => 1]); ``` +#### Modify document name +```php +use SignNow\Api\Action\Document; +use SignNow\Api\Action\OAuth as SignNowOAuth; + +$auth = new SignNowOAuth(HOST); +$entityManager = $auth->bearerByPassword( + BASIC_TOKEN, + USER, + PASSWORD +); + +$documentUniqueId = 'd136ce0211a74a808de9fefe7249446fe452e566'; +$documentName = 'Your document name to be modified'; + +$document = new Document($entityManager); +$documentEntity = $document->modifyName($documentUniqueId, $documentName); +``` #### Create a single-use link for document downloading ```php use SignNow\Api\Entity\Document\DownloadLink; diff --git a/src/Action/Document.php b/src/Action/Document.php index ec5b120..9ea2c60 100644 --- a/src/Action/Document.php +++ b/src/Action/Document.php @@ -167,4 +167,22 @@ public function createDownloadLink(string $documentUniqueId): DocumentDownloadLi ] ); } + + /** + * @param string $newDocumentName + * @param string $documentUniqueId + * + * @return DocumentEntity|object + * @throws EntityManagerException + * @throws ReflectionException + */ + public function modifyName(string $documentUniqueId, string $newDocumentName): DocumentEntity + { + $document = new DocumentEntity(); + $document->setId($documentUniqueId); + $document->setDocumentName($newDocumentName); + $this->entityManager->setUpdateHttpMethod(Request::METHOD_PUT); + + return $this->entityManager->update($document); + } } diff --git a/tests/functional/Document/UpdateDocumentCest.php b/tests/functional/Document/UpdateDocumentCest.php index 657bfa5..3630b31 100644 --- a/tests/functional/Document/UpdateDocumentCest.php +++ b/tests/functional/Document/UpdateDocumentCest.php @@ -90,4 +90,24 @@ public function testAddFields(FunctionalTester $I): void $I->assertSame($documentUniqueId, $documentEntity->getId()); } + + /** + * @param FunctionalTester $I + * + * @return void + * @throws EntityManagerException + * @throws ReflectionException + */ + public function testUpdateDocumentName(FunctionalTester $I): void + { + $document = new Document($this->auth); + + $documentUniqueId = $I->createUniqueId(); + + $I->mockUpdateDocumentRequest($documentUniqueId); + + $documentEntity = $document->modifyName($documentUniqueId, 'Updated Cool Name'); + + $I->assertSame($documentUniqueId, $documentEntity->getId()); + } }