use super::types::*;
use crate::{error::Result, http::HttpClient};
use std::sync::Arc;
pub struct AssociationsApi {
http: Arc<HttpClient>,
}
impl AssociationsApi {
pub fn new(http: Arc<HttpClient>) -> Self {
Self { http }
}
pub async fn list(&self) -> Result<ListAssociationsResponse> {
self.http.get("/associations/").await
}
pub async fn get(&self, association_id: &str) -> Result<GetAssociationResponse> {
self.http
.get(&format!("/associations/{association_id}"))
.await
}
pub async fn create(&self, params: &CreateAssociationParams) -> Result<GetAssociationResponse> {
self.http.post("/associations/", params).await
}
pub async fn delete(&self, association_id: &str) -> Result<serde_json::Value> {
self.http
.delete(&format!("/associations/{association_id}"))
.await
}
pub async fn create_relation(
&self,
params: &CreateRelationParams,
) -> Result<GetRelationResponse> {
self.http.post("/associations/relations", params).await
}
pub async fn list_relations(&self, association_id: &str) -> Result<ListRelationsResponse> {
self.http
.get(&format!("/associations/{association_id}/relations"))
.await
}
pub async fn delete_relation(&self, relation_id: &str) -> Result<serde_json::Value> {
self.http
.delete(&format!("/associations/relations/{relation_id}"))
.await
}
}