forked from slackapi/python-slack-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse.py
More file actions
34 lines (29 loc) · 952 Bytes
/
response.py
File metadata and controls
34 lines (29 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import json
from typing import Dict, Any, Optional
from slack_sdk.audit_logs.v1.logs import LogsResponse
# TODO: Unlike WebClient's responses, this class has not yet provided __iter__ method
class AuditLogsResponse:
url: str
status_code: int
headers: Dict[str, Any]
raw_body: Optional[str]
body: Optional[Dict[str, Any]]
typed_body: Optional[LogsResponse]
@property # type: ignore[no-redef]
def typed_body(self) -> Optional[LogsResponse]:
if self.body is None:
return None
return LogsResponse(**self.body)
def __init__(
self,
*,
url: str,
status_code: int,
raw_body: Optional[str],
headers: dict,
):
self.url = url
self.status_code = status_code
self.headers = headers
self.raw_body = raw_body
self.body = json.loads(raw_body) if raw_body is not None and raw_body.startswith("{") else None