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 CancelShipmentError {
22 Status400(models::shipping::CancelShipmentResponse),
23 Status401(models::shipping::CancelShipmentResponse),
24 Status403(models::shipping::CancelShipmentResponse),
25 Status404(models::shipping::CancelShipmentResponse),
26 Status429(models::shipping::CancelShipmentResponse),
27 Status500(models::shipping::CancelShipmentResponse),
28 Status503(models::shipping::CancelShipmentResponse),
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum CreateShipmentError {
36 Status400(models::shipping::CreateShipmentResponse),
37 Status401(models::shipping::CreateShipmentResponse),
38 Status403(models::shipping::CreateShipmentResponse),
39 Status404(models::shipping::CreateShipmentResponse),
40 Status429(models::shipping::CreateShipmentResponse),
41 Status500(models::shipping::CreateShipmentResponse),
42 Status503(models::shipping::CreateShipmentResponse),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetAccountError {
50 Status400(models::shipping::GetAccountResponse),
51 Status401(models::shipping::GetAccountResponse),
52 Status403(models::shipping::GetAccountResponse),
53 Status404(models::shipping::GetAccountResponse),
54 Status429(models::shipping::GetAccountResponse),
55 Status500(models::shipping::GetAccountResponse),
56 Status503(models::shipping::GetAccountResponse),
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetRatesError {
64 Status400(models::shipping::GetRatesResponse),
65 Status401(models::shipping::GetRatesResponse),
66 Status403(models::shipping::GetRatesResponse),
67 Status404(models::shipping::GetRatesResponse),
68 Status429(models::shipping::GetRatesResponse),
69 Status500(models::shipping::GetRatesResponse),
70 Status503(models::shipping::GetRatesResponse),
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum GetShipmentError {
78 Status400(models::shipping::GetShipmentResponse),
79 Status401(models::shipping::GetShipmentResponse),
80 Status403(models::shipping::GetShipmentResponse),
81 Status404(models::shipping::GetShipmentResponse),
82 Status429(models::shipping::GetShipmentResponse),
83 Status500(models::shipping::GetShipmentResponse),
84 Status503(models::shipping::GetShipmentResponse),
85 UnknownValue(serde_json::Value),
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum GetTrackingInformationError {
92 Status400(models::shipping::GetTrackingInformationResponse),
93 Status401(models::shipping::GetTrackingInformationResponse),
94 Status403(models::shipping::GetTrackingInformationResponse),
95 Status404(models::shipping::GetTrackingInformationResponse),
96 Status429(models::shipping::GetTrackingInformationResponse),
97 Status500(models::shipping::GetTrackingInformationResponse),
98 Status503(models::shipping::GetTrackingInformationResponse),
99 UnknownValue(serde_json::Value),
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum PurchaseLabelsError {
106 Status400(models::shipping::PurchaseLabelsResponse),
107 Status401(models::shipping::PurchaseLabelsResponse),
108 Status403(models::shipping::PurchaseLabelsResponse),
109 Status404(models::shipping::PurchaseLabelsResponse),
110 Status429(models::shipping::PurchaseLabelsResponse),
111 Status500(models::shipping::PurchaseLabelsResponse),
112 Status503(models::shipping::PurchaseLabelsResponse),
113 UnknownValue(serde_json::Value),
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum PurchaseShipmentError {
120 Status400(models::shipping::PurchaseShipmentResponse),
121 Status401(models::shipping::PurchaseShipmentResponse),
122 Status403(models::shipping::PurchaseShipmentResponse),
123 Status404(models::shipping::PurchaseShipmentResponse),
124 Status429(models::shipping::PurchaseShipmentResponse),
125 Status500(models::shipping::PurchaseShipmentResponse),
126 Status503(models::shipping::PurchaseShipmentResponse),
127 UnknownValue(serde_json::Value),
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(untagged)]
133pub enum RetrieveShippingLabelError {
134 Status400(models::shipping::RetrieveShippingLabelResponse),
135 Status401(models::shipping::RetrieveShippingLabelResponse),
136 Status403(models::shipping::RetrieveShippingLabelResponse),
137 Status404(models::shipping::RetrieveShippingLabelResponse),
138 Status429(models::shipping::RetrieveShippingLabelResponse),
139 Status500(models::shipping::RetrieveShippingLabelResponse),
140 Status503(models::shipping::RetrieveShippingLabelResponse),
141 UnknownValue(serde_json::Value),
142}
143
144
145pub async fn cancel_shipment(configuration: &configuration::Configuration, shipment_id: &str) -> Result<models::shipping::CancelShipmentResponse, Error<CancelShipmentError>> {
147 let p_shipment_id = shipment_id;
149
150 let uri_str = format!("{}/shipping/v1/shipments/{shipmentId}/cancel", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_id));
151 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
152
153 if let Some(ref user_agent) = configuration.user_agent {
154 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
155 }
156
157 let req = req_builder.build()?;
158 let resp = configuration.client.execute(req).await?;
159
160 let status = resp.status();
161 let content_type = resp
162 .headers()
163 .get("content-type")
164 .and_then(|v| v.to_str().ok())
165 .unwrap_or("application/octet-stream");
166 let content_type = super::ContentType::from(content_type);
167
168 if !status.is_client_error() && !status.is_server_error() {
169 let content = resp.text().await?;
170 match content_type {
171 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
172 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipping::CancelShipmentResponse`"))),
173 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::shipping::CancelShipmentResponse`")))),
174 }
175 } else {
176 let content = resp.text().await?;
177 let entity: Option<CancelShipmentError> = serde_json::from_str(&content).ok();
178 Err(Error::ResponseError(ResponseContent { status, content, entity }))
179 }
180}
181
182pub async fn create_shipment(configuration: &configuration::Configuration, body: models::shipping::CreateShipmentRequest) -> Result<models::shipping::CreateShipmentResponse, Error<CreateShipmentError>> {
184 let p_body = body;
186
187 let uri_str = format!("{}/shipping/v1/shipments", configuration.base_path);
188 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
189
190 if let Some(ref user_agent) = configuration.user_agent {
191 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
192 }
193 req_builder = req_builder.json(&p_body);
194
195 let req = req_builder.build()?;
196 let resp = configuration.client.execute(req).await?;
197
198 let status = resp.status();
199 let content_type = resp
200 .headers()
201 .get("content-type")
202 .and_then(|v| v.to_str().ok())
203 .unwrap_or("application/octet-stream");
204 let content_type = super::ContentType::from(content_type);
205
206 if !status.is_client_error() && !status.is_server_error() {
207 let content = resp.text().await?;
208 match content_type {
209 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
210 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipping::CreateShipmentResponse`"))),
211 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::shipping::CreateShipmentResponse`")))),
212 }
213 } else {
214 let content = resp.text().await?;
215 let entity: Option<CreateShipmentError> = serde_json::from_str(&content).ok();
216 Err(Error::ResponseError(ResponseContent { status, content, entity }))
217 }
218}
219
220pub async fn get_account(configuration: &configuration::Configuration, ) -> Result<models::shipping::GetAccountResponse, Error<GetAccountError>> {
222
223 let uri_str = format!("{}/shipping/v1/account", configuration.base_path);
224 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
225
226 if let Some(ref user_agent) = configuration.user_agent {
227 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
228 }
229
230 let req = req_builder.build()?;
231 let resp = configuration.client.execute(req).await?;
232
233 let status = resp.status();
234 let content_type = resp
235 .headers()
236 .get("content-type")
237 .and_then(|v| v.to_str().ok())
238 .unwrap_or("application/octet-stream");
239 let content_type = super::ContentType::from(content_type);
240
241 if !status.is_client_error() && !status.is_server_error() {
242 let content = resp.text().await?;
243 match content_type {
244 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
245 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipping::GetAccountResponse`"))),
246 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::shipping::GetAccountResponse`")))),
247 }
248 } else {
249 let content = resp.text().await?;
250 let entity: Option<GetAccountError> = serde_json::from_str(&content).ok();
251 Err(Error::ResponseError(ResponseContent { status, content, entity }))
252 }
253}
254
255pub async fn get_rates(configuration: &configuration::Configuration, body: models::shipping::GetRatesRequest) -> Result<models::shipping::GetRatesResponse, Error<GetRatesError>> {
257 let p_body = body;
259
260 let uri_str = format!("{}/shipping/v1/rates", configuration.base_path);
261 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
262
263 if let Some(ref user_agent) = configuration.user_agent {
264 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
265 }
266 req_builder = req_builder.json(&p_body);
267
268 let req = req_builder.build()?;
269 let resp = configuration.client.execute(req).await?;
270
271 let status = resp.status();
272 let content_type = resp
273 .headers()
274 .get("content-type")
275 .and_then(|v| v.to_str().ok())
276 .unwrap_or("application/octet-stream");
277 let content_type = super::ContentType::from(content_type);
278
279 if !status.is_client_error() && !status.is_server_error() {
280 let content = resp.text().await?;
281 match content_type {
282 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
283 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipping::GetRatesResponse`"))),
284 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::shipping::GetRatesResponse`")))),
285 }
286 } else {
287 let content = resp.text().await?;
288 let entity: Option<GetRatesError> = serde_json::from_str(&content).ok();
289 Err(Error::ResponseError(ResponseContent { status, content, entity }))
290 }
291}
292
293pub async fn get_shipment(configuration: &configuration::Configuration, shipment_id: &str) -> Result<models::shipping::GetShipmentResponse, Error<GetShipmentError>> {
295 let p_shipment_id = shipment_id;
297
298 let uri_str = format!("{}/shipping/v1/shipments/{shipmentId}", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_id));
299 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
300
301 if let Some(ref user_agent) = configuration.user_agent {
302 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
303 }
304
305 let req = req_builder.build()?;
306 let resp = configuration.client.execute(req).await?;
307
308 let status = resp.status();
309 let content_type = resp
310 .headers()
311 .get("content-type")
312 .and_then(|v| v.to_str().ok())
313 .unwrap_or("application/octet-stream");
314 let content_type = super::ContentType::from(content_type);
315
316 if !status.is_client_error() && !status.is_server_error() {
317 let content = resp.text().await?;
318 match content_type {
319 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
320 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipping::GetShipmentResponse`"))),
321 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::shipping::GetShipmentResponse`")))),
322 }
323 } else {
324 let content = resp.text().await?;
325 let entity: Option<GetShipmentError> = serde_json::from_str(&content).ok();
326 Err(Error::ResponseError(ResponseContent { status, content, entity }))
327 }
328}
329
330pub async fn get_tracking_information(configuration: &configuration::Configuration, tracking_id: &str) -> Result<models::shipping::GetTrackingInformationResponse, Error<GetTrackingInformationError>> {
332 let p_tracking_id = tracking_id;
334
335 let uri_str = format!("{}/shipping/v1/tracking/{trackingId}", configuration.base_path, trackingId=crate::apis::urlencode(p_tracking_id));
336 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
337
338 if let Some(ref user_agent) = configuration.user_agent {
339 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
340 }
341
342 let req = req_builder.build()?;
343 let resp = configuration.client.execute(req).await?;
344
345 let status = resp.status();
346 let content_type = resp
347 .headers()
348 .get("content-type")
349 .and_then(|v| v.to_str().ok())
350 .unwrap_or("application/octet-stream");
351 let content_type = super::ContentType::from(content_type);
352
353 if !status.is_client_error() && !status.is_server_error() {
354 let content = resp.text().await?;
355 match content_type {
356 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
357 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipping::GetTrackingInformationResponse`"))),
358 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::shipping::GetTrackingInformationResponse`")))),
359 }
360 } else {
361 let content = resp.text().await?;
362 let entity: Option<GetTrackingInformationError> = serde_json::from_str(&content).ok();
363 Err(Error::ResponseError(ResponseContent { status, content, entity }))
364 }
365}
366
367pub async fn purchase_labels(configuration: &configuration::Configuration, shipment_id: &str, body: models::shipping::PurchaseLabelsRequest) -> Result<models::shipping::PurchaseLabelsResponse, Error<PurchaseLabelsError>> {
369 let p_shipment_id = shipment_id;
371 let p_body = body;
372
373 let uri_str = format!("{}/shipping/v1/shipments/{shipmentId}/purchaseLabels", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_id));
374 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
375
376 if let Some(ref user_agent) = configuration.user_agent {
377 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
378 }
379 req_builder = req_builder.json(&p_body);
380
381 let req = req_builder.build()?;
382 let resp = configuration.client.execute(req).await?;
383
384 let status = resp.status();
385 let content_type = resp
386 .headers()
387 .get("content-type")
388 .and_then(|v| v.to_str().ok())
389 .unwrap_or("application/octet-stream");
390 let content_type = super::ContentType::from(content_type);
391
392 if !status.is_client_error() && !status.is_server_error() {
393 let content = resp.text().await?;
394 match content_type {
395 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
396 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipping::PurchaseLabelsResponse`"))),
397 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::shipping::PurchaseLabelsResponse`")))),
398 }
399 } else {
400 let content = resp.text().await?;
401 let entity: Option<PurchaseLabelsError> = serde_json::from_str(&content).ok();
402 Err(Error::ResponseError(ResponseContent { status, content, entity }))
403 }
404}
405
406pub async fn purchase_shipment(configuration: &configuration::Configuration, body: models::shipping::PurchaseShipmentRequest) -> Result<models::shipping::PurchaseShipmentResponse, Error<PurchaseShipmentError>> {
408 let p_body = body;
410
411 let uri_str = format!("{}/shipping/v1/purchaseShipment", configuration.base_path);
412 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
413
414 if let Some(ref user_agent) = configuration.user_agent {
415 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
416 }
417 req_builder = req_builder.json(&p_body);
418
419 let req = req_builder.build()?;
420 let resp = configuration.client.execute(req).await?;
421
422 let status = resp.status();
423 let content_type = resp
424 .headers()
425 .get("content-type")
426 .and_then(|v| v.to_str().ok())
427 .unwrap_or("application/octet-stream");
428 let content_type = super::ContentType::from(content_type);
429
430 if !status.is_client_error() && !status.is_server_error() {
431 let content = resp.text().await?;
432 match content_type {
433 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
434 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipping::PurchaseShipmentResponse`"))),
435 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::shipping::PurchaseShipmentResponse`")))),
436 }
437 } else {
438 let content = resp.text().await?;
439 let entity: Option<PurchaseShipmentError> = serde_json::from_str(&content).ok();
440 Err(Error::ResponseError(ResponseContent { status, content, entity }))
441 }
442}
443
444pub async fn retrieve_shipping_label(configuration: &configuration::Configuration, shipment_id: &str, tracking_id: &str, body: models::shipping::RetrieveShippingLabelRequest) -> Result<models::shipping::RetrieveShippingLabelResponse, Error<RetrieveShippingLabelError>> {
446 let p_shipment_id = shipment_id;
448 let p_tracking_id = tracking_id;
449 let p_body = body;
450
451 let uri_str = format!("{}/shipping/v1/shipments/{shipmentId}/containers/{trackingId}/label", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_id), trackingId=crate::apis::urlencode(p_tracking_id));
452 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
453
454 if let Some(ref user_agent) = configuration.user_agent {
455 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
456 }
457 req_builder = req_builder.json(&p_body);
458
459 let req = req_builder.build()?;
460 let resp = configuration.client.execute(req).await?;
461
462 let status = resp.status();
463 let content_type = resp
464 .headers()
465 .get("content-type")
466 .and_then(|v| v.to_str().ok())
467 .unwrap_or("application/octet-stream");
468 let content_type = super::ContentType::from(content_type);
469
470 if !status.is_client_error() && !status.is_server_error() {
471 let content = resp.text().await?;
472 match content_type {
473 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
474 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipping::RetrieveShippingLabelResponse`"))),
475 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::shipping::RetrieveShippingLabelResponse`")))),
476 }
477 } else {
478 let content = resp.text().await?;
479 let entity: Option<RetrieveShippingLabelError> = serde_json::from_str(&content).ok();
480 Err(Error::ResponseError(ResponseContent { status, content, entity }))
481 }
482}
483