Skip to content

Commit 87053d8

Browse files
authored
Merge pull request #43 from veryfi/feature/PLAT-5449-add-multiple-tags-function
Add multiple tags function
2 parents f7040b0 + da8a7c3 commit 87053d8

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
CHANGES
22
=======
3+
3.4.1
4+
-----
5+
* Add support to add multiple tags on existing documents
6+
37
3.4.0
48
-----
59
* Add support to add tags on existing documents

tests/test_client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,31 @@ def test_tags():
381381
)
382382
d = client.add_tag(mock_doc_id, "tag_123")
383383
assert d == mock_resp
384+
385+
386+
@responses.activate
387+
def test_replace_multiple_tags():
388+
mock_doc_id = 169985445
389+
mock_resp = {"id": 6673474, "tags": ["tag_1", "tag_2", "tag_3"]}
390+
client = Client(client_id="v", client_secret="w", username="o", api_key="c")
391+
responses.put(
392+
f"{client.versioned_url}/partner/documents/{mock_doc_id}/",
393+
json=mock_resp,
394+
status=200,
395+
)
396+
d = client.replace_tags(mock_doc_id, ["tag_1", "tag_2", "tag_3"])
397+
assert d == mock_resp
398+
399+
400+
@responses.activate
401+
def test_add_multiple_tags():
402+
mock_doc_id = 169985445
403+
mock_resp = {"id": 6673474, "tags": ["tag_1", "tag_2", "tag_3"]}
404+
client = Client(client_id="v", client_secret="w", username="o", api_key="c")
405+
responses.post(
406+
f"{client.versioned_url}/partner/documents/{mock_doc_id}/tags/",
407+
json=mock_resp,
408+
status=200,
409+
)
410+
d = client.add_tags(mock_doc_id, ["tag_1", "tag_2", "tag_3"])
411+
assert d == mock_resp

veryfi/client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _get_headers(self) -> Dict:
6161
:return: Dictionary with headers
6262
"""
6363
final_headers = {
64-
"User-Agent": "Python Veryfi-Python/3.4.0",
64+
"User-Agent": "Python Veryfi-Python/3.4.1",
6565
"Accept": "application/json",
6666
"Content-Type": "application/json",
6767
"Client-Id": self.client_id,
@@ -398,3 +398,25 @@ def add_tag(self, document_id, tag_name):
398398
endpoint_name = f"/documents/{document_id}/tags/"
399399
request_arguments = {"name": tag_name}
400400
return self._request("PUT", endpoint_name, request_arguments)
401+
402+
def replace_tags(self, document_id, tags):
403+
"""
404+
Replace multiple tags on an existing document.
405+
:param document_id: ID of the document you'd like to update
406+
:param tags: array of strings
407+
:return: Added tags data
408+
"""
409+
endpoint_name = f"/documents/{document_id}/"
410+
request_arguments = {"tags": tags}
411+
return self._request("PUT", endpoint_name, request_arguments)
412+
413+
def add_tags(self, document_id, tags):
414+
"""
415+
Add multiple tags on an existing document.
416+
:param document_id: ID of the document you'd like to update
417+
:param tags: array of strings
418+
:return: Added tags data
419+
"""
420+
endpoint_name = f"/documents/{document_id}/tags/"
421+
request_arguments = {"tags": tags}
422+
return self._request("POST", endpoint_name, request_arguments)

0 commit comments

Comments
 (0)