Skip to content

Commit

Permalink
Release v0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Jul 17, 2023
1 parent 2c77039 commit dfa9a09
Show file tree
Hide file tree
Showing 2 changed files with 50 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 = "mercoa"
version = "v0.2.2"
version = "v0.2.3"
description = ""
readme = "README.md"
authors = []
Expand Down
49 changes: 49 additions & 0 deletions src/mercoa/resources/entity/resources/user/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ def delete(self, entity_id: EntityId, user_id: EntityUserId) -> None:
raise Unauthorized(pydantic.parse_obj_as(str, _response_json["content"])) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)

def get_token(self, entity_id: EntityId, user_id: EntityUserId) -> str:
_response = httpx.request(
"GET",
urllib.parse.urljoin(f"{self._environment.value}/", f"entity/{entity_id}/user/{user_id}/token"),
headers=remove_none_from_headers(
{"Authorization": f"Bearer {self._token}" if self._token is not None else None}
),
timeout=60,
)
try:
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(str, _response_json) # type: ignore
if "errorName" in _response_json:
if _response_json["errorName"] == "AuthHeaderMissingError":
raise AuthHeaderMissingError()
if _response_json["errorName"] == "AuthHeaderMalformedError":
raise AuthHeaderMalformedError(pydantic.parse_obj_as(str, _response_json["content"])) # type: ignore
if _response_json["errorName"] == "Unauthorized":
raise Unauthorized(pydantic.parse_obj_as(str, _response_json["content"])) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)


class AsyncUserClient:
def __init__(self, *, environment: MercoaEnvironment = MercoaEnvironment.PRODUCTION, token: str):
Expand Down Expand Up @@ -284,3 +308,28 @@ async def delete(self, entity_id: EntityId, user_id: EntityUserId) -> None:
if _response_json["errorName"] == "Unauthorized":
raise Unauthorized(pydantic.parse_obj_as(str, _response_json["content"])) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)

async def get_token(self, entity_id: EntityId, user_id: EntityUserId) -> str:
async with httpx.AsyncClient() as _client:
_response = await _client.request(
"GET",
urllib.parse.urljoin(f"{self._environment.value}/", f"entity/{entity_id}/user/{user_id}/token"),
headers=remove_none_from_headers(
{"Authorization": f"Bearer {self._token}" if self._token is not None else None}
),
timeout=60,
)
try:
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(str, _response_json) # type: ignore
if "errorName" in _response_json:
if _response_json["errorName"] == "AuthHeaderMissingError":
raise AuthHeaderMissingError()
if _response_json["errorName"] == "AuthHeaderMalformedError":
raise AuthHeaderMalformedError(pydantic.parse_obj_as(str, _response_json["content"])) # type: ignore
if _response_json["errorName"] == "Unauthorized":
raise Unauthorized(pydantic.parse_obj_as(str, _response_json["content"])) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)

0 comments on commit dfa9a09

Please sign in to comment.