diff --git a/src/veryfi/Client.php b/src/veryfi/Client.php index 6b2025f..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, @@ -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); + } + } 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); + } }