use crate::Result;
use crate::UptrakitClient;
use crate::types_impl::surfaces::{
InvokeSurfaceInteractionRequest, SurfaceProviderInfo, SurfaceReadResponse, SurfaceResponse,
};
impl UptrakitClient {
pub async fn list_surfaces(
&self,
slot: Option<&str>,
page: Option<&str>,
) -> Result<Vec<SurfaceResponse>> {
let url = format!("{}{}", self.base_url, crate::paths::surfaces::BASE);
let mut req = self.http.get(&url).bearer_auth(self.token_or_err()?);
let mut query_params: Vec<(&str, &str)> = Vec::new();
if let Some(slot) = slot {
query_params.push(("slot", slot));
}
if let Some(page) = page {
query_params.push(("page", page));
}
if !query_params.is_empty() {
req = req.query(&query_params);
}
let resp = self.send_with_retry(req).await?;
self.handle_response(resp).await
}
pub async fn list_surface_providers(
&self,
surface_id: &str,
) -> Result<Vec<SurfaceProviderInfo>> {
self.get(&crate::paths::surfaces::providers(surface_id))
.await
}
pub async fn read_surface(&self, surface_id: &str) -> Result<SurfaceReadResponse> {
self.get(&crate::paths::surfaces::read(surface_id)).await
}
pub async fn read_surface_interaction(
&self,
surface_id: &str,
interaction_id: &str,
query: &[(&str, String)],
) -> Result<serde_json::Value> {
self.get_with_query(
&crate::paths::surfaces::interaction(surface_id, interaction_id),
&query,
)
.await
}
pub async fn invoke_surface_interaction(
&self,
surface_id: &str,
interaction_id: &str,
request: &InvokeSurfaceInteractionRequest,
) -> Result<serde_json::Value> {
self.post_json(
&crate::paths::surfaces::interaction(surface_id, interaction_id),
request,
)
.await
}
pub async fn update_surface_interaction(
&self,
surface_id: &str,
interaction_id: &str,
request: &InvokeSurfaceInteractionRequest,
) -> Result<serde_json::Value> {
self.put_json(
&crate::paths::surfaces::interaction(surface_id, interaction_id),
request,
)
.await
}
pub async fn delete_surface_interaction(
&self,
surface_id: &str,
interaction_id: &str,
request: &InvokeSurfaceInteractionRequest,
) -> Result<serde_json::Value> {
self.delete_json_body(
&crate::paths::surfaces::interaction(surface_id, interaction_id),
request,
)
.await
}
pub async fn read_surface_interaction_item(
&self,
surface_id: &str,
interaction_id: &str,
item_id: &str,
query: &[(&str, String)],
) -> Result<serde_json::Value> {
self.get_with_query(
&crate::paths::surfaces::interaction_item(surface_id, interaction_id, item_id),
&query,
)
.await
}
pub async fn update_surface_interaction_item(
&self,
surface_id: &str,
interaction_id: &str,
item_id: &str,
request: &InvokeSurfaceInteractionRequest,
) -> Result<serde_json::Value> {
self.put_json(
&crate::paths::surfaces::interaction_item(surface_id, interaction_id, item_id),
request,
)
.await
}
pub async fn delete_surface_interaction_item(
&self,
surface_id: &str,
interaction_id: &str,
item_id: &str,
request: &InvokeSurfaceInteractionRequest,
) -> Result<serde_json::Value> {
self.delete_json_body(
&crate::paths::surfaces::interaction_item(surface_id, interaction_id, item_id),
request,
)
.await
}
}