Skip to main content

highlevel_api/apis/objects/
client.rs

1use super::types::*;
2use crate::{error::Result, http::HttpClient};
3use std::sync::Arc;
4
5pub struct ObjectsApi {
6    http: Arc<HttpClient>,
7}
8
9impl ObjectsApi {
10    pub fn new(http: Arc<HttpClient>) -> Self {
11        Self { http }
12    }
13
14    // ── Schemas ──────────────────────────────────────────────────────────────
15
16    pub async fn list_schemas(&self, params: &ListSchemasParams) -> Result<ListSchemasResponse> {
17        self.http.get_with_query("/objects/", params).await
18    }
19
20    pub async fn get_schema(&self, schema_key: &str) -> Result<GetSchemaResponse> {
21        self.http.get(&format!("/objects/{schema_key}")).await
22    }
23
24    pub async fn create_schema(&self, params: &CreateSchemaParams) -> Result<GetSchemaResponse> {
25        self.http.post("/objects/", params).await
26    }
27
28    pub async fn update_schema(
29        &self,
30        schema_key: &str,
31        params: &UpdateSchemaParams,
32    ) -> Result<GetSchemaResponse> {
33        self.http
34            .put(&format!("/objects/{schema_key}"), params)
35            .await
36    }
37
38    // ── Records ──────────────────────────────────────────────────────────────
39
40    pub async fn create_record(
41        &self,
42        schema_key: &str,
43        params: &CreateRecordParams,
44    ) -> Result<CreateRecordResponse> {
45        self.http
46            .post(&format!("/objects/{schema_key}/records"), params)
47            .await
48    }
49
50    pub async fn get_record(&self, schema_key: &str, record_id: &str) -> Result<GetRecordResponse> {
51        self.http
52            .get(&format!("/objects/{schema_key}/records/{record_id}"))
53            .await
54    }
55
56    pub async fn update_record(
57        &self,
58        schema_key: &str,
59        record_id: &str,
60        params: &UpdateRecordParams,
61    ) -> Result<GetRecordResponse> {
62        self.http
63            .put(
64                &format!("/objects/{schema_key}/records/{record_id}"),
65                params,
66            )
67            .await
68    }
69
70    pub async fn delete_record(
71        &self,
72        schema_key: &str,
73        record_id: &str,
74    ) -> Result<DeleteRecordResponse> {
75        self.http
76            .delete(&format!("/objects/{schema_key}/records/{record_id}"))
77            .await
78    }
79
80    pub async fn search_records(
81        &self,
82        schema_key: &str,
83        params: &SearchRecordsParams,
84    ) -> Result<SearchRecordsResponse> {
85        self.http
86            .post(&format!("/objects/{schema_key}/records/search"), params)
87            .await
88    }
89}