diff --git a/pyproject.toml b/pyproject.toml index 8f27839..dc7ff94 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "superagent-py" -version = "v0.0.42" +version = "v0.0.43" description = "" readme = "README.md" authors = [] diff --git a/src/superagent/resources/auth/client.py b/src/superagent/resources/auth/client.py index 0ea7040..dc9d0e6 100644 --- a/src/superagent/resources/auth/client.py +++ b/src/superagent/resources/auth/client.py @@ -74,6 +74,33 @@ def sign_up( raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + def oauth_handler( + self, *, email: str, name: str, access_token: typing.Optional[str] = OMIT, provider: typing.Optional[str] = OMIT + ) -> typing.Any: + _request: typing.Dict[str, typing.Any] = {"email": email, "name": name} + if access_token is not OMIT: + _request["access_token"] = access_token + if provider is not OMIT: + _request["provider"] = provider + _response = httpx.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/auth/oauth/callback"), + 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) + class AsyncAuthClient: def __init__(self, *, environment: str, token: typing.Optional[str] = None): @@ -133,3 +160,31 @@ async def sign_up( except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + + async def oauth_handler( + self, *, email: str, name: str, access_token: typing.Optional[str] = OMIT, provider: typing.Optional[str] = OMIT + ) -> typing.Any: + _request: typing.Dict[str, typing.Any] = {"email": email, "name": name} + if access_token is not OMIT: + _request["access_token"] = access_token + if provider is not OMIT: + _request["provider"] = provider + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/auth/oauth/callback"), + 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) diff --git a/src/superagent/resources/documents/client.py b/src/superagent/resources/documents/client.py index 0b748fc..5832f6f 100644 --- a/src/superagent/resources/documents/client.py +++ b/src/superagent/resources/documents/client.py @@ -44,6 +44,7 @@ def create_document( *, type: str, url: typing.Optional[str] = OMIT, + content: typing.Optional[str] = OMIT, name: str, authorization: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, @@ -54,6 +55,8 @@ def create_document( _request: typing.Dict[str, typing.Any] = {"type": type, "name": name} if url is not OMIT: _request["url"] = url + if content is not OMIT: + _request["content"] = content if authorization is not OMIT: _request["authorization"] = authorization if metadata is not OMIT: @@ -170,6 +173,7 @@ async def create_document( *, type: str, url: typing.Optional[str] = OMIT, + content: typing.Optional[str] = OMIT, name: str, authorization: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, @@ -180,6 +184,8 @@ async def create_document( _request: typing.Dict[str, typing.Any] = {"type": type, "name": name} if url is not OMIT: _request["url"] = url + if content is not OMIT: + _request["content"] = content if authorization is not OMIT: _request["authorization"] = authorization if metadata is not OMIT: