Skip to content

Commit

Permalink
Merge pull request #41 from veryfi/feature/add-tag-function
Browse files Browse the repository at this point in the history
Add tag function
  • Loading branch information
manycoding authored Nov 29, 2023
2 parents 4fbf71c + 8dda212 commit f76bba0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.coverage
tests/__pycache__/
veryfi/__pycache__/
.idea/*
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CHANGES
=======
3.2.0
-----
* Add support to add tags on existing documents

3.1.1
-----
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ veryfi_client.update_document(id=12345, vendor=new_vendor, category=new_category


## Need help?
Visit https://docs.veryfi.com/ to access integration guides and usage notes in the Veryfi API Documentation Portal

If you run into any issue or need help installing or using the library, please contact [email protected].

If you found a bug in this library or would like new features added, then open an issue or pull requests against this repo!
Expand Down
14 changes: 14 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,17 @@ def test_get_documents():
**{"created_lt": "2021-07-22+00:00:00"},
)
assert d == mock


@responses.activate
def test_tags():
mock_doc_id = 169985445
mock_resp = {"id": 6673474, "name": "tag_123"}
client = Client(client_id="v", client_secret="w", username="o", api_key="c")
responses.put(
f"{client.versioned_url}/partner/documents/{mock_doc_id}/tags/",
json=mock_resp,
status=200,
)
d = client.add_tag(mock_doc_id, "tag_123")
assert d == mock_resp
13 changes: 12 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.0.0",
"User-Agent": "Python Veryfi-Python/3.2.0",
"Accept": "application/json",
"Content-Type": "application/json",
"Client-Id": self.client_id,
Expand Down Expand Up @@ -387,3 +387,14 @@ def delete_line_item(self, document_id, line_item_id):
endpoint_name = f"/documents/{document_id}/line-items/{line_item_id}"
request_arguments = {}
self._request("DELETE", endpoint_name, request_arguments)

def add_tag(self, document_id, tag_name):
"""
Add a new tag on an existing document.
:param document_id: ID of the document you'd like to update
:param tag_name: name of the new tag
:return: Added tag data
"""
endpoint_name = f"/documents/{document_id}/tags/"
request_arguments = {"name": tag_name}
return self._request("PUT", endpoint_name, request_arguments)

0 comments on commit f76bba0

Please sign in to comment.