From 17f4e8b3055fa7a7b9675d5cb79b7e355264f0a4 Mon Sep 17 00:00:00 2001 From: Alejandro Uribe Date: Wed, 13 Dec 2023 10:04:36 -0500 Subject: [PATCH 1/3] Update Client.php --- src/veryfi/Client.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/veryfi/Client.php b/src/veryfi/Client.php index 6b2025f..418a8b8 100644 --- a/src/veryfi/Client.php +++ b/src/veryfi/Client.php @@ -519,4 +519,35 @@ public function delete_tag(int $document_id, $request_arguments = array(); return $this->request('DELETE', $endpoint_name, $request_arguments); } + + /** + * Add multiple tags on an existing document + * + * @param int $document_id ID of the document you'd like to add a Tag + * @param array $tags array of strings + * @return string Added tag data + */ + public function add_tags(int $document_id, + array $tags): string + { + $endpoint_name = "/documents/$document_id/tags/"; + $request_arguments = array('tags' => $tags); + return $this->request('POST', $endpoint_name, $request_arguments); + } + + /** + * Replace multiple tags on an existing document + * + * @param int $document_id ID of the document you'd like to add a Tag + * @param array $tags array of strings + * @return string Added tag data + */ + public function replace_tags(int $document_id, + array $tags): string + { + $endpoint_name = "/documents/$document_id/"; + $request_arguments = array('tags' => $tags); + return $this->request('PUT', $endpoint_name, $request_arguments); + } + } From 31c5f2f4b7d70f8be506cb5c3473b5d70a026d8e Mon Sep 17 00:00:00 2001 From: Alejandro Uribe Date: Tue, 2 Jan 2024 12:56:32 -0500 Subject: [PATCH 2/3] Update ClientTest.php --- tests/ClientTest.php | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 050a74c..335d739 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -459,4 +459,50 @@ public function test_delete_tag(): void $json_response = json_decode($veryfi_client->delete_tag($document_id, $tag_id), true); $this->assertEmpty($json_response); } + + public function test_replace_document_tags(): void + { + $document_id = 140804210; + if ($this->mock_responses) { + $veryfi_client = $this->getMockBuilder(Client::class) + ->onlyMethods(['exec_curl']) + ->setConstructorArgs([$this->client_id, $this->client_secret, $this->username, $this->api_key]) + ->getMock(); + + $file_path = __DIR__ . '/resources/getTags.json'; + $file = fopen($file_path, 'r'); + $file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8'); + $veryfi_client->expects($this->once()) + ->method('exec_curl') + ->willReturn($file_data); + } else { + $veryfi_client = new Client($this->client_id, $this->client_secret, $this->username, $this->api_key); + } + $tags = array('TAG_1', 'TAG_2', 'TAG_3'); + $json_response = json_decode($veryfi_client->replace_tags($document_id, $tags), true); + $this->assertNotEmpty($json_response); + } + + public function test_add_document_tags(): void + { + $document_id = 140804210; + if ($this->mock_responses) { + $veryfi_client = $this->getMockBuilder(Client::class) + ->onlyMethods(['exec_curl']) + ->setConstructorArgs([$this->client_id, $this->client_secret, $this->username, $this->api_key]) + ->getMock(); + + $file_path = __DIR__ . '/resources/getTags.json'; + $file = fopen($file_path, 'r'); + $file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8'); + $veryfi_client->expects($this->once()) + ->method('exec_curl') + ->willReturn($file_data); + } else { + $veryfi_client = new Client($this->client_id, $this->client_secret, $this->username, $this->api_key); + } + $tags = array('TAG_1', 'TAG_2', 'TAG_3'); + $json_response = json_decode($veryfi_client->add_tags($document_id, $tags), true); + $this->assertNotEmpty($json_response); + } } From 554120508eda8fb81f9f7ce1ec44d1a489fdd644 Mon Sep 17 00:00:00 2001 From: Alejandro Uribe Date: Tue, 2 Jan 2024 12:58:28 -0500 Subject: [PATCH 3/3] Update Client.php --- src/veryfi/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/veryfi/Client.php b/src/veryfi/Client.php index 418a8b8..e8f9b3d 100644 --- a/src/veryfi/Client.php +++ b/src/veryfi/Client.php @@ -129,7 +129,7 @@ public function __construct(string $client_id, private function get_headers(): array { return array( - 'User-Agent' => 'php veryfi-php/1.0.2', + 'User-Agent' => 'php veryfi-php/1.0.3', 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Client-ID' => $this->client_id,