use std::sync::Arc;
use crate::{error::Result, http::HttpClient};
use super::types::*;
pub struct LinksApi {
http: Arc<HttpClient>,
}
impl LinksApi {
pub fn new(http: Arc<HttpClient>) -> Self {
Self { http }
}
pub async fn list(&self, location_id: &str) -> Result<GetLinksResponse> {
#[derive(serde::Serialize)]
struct Q<'a> {
#[serde(rename = "locationId")]
location_id: &'a str,
}
self.http.get_with_query("/links", &Q { location_id }).await
}
pub async fn create(&self, params: &CreateLinkParams) -> Result<GetLinkResponse> {
self.http.post("/links", params).await
}
pub async fn update(
&self,
link_id: &str,
params: &UpdateLinkParams,
) -> Result<GetLinkResponse> {
self.http.put(&format!("/links/{link_id}"), params).await
}
pub async fn delete(&self, link_id: &str) -> Result<DeleteLinkResponse> {
self.http.delete(&format!("/links/{link_id}")).await
}
}