square_api_client/api/
customer_groups_api.rs1use crate::{
15 config::Configuration,
16 http::client::HttpClient,
17 models::{
18 errors::ApiError, CreateCustomerGroupRequest, CreateCustomerGroupResponse,
19 DeleteCustomerGroupResponse, ListCustomerGroupsParameters, ListCustomerGroupsResponse,
20 RetrieveCustomerGroupResponse, UpdateCustomerGroupRequest, UpdateCustomerGroupResponse,
21 },
22};
23
24const DEFAULT_URI: &str = "/customers/groups";
25
26pub struct CustomerGroupsApi {
29 config: Configuration,
31 client: HttpClient,
33}
34
35impl CustomerGroupsApi {
36 pub fn new(config: Configuration, client: HttpClient) -> Self {
37 Self { config, client }
38 }
39
40 pub async fn list_customer_groups(
42 &self,
43 params: &ListCustomerGroupsParameters,
44 ) -> Result<ListCustomerGroupsResponse, ApiError> {
45 let url = format!("{}{}", &self.url(), params.to_query_string());
46 let response = self.client.get(&url).await?;
47
48 response.deserialize().await
49 }
50
51 pub async fn create_customer_group(
55 &self,
56 body: &CreateCustomerGroupRequest,
57 ) -> Result<CreateCustomerGroupResponse, ApiError> {
58 let response = self.client.post(&self.url(), body).await?;
59
60 response.deserialize().await
61 }
62
63 pub async fn delete_customer_group(
65 &self,
66 group_id: &str,
67 ) -> Result<DeleteCustomerGroupResponse, ApiError> {
68 let url = format!("{}/{}", &self.url(), group_id);
69 let response = self.client.delete(&url).await?;
70
71 response.deserialize().await
72 }
73
74 pub async fn retrieve_customer_group(
76 &self,
77 group_id: &str,
78 ) -> Result<RetrieveCustomerGroupResponse, ApiError> {
79 let url = format!("{}/{}", &self.url(), group_id);
80 let response = self.client.get(&url).await?;
81
82 response.deserialize().await
83 }
84
85 pub async fn update_customer_group(
86 &self,
87 group_id: &str,
88 body: &UpdateCustomerGroupRequest,
89 ) -> Result<UpdateCustomerGroupResponse, ApiError> {
90 let url = format!("{}/{}", &self.url(), group_id);
91 let response = self.client.put(&url, body).await?;
92
93 response.deserialize().await
94 }
95
96 fn url(&self) -> String {
97 format!("{}{}", &self.config.get_base_url(), DEFAULT_URI)
98 }
99}