|
8 | 8 |
|
9 | 9 | import requests |
10 | 10 |
|
| 11 | +from veryfi.model import AddLineItem, UpdateLineItem |
11 | 12 | from veryfi.errors import VeryfiClientError |
12 | 13 |
|
13 | 14 |
|
@@ -237,3 +238,69 @@ def update_document(self, document_id: int, **kwargs) -> Dict: |
237 | 238 | endpoint_name = f"/documents/{document_id}/" |
238 | 239 |
|
239 | 240 | return self._request("PUT", endpoint_name, kwargs) |
| 241 | + |
| 242 | + def get_line_items(self, document_id): |
| 243 | + """ |
| 244 | + Retrieve all line items for a document. |
| 245 | + :param document_id: ID of the document you'd like to retrieve |
| 246 | + :return: List of line items extracted from the document |
| 247 | + """ |
| 248 | + endpoint_name = f"/documents/{document_id}/line-items/" |
| 249 | + request_arguments = {} |
| 250 | + line_items = self._request("GET", endpoint_name, request_arguments) |
| 251 | + return line_items |
| 252 | + |
| 253 | + def get_line_item(self, document_id, line_item_id): |
| 254 | + """ |
| 255 | + Retrieve a line item for existing document by ID. |
| 256 | + :param document_id: ID of the document you'd like to retrieve |
| 257 | + :param line_item_id: ID of the line item you'd like to retrieve |
| 258 | + :return: Line item extracted from the document |
| 259 | + """ |
| 260 | + endpoint_name = f"/documents/{document_id}/line-items/{line_item_id}" |
| 261 | + request_arguments = {} |
| 262 | + line_items = self._request("GET", endpoint_name, request_arguments) |
| 263 | + return line_items |
| 264 | + |
| 265 | + def add_line_item(self, document_id: int, payload: Dict) -> Dict: |
| 266 | + """ |
| 267 | + Add a new line item on an existing document. |
| 268 | + :param document_id: ID of the document you'd like to update |
| 269 | + :param payload: line item object to add |
| 270 | + :return: Added line item data |
| 271 | + """ |
| 272 | + endpoint_name = f"/documents/{document_id}/line-items/" |
| 273 | + request_arguments = AddLineItem(**payload).dict(exclude_none=True) |
| 274 | + return self._request("POST", endpoint_name, request_arguments) |
| 275 | + |
| 276 | + def update_line_item(self, document_id: int, line_item_id: int, payload: Dict) -> Dict: |
| 277 | + """ |
| 278 | + Update an existing line item on an existing document. |
| 279 | + :param document_id: ID of the document you'd like to update |
| 280 | + :param line_item_id: ID of the line item you'd like to update |
| 281 | + :param payload: line item object to update |
| 282 | +
|
| 283 | + :return: Line item data with updated fields, if fields are writable. Otherwise line item data with unchanged fields. |
| 284 | + """ |
| 285 | + endpoint_name = f"/documents/{document_id}/line-items/{line_item_id}" |
| 286 | + request_arguments = UpdateLineItem(**payload).dict(exclude_none=True) |
| 287 | + return self._request("PUT", endpoint_name, request_arguments) |
| 288 | + |
| 289 | + def delete_line_items(self, document_id): |
| 290 | + """ |
| 291 | + Delete all line items on an existing document. |
| 292 | + :param document_id: ID of the document you'd like to delete |
| 293 | + """ |
| 294 | + endpoint_name = f"/documents/{document_id}/line-items/" |
| 295 | + request_arguments = {} |
| 296 | + self._request("DELETE", endpoint_name, request_arguments) |
| 297 | + |
| 298 | + def delete_line_item(self, document_id, line_item_id): |
| 299 | + """ |
| 300 | + Delete an existing line item on an existing document. |
| 301 | + :param document_id: ID of the document you'd like to delete |
| 302 | + :param line_item_id: ID of the line item you'd like to delete |
| 303 | + """ |
| 304 | + endpoint_name = f"/documents/{document_id}/line-items/{line_item_id}" |
| 305 | + request_arguments = {} |
| 306 | + self._request("DELETE", endpoint_name, request_arguments) |
0 commit comments