diff --git a/pyproject.toml b/pyproject.toml index f7f5463..bcaf56e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "superagent-py" -version = "v0.0.35" +version = "v0.0.36" description = "" readme = "README.md" authors = [] @@ -10,8 +10,8 @@ packages = [ [tool.poetry.dependencies] python = "^3.7" -pydantic = "^1.9.2" httpx = "0.23.3" +pydantic = "^1.9.2" [tool.poetry.dev-dependencies] mypy = "0.971" diff --git a/src/superagent/resources/documents/client.py b/src/superagent/resources/documents/client.py index 8fb38eb..0b748fc 100644 --- a/src/superagent/resources/documents/client.py +++ b/src/superagent/resources/documents/client.py @@ -102,6 +102,26 @@ def get_document(self, document_id: str) -> typing.Any: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + def patch_document(self, document_id: str, *, request: typing.Dict[str, typing.Any]) -> typing.Any: + _response = httpx.request( + "PATCH", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/documents/{document_id}"), + json=jsonable_encoder(request), + headers=remove_none_from_headers( + {"Authorization": f"Bearer {self._token}" if self._token is not None else None} + ), + timeout=60, + ) + if 200 <= _response.status_code < 300: + return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore + try: + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + def delete_document(self, document_id: str) -> typing.Any: _response = httpx.request( "DELETE", @@ -210,6 +230,27 @@ async def get_document(self, document_id: str) -> typing.Any: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + async def patch_document(self, document_id: str, *, request: typing.Dict[str, typing.Any]) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "PATCH", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/documents/{document_id}"), + json=jsonable_encoder(request), + headers=remove_none_from_headers( + {"Authorization": f"Bearer {self._token}" if self._token is not None else None} + ), + timeout=60, + ) + if 200 <= _response.status_code < 300: + return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore + try: + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + async def delete_document(self, document_id: str) -> typing.Any: async with httpx.AsyncClient() as _client: _response = await _client.request(