Skip to content

Commit

Permalink
Merge pull request #43 from veryfi/feature/PLAT-5449-add-multiple-tag…
Browse files Browse the repository at this point in the history
…s-function

Add multiple tags function
  • Loading branch information
manycoding authored Jan 2, 2024
2 parents f7040b0 + da8a7c3 commit 87053d8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
CHANGES
=======
3.4.1
-----
* Add support to add multiple tags on existing documents

3.4.0
-----
* Add support to add tags on existing documents
Expand Down
28 changes: 28 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,31 @@ def test_tags():
)
d = client.add_tag(mock_doc_id, "tag_123")
assert d == mock_resp


@responses.activate
def test_replace_multiple_tags():
mock_doc_id = 169985445
mock_resp = {"id": 6673474, "tags": ["tag_1", "tag_2", "tag_3"]}
client = Client(client_id="v", client_secret="w", username="o", api_key="c")
responses.put(
f"{client.versioned_url}/partner/documents/{mock_doc_id}/",
json=mock_resp,
status=200,
)
d = client.replace_tags(mock_doc_id, ["tag_1", "tag_2", "tag_3"])
assert d == mock_resp


@responses.activate
def test_add_multiple_tags():
mock_doc_id = 169985445
mock_resp = {"id": 6673474, "tags": ["tag_1", "tag_2", "tag_3"]}
client = Client(client_id="v", client_secret="w", username="o", api_key="c")
responses.post(
f"{client.versioned_url}/partner/documents/{mock_doc_id}/tags/",
json=mock_resp,
status=200,
)
d = client.add_tags(mock_doc_id, ["tag_1", "tag_2", "tag_3"])
assert d == mock_resp
24 changes: 23 additions & 1 deletion veryfi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _get_headers(self) -> Dict:
:return: Dictionary with headers
"""
final_headers = {
"User-Agent": "Python Veryfi-Python/3.4.0",
"User-Agent": "Python Veryfi-Python/3.4.1",
"Accept": "application/json",
"Content-Type": "application/json",
"Client-Id": self.client_id,
Expand Down Expand Up @@ -398,3 +398,25 @@ def add_tag(self, document_id, tag_name):
endpoint_name = f"/documents/{document_id}/tags/"
request_arguments = {"name": tag_name}
return self._request("PUT", endpoint_name, request_arguments)

def replace_tags(self, document_id, tags):
"""
Replace multiple tags on an existing document.
:param document_id: ID of the document you'd like to update
:param tags: array of strings
:return: Added tags data
"""
endpoint_name = f"/documents/{document_id}/"
request_arguments = {"tags": tags}
return self._request("PUT", endpoint_name, request_arguments)

def add_tags(self, document_id, tags):
"""
Add multiple tags on an existing document.
:param document_id: ID of the document you'd like to update
:param tags: array of strings
:return: Added tags data
"""
endpoint_name = f"/documents/{document_id}/tags/"
request_arguments = {"tags": tags}
return self._request("POST", endpoint_name, request_arguments)

0 comments on commit 87053d8

Please sign in to comment.