Skip to content

Commit 3ccd837

Browse files
authored
Merge pull request #17 from veryfi/feature/PLAT-5449-add-multiple-tags
Add multiple tags
2 parents 1015b0a + 5541205 commit 3ccd837

2 files changed

Lines changed: 78 additions & 1 deletion

File tree

src/veryfi/Client.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function __construct(string $client_id,
129129
private function get_headers(): array
130130
{
131131
return array(
132-
'User-Agent' => 'php veryfi-php/1.0.2',
132+
'User-Agent' => 'php veryfi-php/1.0.3',
133133
'Accept' => 'application/json',
134134
'Content-Type' => 'application/json',
135135
'Client-ID' => $this->client_id,
@@ -519,4 +519,35 @@ public function delete_tag(int $document_id,
519519
$request_arguments = array();
520520
return $this->request('DELETE', $endpoint_name, $request_arguments);
521521
}
522+
523+
/**
524+
* Add multiple tags on an existing document
525+
*
526+
* @param int $document_id ID of the document you'd like to add a Tag
527+
* @param array $tags array of strings
528+
* @return string Added tag data
529+
*/
530+
public function add_tags(int $document_id,
531+
array $tags): string
532+
{
533+
$endpoint_name = "/documents/$document_id/tags/";
534+
$request_arguments = array('tags' => $tags);
535+
return $this->request('POST', $endpoint_name, $request_arguments);
536+
}
537+
538+
/**
539+
* Replace multiple tags on an existing document
540+
*
541+
* @param int $document_id ID of the document you'd like to add a Tag
542+
* @param array $tags array of strings
543+
* @return string Added tag data
544+
*/
545+
public function replace_tags(int $document_id,
546+
array $tags): string
547+
{
548+
$endpoint_name = "/documents/$document_id/";
549+
$request_arguments = array('tags' => $tags);
550+
return $this->request('PUT', $endpoint_name, $request_arguments);
551+
}
552+
522553
}

tests/ClientTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,50 @@ public function test_delete_tag(): void
459459
$json_response = json_decode($veryfi_client->delete_tag($document_id, $tag_id), true);
460460
$this->assertEmpty($json_response);
461461
}
462+
463+
public function test_replace_document_tags(): void
464+
{
465+
$document_id = 140804210;
466+
if ($this->mock_responses) {
467+
$veryfi_client = $this->getMockBuilder(Client::class)
468+
->onlyMethods(['exec_curl'])
469+
->setConstructorArgs([$this->client_id, $this->client_secret, $this->username, $this->api_key])
470+
->getMock();
471+
472+
$file_path = __DIR__ . '/resources/getTags.json';
473+
$file = fopen($file_path, 'r');
474+
$file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8');
475+
$veryfi_client->expects($this->once())
476+
->method('exec_curl')
477+
->willReturn($file_data);
478+
} else {
479+
$veryfi_client = new Client($this->client_id, $this->client_secret, $this->username, $this->api_key);
480+
}
481+
$tags = array('TAG_1', 'TAG_2', 'TAG_3');
482+
$json_response = json_decode($veryfi_client->replace_tags($document_id, $tags), true);
483+
$this->assertNotEmpty($json_response);
484+
}
485+
486+
public function test_add_document_tags(): void
487+
{
488+
$document_id = 140804210;
489+
if ($this->mock_responses) {
490+
$veryfi_client = $this->getMockBuilder(Client::class)
491+
->onlyMethods(['exec_curl'])
492+
->setConstructorArgs([$this->client_id, $this->client_secret, $this->username, $this->api_key])
493+
->getMock();
494+
495+
$file_path = __DIR__ . '/resources/getTags.json';
496+
$file = fopen($file_path, 'r');
497+
$file_data = mb_convert_encoding(fread($file, filesize($file_path)), 'UTF-8');
498+
$veryfi_client->expects($this->once())
499+
->method('exec_curl')
500+
->willReturn($file_data);
501+
} else {
502+
$veryfi_client = new Client($this->client_id, $this->client_secret, $this->username, $this->api_key);
503+
}
504+
$tags = array('TAG_1', 'TAG_2', 'TAG_3');
505+
$json_response = json_decode($veryfi_client->add_tags($document_id, $tags), true);
506+
$this->assertNotEmpty($json_response);
507+
}
462508
}

0 commit comments

Comments
 (0)