kontext_dev_sdk/management/
integrations.rs1use std::sync::Arc;
4
5use kontext_dev_sdk_core::types::{
6 CreateIntegrationRequest, IntegrationResponse, ListIntegrationsResponse, PaginationParams,
7 UpdateIntegrationRequest,
8};
9
10use crate::http_client::{HttpClient, HttpError, RequestOptions, RequestParams};
11
12pub type IntegrationsResource = IntegrationsApi;
14
15#[derive(Clone)]
16pub struct IntegrationsApi {
17 http: Arc<HttpClient>,
18}
19
20impl IntegrationsApi {
21 pub fn new(http: Arc<HttpClient>) -> Self {
22 Self { http }
23 }
24
25 pub async fn create(
26 &self,
27 data: CreateIntegrationRequest,
28 ) -> Result<IntegrationResponse, HttpError> {
29 self.http.post("/integrations", Some(data), None).await
30 }
31
32 pub async fn list(
33 &self,
34 params: Option<PaginationParams>,
35 ) -> Result<ListIntegrationsResponse, HttpError> {
36 let options = params.map(|p| {
37 let mut request_params = RequestParams::new();
38 if let Some(limit) = p.limit {
39 request_params.insert("limit".to_string(), limit.to_string());
40 }
41 if let Some(cursor) = p.cursor {
42 request_params.insert("cursor".to_string(), cursor);
43 }
44 RequestOptions {
45 params: Some(request_params),
46 headers: None,
47 }
48 });
49 self.http.get("/integrations", options).await
50 }
51
52 pub async fn get(&self, id: &str) -> Result<IntegrationResponse, HttpError> {
53 self.http.get(&format!("/integrations/{id}"), None).await
54 }
55
56 pub async fn update(
57 &self,
58 id: &str,
59 data: UpdateIntegrationRequest,
60 ) -> Result<IntegrationResponse, HttpError> {
61 self.http
62 .patch(&format!("/integrations/{id}"), Some(data), None)
63 .await
64 }
65
66 pub async fn archive(&self, id: &str) -> Result<(), HttpError> {
67 self.http
68 .delete_no_content(&format!("/integrations/{id}"), None)
69 .await
70 }
71
72 pub async fn validate(&self, id: &str) -> Result<IntegrationResponse, HttpError> {
73 self.http
74 .post::<IntegrationResponse, ()>(&format!("/integrations/{id}/validate"), None, None)
75 .await
76 }
77}