Skip to main content

uptrakit_openapi_client/
surfaces.rs

1use crate::Result;
2use crate::UptrakitClient;
3use crate::types_impl::surfaces::{
4    InvokeSurfaceInteractionRequest, SurfaceProviderInfo, SurfaceReadResponse, SurfaceResponse,
5};
6
7impl UptrakitClient {
8    /// List registered surfaces. Optional `slot` and `page` filters map to query params.
9    pub async fn list_surfaces(
10        &self,
11        slot: Option<&str>,
12        page: Option<&str>,
13    ) -> Result<Vec<SurfaceResponse>> {
14        let url = format!("{}{}", self.base_url, crate::paths::surfaces::BASE);
15        let mut req = self.http.get(&url).bearer_auth(self.token_or_err()?);
16        let mut query_params: Vec<(&str, &str)> = Vec::new();
17        if let Some(slot) = slot {
18            query_params.push(("slot", slot));
19        }
20        if let Some(page) = page {
21            query_params.push(("page", page));
22        }
23        if !query_params.is_empty() {
24            req = req.query(&query_params);
25        }
26        let resp = self.send_with_retry(req).await?;
27        self.handle_response(resp).await
28    }
29
30    /// List targeted providers for a surface.
31    pub async fn list_surface_providers(
32        &self,
33        surface_id: &str,
34    ) -> Result<Vec<SurfaceProviderInfo>> {
35        self.get(&crate::paths::surfaces::providers(surface_id))
36            .await
37    }
38
39    /// Read a single surface with its interactions and data sources.
40    pub async fn read_surface(&self, surface_id: &str) -> Result<SurfaceReadResponse> {
41        self.get(&crate::paths::surfaces::read(surface_id)).await
42    }
43
44    /// Read a surface interaction via `GET`. `query` pairs are forwarded verbatim
45    /// as query-string parameters (reserved keys included).
46    pub async fn read_surface_interaction(
47        &self,
48        surface_id: &str,
49        interaction_id: &str,
50        query: &[(&str, String)],
51    ) -> Result<serde_json::Value> {
52        self.get_with_query(
53            &crate::paths::surfaces::interaction(surface_id, interaction_id),
54            &query,
55        )
56        .await
57    }
58
59    /// Invoke a surface interaction.
60    pub async fn invoke_surface_interaction(
61        &self,
62        surface_id: &str,
63        interaction_id: &str,
64        request: &InvokeSurfaceInteractionRequest,
65    ) -> Result<serde_json::Value> {
66        self.post_json(
67            &crate::paths::surfaces::interaction(surface_id, interaction_id),
68            request,
69        )
70        .await
71    }
72
73    /// Update a surface interaction via `PUT`.
74    pub async fn update_surface_interaction(
75        &self,
76        surface_id: &str,
77        interaction_id: &str,
78        request: &InvokeSurfaceInteractionRequest,
79    ) -> Result<serde_json::Value> {
80        self.put_json(
81            &crate::paths::surfaces::interaction(surface_id, interaction_id),
82            request,
83        )
84        .await
85    }
86
87    /// Delete a surface interaction via `DELETE`.
88    pub async fn delete_surface_interaction(
89        &self,
90        surface_id: &str,
91        interaction_id: &str,
92        request: &InvokeSurfaceInteractionRequest,
93    ) -> Result<serde_json::Value> {
94        self.delete_json_body(
95            &crate::paths::surfaces::interaction(surface_id, interaction_id),
96            request,
97        )
98        .await
99    }
100
101    /// Read a surface interaction targeting a specific item via `GET .../{item_id}`.
102    pub async fn read_surface_interaction_item(
103        &self,
104        surface_id: &str,
105        interaction_id: &str,
106        item_id: &str,
107        query: &[(&str, String)],
108    ) -> Result<serde_json::Value> {
109        self.get_with_query(
110            &crate::paths::surfaces::interaction_item(surface_id, interaction_id, item_id),
111            &query,
112        )
113        .await
114    }
115
116    /// Update a surface interaction targeting a specific item via `PUT .../{item_id}`.
117    pub async fn update_surface_interaction_item(
118        &self,
119        surface_id: &str,
120        interaction_id: &str,
121        item_id: &str,
122        request: &InvokeSurfaceInteractionRequest,
123    ) -> Result<serde_json::Value> {
124        self.put_json(
125            &crate::paths::surfaces::interaction_item(surface_id, interaction_id, item_id),
126            request,
127        )
128        .await
129    }
130
131    /// Delete a surface interaction targeting a specific item via `DELETE .../{item_id}`.
132    pub async fn delete_surface_interaction_item(
133        &self,
134        surface_id: &str,
135        interaction_id: &str,
136        item_id: &str,
137        request: &InvokeSurfaceInteractionRequest,
138    ) -> Result<serde_json::Value> {
139        self.delete_json_body(
140            &crate::paths::surfaces::interaction_item(surface_id, interaction_id, item_id),
141            request,
142        )
143        .await
144    }
145}