Skip to content

Commit 6bc6352

Browse files
authored
Merge pull request #36 from sypht-team/chore/housekeeping
Chore/housekeeping
2 parents 9daf308 + f12d7c6 commit 6bc6352

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

sypht/client.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import json
22
import os
3+
from typing import List, Optional
34
from base64 import b64encode
45
from datetime import datetime, timedelta
5-
from urllib.parse import quote_plus, urljoin
6+
from urllib.parse import quote_plus, urlencode, urljoin
67

78
import requests
89

@@ -378,10 +379,19 @@ def get_file_data(self, file_id, endpoint=None, headers=None):
378379

379380
return response.content
380381

381-
def fetch_results(self, file_id, endpoint=None, verbose=False, headers=None):
382+
def fetch_results(self, file_id, timeout=None, endpoint=None, verbose=False, headers=None):
383+
"""
384+
:param file_id: the id of the document that was uploaded and extracted
385+
:param timeout: a timeout in milliseconds to wait for the results
386+
"""
382387
endpoint = urljoin(endpoint or self.base_endpoint, "result/final/" + file_id)
388+
qsdict = {}
383389
if verbose:
384-
endpoint += "?verbose=true"
390+
qsdict["verbose"] = "true"
391+
if timeout:
392+
qsdict["timeout"] = timeout
393+
qs = urlencode(qsdict)
394+
endpoint += f"?{qs}" if qs else ""
385395
headers = headers or {}
386396
headers = self._get_headers(**headers)
387397
result = self._parse_response(self.requests.get(endpoint, headers=headers))
@@ -803,3 +813,30 @@ def submit_task(
803813
return self._parse_response(
804814
self.requests.post(endpoint, data=json.dumps(task), headers=headers)
805815
)
816+
817+
def add_tags_to_tasks(self, task_ids: List[str], tags: List[str], company_id: Optional[str]=None, endpoint: Optional[str]=None):
818+
company_id = company_id or self.company_id
819+
endpoint = urljoin(
820+
endpoint or self.base_endpoint,
821+
f"app/company/{company_id}/tasks/tags/batch",
822+
)
823+
headers = self._get_headers()
824+
headers["Accept"] = "application/json"
825+
headers["Content-Type"] = "application/json"
826+
data = {"taskIds": task_ids, "add": tags, "remove": []}
827+
return self._parse_response(
828+
self.requests.post(
829+
endpoint, data=json.dumps(data), headers=headers
830+
)
831+
)
832+
833+
def get_tags_for_task(self, task_id: str, company_id: Optional[str]=None, endpoint: Optional[str]=None):
834+
company_id = company_id or self.company_id
835+
endpoint = urljoin(
836+
endpoint or self.base_endpoint,
837+
f"app/company/{company_id}/tasks/{task_id}/tags",
838+
)
839+
headers = self._get_headers()
840+
headers["Accept"] = "application/json"
841+
headers["Content-Type"] = "application/json"
842+
return self._parse_response(self.requests.get(endpoint, headers=headers))

0 commit comments

Comments
 (0)