Skip to content

Commit

Permalink
Merge pull request #17 from veryfi/feature/PLAT-5449-add-multiple-tags
Browse files Browse the repository at this point in the history
Add multiple tags
  • Loading branch information
Kaevan89 authored Jan 2, 2024
2 parents 1015b0a + 5541205 commit 3ccd837
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/veryfi/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

}
46 changes: 46 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 3ccd837

Please sign in to comment.