-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsession.py
More file actions
136 lines (117 loc) · 4.85 KB
/
session.py
File metadata and controls
136 lines (117 loc) · 4.85 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from typing import List, Union, IO
from ....models.session import (
BasicResponse,
CreateSessionParams,
GetSessionDownloadsUrlResponse,
GetSessionRecordingUrlResponse,
GetSessionVideoRecordingUrlResponse,
SessionDetail,
SessionListParams,
SessionListResponse,
SessionRecording,
UploadFileResponse,
SessionEventLogListParams,
SessionEventLogListResponse,
SessionEventLog,
SessionConsoleLogListParams,
SessionConsoleLogListResponse,
)
class SessionEventLogsManager:
def __init__(self, client):
self._client = client
def list(
self,
session_id: str,
params: SessionEventLogListParams = SessionEventLogListParams(),
) -> SessionEventLogListResponse:
response = self._client.transport.get(
self._client._build_url(f"/session/{session_id}/event-logs"),
params=params.model_dump(exclude_none=True, by_alias=True),
)
return SessionEventLogListResponse(**response.data)
class SessionConsoleLogsManager:
def __init__(self, client):
self._client = client
def list(
self,
session_id: str,
params: SessionConsoleLogListParams = SessionConsoleLogListParams(),
) -> SessionConsoleLogListResponse:
response = self._client.transport.get(
self._client._build_url(f"/session/{session_id}/console"),
params=params.model_dump(exclude_none=True, by_alias=True),
)
return SessionConsoleLogListResponse(**response.data)
class SessionManager:
def __init__(self, client):
self._client = client
self.event_logs = SessionEventLogsManager(client)
self.console_logs = SessionConsoleLogsManager(client)
def create(self, params: CreateSessionParams = None) -> SessionDetail:
response = self._client.transport.post(
self._client._build_url("/session"),
data=(
{}
if params is None
else params.model_dump(exclude_none=True, by_alias=True)
),
)
return SessionDetail(**response.data)
def get(self, id: str) -> SessionDetail:
response = self._client.transport.get(self._client._build_url(f"/session/{id}"))
return SessionDetail(**response.data)
def stop(self, id: str) -> BasicResponse:
response = self._client.transport.put(
self._client._build_url(f"/session/{id}/stop")
)
return BasicResponse(**response.data)
def list(
self, params: SessionListParams = SessionListParams()
) -> SessionListResponse:
response = self._client.transport.get(
self._client._build_url("/sessions"),
params=params.model_dump(exclude_none=True, by_alias=True),
)
return SessionListResponse(**response.data)
def get_recording(self, id: str) -> List[SessionRecording]:
response = self._client.transport.get(
self._client._build_url(f"/session/{id}/recording"), None, True
)
return [SessionRecording(**recording) for recording in response.data]
def get_recording_url(self, id: str) -> GetSessionRecordingUrlResponse:
response = self._client.transport.get(
self._client._build_url(f"/session/{id}/recording-url")
)
return GetSessionRecordingUrlResponse(**response.data)
def get_video_recording_url(self, id: str) -> GetSessionVideoRecordingUrlResponse:
response = self._client.transport.get(
self._client._build_url(f"/session/{id}/video-recording-url")
)
return GetSessionVideoRecordingUrlResponse(**response.data)
def get_downloads_url(self, id: str) -> GetSessionDownloadsUrlResponse:
response = self._client.transport.get(
self._client._build_url(f"/session/{id}/downloads-url")
)
return GetSessionDownloadsUrlResponse(**response.data)
def upload_file(self, id: str, file_input: Union[str, IO]) -> UploadFileResponse:
response = None
if isinstance(file_input, str):
with open(file_input, "rb") as file_obj:
files = {"file": file_obj}
response = self._client.transport.post(
self._client._build_url(f"/session/{id}/uploads"),
files=files,
)
else:
files = {"file": file_input}
response = self._client.transport.post(
self._client._build_url(f"/session/{id}/uploads"),
files=files,
)
return UploadFileResponse(**response.data)
def extend_session(self, id: str, duration_minutes: int) -> BasicResponse:
response = self._client.transport.put(
self._client._build_url(f"/session/{id}/extend-session"),
data={"durationMinutes": duration_minutes},
)
return BasicResponse(**response.data)