1use reqwest;
13
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateClientError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteClientError {
29 Status401(),
30 Status404(),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetClientError {
38 Status401(),
39 Status404(),
40 UnknownValue(serde_json::Value),
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum ListClientsError {
47 Status401(),
48 UnknownValue(serde_json::Value),
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum ModifyClientError {
55 Status401(),
56 Status404(),
57 UnknownValue(serde_json::Value),
58}
59
60
61pub async fn create_client(configuration: &configuration::Configuration, company_id: i32, create_client_request: Option<models::CreateClientRequest>) -> Result<models::CreateClientResponse, Error<CreateClientError>> {
63 let local_var_configuration = configuration;
64
65 let local_var_client = &local_var_configuration.client;
66
67 let local_var_uri_str = format!("{}/c/{company_id}/entities/clients", local_var_configuration.base_path, company_id=company_id);
68 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
69
70 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
71 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
72 }
73 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
74 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
75 };
76 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
77 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
78 };
79 local_var_req_builder = local_var_req_builder.json(&create_client_request);
80
81 let local_var_req = local_var_req_builder.build()?;
82 let local_var_resp = local_var_client.execute(local_var_req).await?;
83
84 let local_var_status = local_var_resp.status();
85 let local_var_content = local_var_resp.text().await?;
86
87 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
88 serde_json::from_str(&local_var_content).map_err(Error::from)
89 } else {
90 let local_var_entity: Option<CreateClientError> = serde_json::from_str(&local_var_content).ok();
91 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
92 Err(Error::ResponseError(local_var_error))
93 }
94}
95
96pub async fn delete_client(configuration: &configuration::Configuration, company_id: i32, client_id: i32) -> Result<(), Error<DeleteClientError>> {
98 let local_var_configuration = configuration;
99
100 let local_var_client = &local_var_configuration.client;
101
102 let local_var_uri_str = format!("{}/c/{company_id}/entities/clients/{client_id}", local_var_configuration.base_path, company_id=company_id, client_id=client_id);
103 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
104
105 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
106 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
107 }
108 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
109 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
110 };
111 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
112 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
113 };
114
115 let local_var_req = local_var_req_builder.build()?;
116 let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118 let local_var_status = local_var_resp.status();
119 let local_var_content = local_var_resp.text().await?;
120
121 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122 Ok(())
123 } else {
124 let local_var_entity: Option<DeleteClientError> = serde_json::from_str(&local_var_content).ok();
125 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
126 Err(Error::ResponseError(local_var_error))
127 }
128}
129
130pub async fn get_client(configuration: &configuration::Configuration, company_id: i32, client_id: i32, fields: Option<&str>, fieldset: Option<&str>) -> Result<models::GetClientResponse, Error<GetClientError>> {
132 let local_var_configuration = configuration;
133
134 let local_var_client = &local_var_configuration.client;
135
136 let local_var_uri_str = format!("{}/c/{company_id}/entities/clients/{client_id}", local_var_configuration.base_path, company_id=company_id, client_id=client_id);
137 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
138
139 if let Some(ref local_var_str) = fields {
140 local_var_req_builder = local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
141 }
142 if let Some(ref local_var_str) = fieldset {
143 local_var_req_builder = local_var_req_builder.query(&[("fieldset", &local_var_str.to_string())]);
144 }
145 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
147 }
148 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
149 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
150 };
151 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
152 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
153 };
154
155 let local_var_req = local_var_req_builder.build()?;
156 let local_var_resp = local_var_client.execute(local_var_req).await?;
157
158 let local_var_status = local_var_resp.status();
159 let local_var_content = local_var_resp.text().await?;
160
161 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
162 serde_json::from_str(&local_var_content).map_err(Error::from)
163 } else {
164 let local_var_entity: Option<GetClientError> = serde_json::from_str(&local_var_content).ok();
165 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
166 Err(Error::ResponseError(local_var_error))
167 }
168}
169
170pub async fn list_clients(configuration: &configuration::Configuration, company_id: i32, fields: Option<&str>, fieldset: Option<&str>, sort: Option<&str>, page: Option<i32>, per_page: Option<u8>, q: Option<&str>) -> Result<models::ListClientsResponse, Error<ListClientsError>> {
172 let local_var_configuration = configuration;
173
174 let local_var_client = &local_var_configuration.client;
175
176 let local_var_uri_str = format!("{}/c/{company_id}/entities/clients", local_var_configuration.base_path, company_id=company_id);
177 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
178
179 if let Some(ref local_var_str) = fields {
180 local_var_req_builder = local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
181 }
182 if let Some(ref local_var_str) = fieldset {
183 local_var_req_builder = local_var_req_builder.query(&[("fieldset", &local_var_str.to_string())]);
184 }
185 if let Some(ref local_var_str) = sort {
186 local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
187 }
188 if let Some(ref local_var_str) = page {
189 local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
190 }
191 if let Some(ref local_var_str) = per_page {
192 local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
193 }
194 if let Some(ref local_var_str) = q {
195 local_var_req_builder = local_var_req_builder.query(&[("q", &local_var_str.to_string())]);
196 }
197 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
198 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
199 }
200 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
201 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
202 };
203 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
204 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
205 };
206
207 let local_var_req = local_var_req_builder.build()?;
208 let local_var_resp = local_var_client.execute(local_var_req).await?;
209
210 let local_var_status = local_var_resp.status();
211 let local_var_content = local_var_resp.text().await?;
212
213 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
214 serde_json::from_str(&local_var_content).map_err(Error::from)
215 } else {
216 let local_var_entity: Option<ListClientsError> = serde_json::from_str(&local_var_content).ok();
217 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
218 Err(Error::ResponseError(local_var_error))
219 }
220}
221
222pub async fn modify_client(configuration: &configuration::Configuration, company_id: i32, client_id: i32, modify_client_request: Option<models::ModifyClientRequest>) -> Result<models::ModifyClientResponse, Error<ModifyClientError>> {
224 let local_var_configuration = configuration;
225
226 let local_var_client = &local_var_configuration.client;
227
228 let local_var_uri_str = format!("{}/c/{company_id}/entities/clients/{client_id}", local_var_configuration.base_path, company_id=company_id, client_id=client_id);
229 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
230
231 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
232 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
233 }
234 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
235 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
236 };
237 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
238 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
239 };
240 local_var_req_builder = local_var_req_builder.json(&modify_client_request);
241
242 let local_var_req = local_var_req_builder.build()?;
243 let local_var_resp = local_var_client.execute(local_var_req).await?;
244
245 let local_var_status = local_var_resp.status();
246 let local_var_content = local_var_resp.text().await?;
247
248 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
249 serde_json::from_str(&local_var_content).map_err(Error::from)
250 } else {
251 let local_var_entity: Option<ModifyClientError> = serde_json::from_str(&local_var_content).ok();
252 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
253 Err(Error::ResponseError(local_var_error))
254 }
255}
256