1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ArchiveSupplySourceError {
22 Status400(models::supply_sources_2020_07_01::ErrorList),
23 Status403(models::supply_sources_2020_07_01::ErrorList),
24 Status404(models::supply_sources_2020_07_01::ErrorList),
25 Status413(models::supply_sources_2020_07_01::ErrorList),
26 Status415(models::supply_sources_2020_07_01::ErrorList),
27 Status429(models::supply_sources_2020_07_01::ErrorList),
28 Status500(models::supply_sources_2020_07_01::ErrorList),
29 Status503(models::supply_sources_2020_07_01::ErrorList),
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum CreateSupplySourceError {
37 Status400(models::supply_sources_2020_07_01::ErrorList),
38 Status403(models::supply_sources_2020_07_01::ErrorList),
39 Status404(models::supply_sources_2020_07_01::ErrorList),
40 Status413(models::supply_sources_2020_07_01::ErrorList),
41 Status415(models::supply_sources_2020_07_01::ErrorList),
42 Status429(models::supply_sources_2020_07_01::ErrorList),
43 Status500(models::supply_sources_2020_07_01::ErrorList),
44 Status503(models::supply_sources_2020_07_01::ErrorList),
45 UnknownValue(serde_json::Value),
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetSupplySourceError {
52 Status400(models::supply_sources_2020_07_01::ErrorList),
53 Status403(models::supply_sources_2020_07_01::ErrorList),
54 Status404(models::supply_sources_2020_07_01::ErrorList),
55 Status413(models::supply_sources_2020_07_01::ErrorList),
56 Status415(models::supply_sources_2020_07_01::ErrorList),
57 Status429(models::supply_sources_2020_07_01::ErrorList),
58 Status500(models::supply_sources_2020_07_01::ErrorList),
59 Status503(models::supply_sources_2020_07_01::ErrorList),
60 UnknownValue(serde_json::Value),
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum GetSupplySourcesError {
67 Status400(models::supply_sources_2020_07_01::ErrorList),
68 Status403(models::supply_sources_2020_07_01::ErrorList),
69 Status404(models::supply_sources_2020_07_01::ErrorList),
70 Status413(models::supply_sources_2020_07_01::ErrorList),
71 Status415(models::supply_sources_2020_07_01::ErrorList),
72 Status429(models::supply_sources_2020_07_01::ErrorList),
73 Status500(models::supply_sources_2020_07_01::ErrorList),
74 Status503(models::supply_sources_2020_07_01::ErrorList),
75 UnknownValue(serde_json::Value),
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum UpdateSupplySourceError {
82 Status400(models::supply_sources_2020_07_01::ErrorList),
83 Status403(models::supply_sources_2020_07_01::ErrorList),
84 Status404(models::supply_sources_2020_07_01::ErrorList),
85 Status413(models::supply_sources_2020_07_01::ErrorList),
86 Status415(models::supply_sources_2020_07_01::ErrorList),
87 Status429(models::supply_sources_2020_07_01::ErrorList),
88 Status500(models::supply_sources_2020_07_01::ErrorList),
89 Status503(models::supply_sources_2020_07_01::ErrorList),
90 UnknownValue(serde_json::Value),
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum UpdateSupplySourceStatusError {
97 Status400(models::supply_sources_2020_07_01::ErrorList),
98 Status403(models::supply_sources_2020_07_01::ErrorList),
99 Status404(models::supply_sources_2020_07_01::ErrorList),
100 Status413(models::supply_sources_2020_07_01::ErrorList),
101 Status415(models::supply_sources_2020_07_01::ErrorList),
102 Status429(models::supply_sources_2020_07_01::ErrorList),
103 Status500(models::supply_sources_2020_07_01::ErrorList),
104 Status503(models::supply_sources_2020_07_01::ErrorList),
105 UnknownValue(serde_json::Value),
106}
107
108
109pub async fn archive_supply_source(configuration: &configuration::Configuration, supply_source_id: &str) -> Result<models::supply_sources_2020_07_01::ErrorList, Error<ArchiveSupplySourceError>> {
111 let p_supply_source_id = supply_source_id;
113
114 let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
115 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
116
117 if let Some(ref user_agent) = configuration.user_agent {
118 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
119 }
120
121 let req = req_builder.build()?;
122 let resp = configuration.client.execute(req).await?;
123
124 let status = resp.status();
125 let content_type = resp
126 .headers()
127 .get("content-type")
128 .and_then(|v| v.to_str().ok())
129 .unwrap_or("application/octet-stream");
130 let content_type = super::ContentType::from(content_type);
131
132 if !status.is_client_error() && !status.is_server_error() {
133 let content = resp.text().await?;
134 match content_type {
135 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
136 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`"))),
137 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`")))),
138 }
139 } else {
140 let content = resp.text().await?;
141 let entity: Option<ArchiveSupplySourceError> = serde_json::from_str(&content).ok();
142 Err(Error::ResponseError(ResponseContent { status, content, entity }))
143 }
144}
145
146pub async fn create_supply_source(configuration: &configuration::Configuration, payload: models::supply_sources_2020_07_01::CreateSupplySourceRequest) -> Result<models::supply_sources_2020_07_01::CreateSupplySourceResponse, Error<CreateSupplySourceError>> {
148 let p_payload = payload;
150
151 let uri_str = format!("{}/supplySources/2020-07-01/supplySources", configuration.base_path);
152 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
153
154 if let Some(ref user_agent) = configuration.user_agent {
155 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
156 }
157 req_builder = req_builder.json(&p_payload);
158
159 let req = req_builder.build()?;
160 let resp = configuration.client.execute(req).await?;
161
162 let status = resp.status();
163 let content_type = resp
164 .headers()
165 .get("content-type")
166 .and_then(|v| v.to_str().ok())
167 .unwrap_or("application/octet-stream");
168 let content_type = super::ContentType::from(content_type);
169
170 if !status.is_client_error() && !status.is_server_error() {
171 let content = resp.text().await?;
172 match content_type {
173 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
174 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::CreateSupplySourceResponse`"))),
175 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::CreateSupplySourceResponse`")))),
176 }
177 } else {
178 let content = resp.text().await?;
179 let entity: Option<CreateSupplySourceError> = serde_json::from_str(&content).ok();
180 Err(Error::ResponseError(ResponseContent { status, content, entity }))
181 }
182}
183
184pub async fn get_supply_source(configuration: &configuration::Configuration, supply_source_id: &str) -> Result<models::supply_sources_2020_07_01::SupplySource, Error<GetSupplySourceError>> {
186 let p_supply_source_id = supply_source_id;
188
189 let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
190 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
191
192 if let Some(ref user_agent) = configuration.user_agent {
193 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
194 }
195
196 let req = req_builder.build()?;
197 let resp = configuration.client.execute(req).await?;
198
199 let status = resp.status();
200 let content_type = resp
201 .headers()
202 .get("content-type")
203 .and_then(|v| v.to_str().ok())
204 .unwrap_or("application/octet-stream");
205 let content_type = super::ContentType::from(content_type);
206
207 if !status.is_client_error() && !status.is_server_error() {
208 let content = resp.text().await?;
209 match content_type {
210 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
211 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::SupplySource`"))),
212 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::SupplySource`")))),
213 }
214 } else {
215 let content = resp.text().await?;
216 let entity: Option<GetSupplySourceError> = serde_json::from_str(&content).ok();
217 Err(Error::ResponseError(ResponseContent { status, content, entity }))
218 }
219}
220
221pub async fn get_supply_sources(configuration: &configuration::Configuration, next_page_token: Option<&str>, page_size: Option<f64>) -> Result<models::supply_sources_2020_07_01::GetSupplySourcesResponse, Error<GetSupplySourcesError>> {
223 let p_next_page_token = next_page_token;
225 let p_page_size = page_size;
226
227 let uri_str = format!("{}/supplySources/2020-07-01/supplySources", configuration.base_path);
228 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
229
230 if let Some(ref param_value) = p_next_page_token {
231 req_builder = req_builder.query(&[("nextPageToken", ¶m_value.to_string())]);
232 }
233 if let Some(ref param_value) = p_page_size {
234 req_builder = req_builder.query(&[("pageSize", ¶m_value.to_string())]);
235 }
236 if let Some(ref user_agent) = configuration.user_agent {
237 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
238 }
239
240 let req = req_builder.build()?;
241 let resp = configuration.client.execute(req).await?;
242
243 let status = resp.status();
244 let content_type = resp
245 .headers()
246 .get("content-type")
247 .and_then(|v| v.to_str().ok())
248 .unwrap_or("application/octet-stream");
249 let content_type = super::ContentType::from(content_type);
250
251 if !status.is_client_error() && !status.is_server_error() {
252 let content = resp.text().await?;
253 match content_type {
254 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
255 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::GetSupplySourcesResponse`"))),
256 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::GetSupplySourcesResponse`")))),
257 }
258 } else {
259 let content = resp.text().await?;
260 let entity: Option<GetSupplySourcesError> = serde_json::from_str(&content).ok();
261 Err(Error::ResponseError(ResponseContent { status, content, entity }))
262 }
263}
264
265pub async fn update_supply_source(configuration: &configuration::Configuration, supply_source_id: &str, payload: Option<models::supply_sources_2020_07_01::UpdateSupplySourceRequest>) -> Result<models::supply_sources_2020_07_01::ErrorList, Error<UpdateSupplySourceError>> {
267 let p_supply_source_id = supply_source_id;
269 let p_payload = payload;
270
271 let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
272 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
273
274 if let Some(ref user_agent) = configuration.user_agent {
275 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
276 }
277 req_builder = req_builder.json(&p_payload);
278
279 let req = req_builder.build()?;
280 let resp = configuration.client.execute(req).await?;
281
282 let status = resp.status();
283 let content_type = resp
284 .headers()
285 .get("content-type")
286 .and_then(|v| v.to_str().ok())
287 .unwrap_or("application/octet-stream");
288 let content_type = super::ContentType::from(content_type);
289
290 if !status.is_client_error() && !status.is_server_error() {
291 let content = resp.text().await?;
292 match content_type {
293 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
294 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`"))),
295 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`")))),
296 }
297 } else {
298 let content = resp.text().await?;
299 let entity: Option<UpdateSupplySourceError> = serde_json::from_str(&content).ok();
300 Err(Error::ResponseError(ResponseContent { status, content, entity }))
301 }
302}
303
304pub async fn update_supply_source_status(configuration: &configuration::Configuration, supply_source_id: &str, payload: Option<models::supply_sources_2020_07_01::UpdateSupplySourceStatusRequest>) -> Result<models::supply_sources_2020_07_01::ErrorList, Error<UpdateSupplySourceStatusError>> {
306 let p_supply_source_id = supply_source_id;
308 let p_payload = payload;
309
310 let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}/status", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
311 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
312
313 if let Some(ref user_agent) = configuration.user_agent {
314 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
315 }
316 req_builder = req_builder.json(&p_payload);
317
318 let req = req_builder.build()?;
319 let resp = configuration.client.execute(req).await?;
320
321 let status = resp.status();
322 let content_type = resp
323 .headers()
324 .get("content-type")
325 .and_then(|v| v.to_str().ok())
326 .unwrap_or("application/octet-stream");
327 let content_type = super::ContentType::from(content_type);
328
329 if !status.is_client_error() && !status.is_server_error() {
330 let content = resp.text().await?;
331 match content_type {
332 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
333 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`"))),
334 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::supply_sources_2020_07_01::ErrorList`")))),
335 }
336 } else {
337 let content = resp.text().await?;
338 let entity: Option<UpdateSupplySourceStatusError> = serde_json::from_str(&content).ok();
339 Err(Error::ResponseError(ResponseContent { status, content, entity }))
340 }
341}
342