Skip to content

Commit

Permalink
Release 0.0.43
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Aug 6, 2023
1 parent a0272ed commit c6de582
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "superagent-py"
version = "v0.0.42"
version = "v0.0.43"
description = ""
readme = "README.md"
authors = []
Expand Down
55 changes: 55 additions & 0 deletions src/superagent/resources/auth/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
6 changes: 6 additions & 0 deletions src/superagent/resources/documents/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit c6de582

Please sign in to comment.