use crate::error::MisarDevError;
use crate::transport::Transport;
use crate::transport::body_or_empty;
use crate::transport::build_query;
use crate::transport::encode_path;
use reqwest::Method;
use serde_json::Value;
#[derive(Debug, Clone, Copy)]
pub struct ConnectorsResource<'a> {
pub(crate) t: &'a Transport,
}
impl ConnectorsResource<'_> {
pub async fn available(self) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, "/connectors/available", "", None).await
}
pub async fn create_connection(self, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, "/connectors/connections", "", Some(body_or_empty(body))).await
}
pub async fn delete_connection(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::DELETE, &format!("/connectors/connections/{}", encode_path(id)), "", None).await
}
pub async fn list(self) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, "/connectors", "", None).await
}
pub async fn list_connections(self, query: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, "/connectors/connections", &build_query(query.as_ref(), &[]), None).await
}
pub async fn test_connection(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/connectors/connections/{}/test", encode_path(id)), "", None).await
}
pub async fn toggle(self, slug: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/connectors/{}/toggle", encode_path(slug)), "", Some(body_or_empty(body))).await
}
pub async fn update_connection(self, id: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::PATCH, &format!("/connectors/connections/{}", encode_path(id)), "", Some(body_or_empty(body))).await
}
}