use crate::client::{
MultipartRequestBuilder, PageRequestBuilder, RawRequestBuilder, RequestBuilder, Steel,
};
use crate::types::*;
pub struct Sessions<'a> {
client: &'a Steel,
}
impl<'a> Sessions<'a> {
pub fn new(client: &'a Steel) -> Self {
Self { client }
}
pub fn captchas(&self) -> SessionsCaptchas<'a> {
SessionsCaptchas::new(self.client)
}
pub fn files(&self) -> SessionsFiles<'a> {
SessionsFiles::new(self.client)
}
pub fn list(&self, query: SessionListParams) -> PageRequestBuilder<SessionListSession> {
let path = "/v1/sessions".to_string();
let mut __query: Vec<(String, String)> = Vec::new();
if let Some(__v) = &query.cursor_id {
__query.push(("cursorId".to_string(), __v.to_string()));
}
if let Some(__v) = &query.limit {
__query.push(("limit".to_string(), __v.to_string()));
}
if let Some(__v) = &query.status {
__query.push(("status".to_string(), __v.to_string()));
}
if let Some(__v) = &query.project_id {
__query.push(("projectId".to_string(), __v.to_string()));
}
self.client.page_call(
path,
__query,
|_items, cursor| cursor.map(str::to_string),
"sessions",
Some("nextCursor"),
None,
"cursorId",
)
}
pub fn create(
&self,
body: SessionCreateParams,
) -> RequestBuilder<'_, (), SessionCreateParams, Session> {
let path = "/v1/sessions".to_string();
self.client
.call(reqwest::Method::POST, path, None::<()>, Some(body))
}
pub fn release_all(
&self,
body: SessionReleaseAllParams,
query: SessionReleaseAllQueryParams,
) -> RequestBuilder<
'_,
SessionReleaseAllQueryParams,
SessionReleaseAllParams,
SessionReleaseAllResponse,
> {
let path = "/v1/sessions/release".to_string();
self.client
.call(reqwest::Method::POST, path, Some(query), Some(body))
}
pub fn retrieve(&self, id: &str) -> RequestBuilder<'_, (), (), Session> {
let path = format!("/v1/sessions/{}", crate::client::encode_path(id));
self.client
.call(reqwest::Method::GET, path, None::<()>, None::<()>)
}
pub fn agent_traces(
&self,
id: &str,
query: SessionAgentTracesParams,
) -> RequestBuilder<'_, Vec<(String, String)>, (), SessionAgentTracesResponse> {
let path = format!(
"/v1/sessions/{}/agent-traces",
crate::client::encode_path(id)
);
let mut __query: Vec<(String, String)> = Vec::new();
if let Some(__v) = &query.namespace {
__query.push(("namespace".to_string(), __v.to_string()));
}
if let Some(__v) = &query.start_time {
__query.push(("startTime".to_string(), __v.to_rfc3339()));
}
if let Some(__v) = &query.end_time {
__query.push(("endTime".to_string(), __v.to_rfc3339()));
}
if let Some(__v) = &query.event_types {
for __e in __v {
__query.push(("eventTypes".to_string(), __e.to_string()));
}
}
self.client
.call(reqwest::Method::GET, path, Some(__query), None::<()>)
}
pub fn context(&self, id: &str) -> RequestBuilder<'_, (), (), SessionContext> {
let path = format!("/v1/sessions/{}/context", crate::client::encode_path(id));
self.client
.call(reqwest::Method::GET, path, None::<()>, None::<()>)
}
pub fn cost(&self, id: &str) -> RequestBuilder<'_, (), (), SessionCostResponse> {
let path = format!("/v1/sessions/{}/cost", crate::client::encode_path(id));
self.client
.call(reqwest::Method::GET, path, None::<()>, None::<()>)
}
pub fn events(
&self,
id: &str,
query: SessionEventsParams,
) -> RequestBuilder<'_, SessionEventsParams, (), SessionEventsResponse> {
let path = format!("/v1/sessions/{}/events", crate::client::encode_path(id));
self.client
.call(reqwest::Method::GET, path, Some(query), None::<()>)
}
pub fn live_details(&self, id: &str) -> RequestBuilder<'_, (), (), SessionLiveDetailsResponse> {
let path = format!(
"/v1/sessions/{}/live-details",
crate::client::encode_path(id)
);
self.client
.call(reqwest::Method::GET, path, None::<()>, None::<()>)
}
pub fn release(
&self,
id: &str,
body: SessionReleaseParams,
) -> RequestBuilder<'_, (), SessionReleaseParams, SessionReleaseResponse> {
let path = format!("/v1/sessions/{}/release", crate::client::encode_path(id));
self.client
.call(reqwest::Method::POST, path, None::<()>, Some(body))
}
pub fn computer(
&self,
session_id: &str,
body: SessionComputerParams,
) -> RequestBuilder<'_, (), SessionComputerParams, SessionComputerResponse> {
let path = format!(
"/v1/sessions/{}/computer",
crate::client::encode_path(session_id)
);
self.client
.call(reqwest::Method::POST, path, None::<()>, Some(body))
}
}
pub struct SessionsCaptchas<'a> {
client: &'a Steel,
}
impl<'a> SessionsCaptchas<'a> {
pub fn new(client: &'a Steel) -> Self {
Self { client }
}
pub fn solve(
&self,
session_id: &str,
body: CaptchaSolveParams,
) -> RequestBuilder<'_, (), CaptchaSolveParams, CaptchaSolveResponse> {
let path = format!(
"/v1/sessions/{}/captchas/solve",
crate::client::encode_path(session_id)
);
self.client
.call(reqwest::Method::POST, path, None::<()>, Some(body))
}
pub fn solve_image(
&self,
session_id: &str,
body: CaptchaSolveImageParams,
) -> RequestBuilder<'_, (), CaptchaSolveImageParams, CaptchaSolveImageResponse> {
let path = format!(
"/v1/sessions/{}/captchas/solve-image",
crate::client::encode_path(session_id)
);
self.client
.call(reqwest::Method::POST, path, None::<()>, Some(body))
}
pub fn status(&self, session_id: &str) -> RequestBuilder<'_, (), (), CaptchaStatusResponse> {
let path = format!(
"/v1/sessions/{}/captchas/status",
crate::client::encode_path(session_id)
);
self.client
.call(reqwest::Method::GET, path, None::<()>, None::<()>)
}
}
pub struct SessionsFiles<'a> {
client: &'a Steel,
}
impl<'a> SessionsFiles<'a> {
pub fn new(client: &'a Steel) -> Self {
Self { client }
}
pub fn list(&self, session_id: &str) -> RequestBuilder<'_, (), (), FileList> {
let path = format!(
"/v1/sessions/{}/files",
crate::client::encode_path(session_id)
);
self.client
.call(reqwest::Method::GET, path, None::<()>, None::<()>)
}
pub fn upload(
&self,
session_id: &str,
body: SessionFileUploadParams,
) -> MultipartRequestBuilder<
'_,
impl Fn() -> Result<reqwest::multipart::Form, reqwest::Error>,
(),
File,
> {
let path = format!(
"/v1/sessions/{}/files",
crate::client::encode_path(session_id)
);
self.client
.multipart_call(reqwest::Method::POST, path, None::<()>, move || {
body.to_form()
})
}
pub fn delete_all(&self, session_id: &str) -> RequestBuilder<'_, (), (), serde_json::Value> {
let path = format!(
"/v1/sessions/{}/files",
crate::client::encode_path(session_id)
);
self.client
.call(reqwest::Method::DELETE, path, None::<()>, None::<()>)
}
pub fn download_archive(&self, session_id: &str) -> RawRequestBuilder<'_, (), ()> {
let path = format!(
"/v1/sessions/{}/files.zip",
crate::client::encode_path(session_id)
);
self.client
.raw_call(reqwest::Method::GET, path, None::<()>, None::<()>)
}
pub fn download(&self, session_id: &str, path: &str) -> RawRequestBuilder<'_, (), ()> {
let path = format!(
"/v1/sessions/{}/files/{}",
crate::client::encode_path(session_id),
crate::client::encode_path(path)
);
self.client
.raw_call(reqwest::Method::GET, path, None::<()>, None::<()>)
}
pub fn delete(
&self,
session_id: &str,
path: &str,
) -> RequestBuilder<'_, (), (), serde_json::Value> {
let path = format!(
"/v1/sessions/{}/files/{}",
crate::client::encode_path(session_id),
crate::client::encode_path(path)
);
self.client
.call(reqwest::Method::DELETE, path, None::<()>, None::<()>)
}
}