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::merchant_fulfillment_v0::CancelShipmentResponse),
23 Status401(models::merchant_fulfillment_v0::CancelShipmentResponse),
24 Status403(models::merchant_fulfillment_v0::CancelShipmentResponse),
25 Status404(models::merchant_fulfillment_v0::CancelShipmentResponse),
26 Status429(models::merchant_fulfillment_v0::CancelShipmentResponse),
27 Status500(models::merchant_fulfillment_v0::CancelShipmentResponse),
28 Status503(models::merchant_fulfillment_v0::CancelShipmentResponse),
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum CreateShipmentError {
36 Status400(models::merchant_fulfillment_v0::CreateShipmentResponse),
37 Status401(models::merchant_fulfillment_v0::CreateShipmentResponse),
38 Status403(models::merchant_fulfillment_v0::CreateShipmentResponse),
39 Status404(models::merchant_fulfillment_v0::CreateShipmentResponse),
40 Status429(models::merchant_fulfillment_v0::CreateShipmentResponse),
41 Status500(models::merchant_fulfillment_v0::CreateShipmentResponse),
42 Status503(models::merchant_fulfillment_v0::CreateShipmentResponse),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetAdditionalSellerInputsError {
50 Status400(models::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse),
51 Status401(models::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse),
52 Status403(models::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse),
53 Status404(models::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse),
54 Status429(models::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse),
55 Status500(models::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse),
56 Status503(models::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse),
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetEligibleShipmentServicesError {
64 Status400(models::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse),
65 Status401(models::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse),
66 Status403(models::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse),
67 Status404(models::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse),
68 Status429(models::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse),
69 Status500(models::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse),
70 Status503(models::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse),
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum GetShipmentError {
78 Status400(models::merchant_fulfillment_v0::GetShipmentResponse),
79 Status401(models::merchant_fulfillment_v0::GetShipmentResponse),
80 Status403(models::merchant_fulfillment_v0::GetShipmentResponse),
81 Status404(models::merchant_fulfillment_v0::GetShipmentResponse),
82 Status429(models::merchant_fulfillment_v0::GetShipmentResponse),
83 Status500(models::merchant_fulfillment_v0::GetShipmentResponse),
84 Status503(models::merchant_fulfillment_v0::GetShipmentResponse),
85 UnknownValue(serde_json::Value),
86}
87
88
89pub async fn cancel_shipment(configuration: &configuration::Configuration, shipment_id: &str) -> Result<models::merchant_fulfillment_v0::CancelShipmentResponse, Error<CancelShipmentError>> {
91 let p_shipment_id = shipment_id;
93
94 let uri_str = format!("{}/mfn/v0/shipments/{shipmentId}", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_id));
95 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
96
97 if let Some(ref user_agent) = configuration.user_agent {
98 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
99 }
100
101 let req = req_builder.build()?;
102 let resp = configuration.client.execute(req).await?;
103
104 let status = resp.status();
105 let content_type = resp
106 .headers()
107 .get("content-type")
108 .and_then(|v| v.to_str().ok())
109 .unwrap_or("application/octet-stream");
110 let content_type = super::ContentType::from(content_type);
111
112 if !status.is_client_error() && !status.is_server_error() {
113 let content = resp.text().await?;
114 match content_type {
115 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
116 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::merchant_fulfillment_v0::CancelShipmentResponse`"))),
117 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::merchant_fulfillment_v0::CancelShipmentResponse`")))),
118 }
119 } else {
120 let content = resp.text().await?;
121 let entity: Option<CancelShipmentError> = serde_json::from_str(&content).ok();
122 Err(Error::ResponseError(ResponseContent { status, content, entity }))
123 }
124}
125
126pub async fn create_shipment(configuration: &configuration::Configuration, body: models::merchant_fulfillment_v0::CreateShipmentRequest) -> Result<models::merchant_fulfillment_v0::CreateShipmentResponse, Error<CreateShipmentError>> {
128 let p_body = body;
130
131 let uri_str = format!("{}/mfn/v0/shipments", configuration.base_path);
132 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
133
134 if let Some(ref user_agent) = configuration.user_agent {
135 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
136 }
137 req_builder = req_builder.json(&p_body);
138
139 let req = req_builder.build()?;
140 let resp = configuration.client.execute(req).await?;
141
142 let status = resp.status();
143 let content_type = resp
144 .headers()
145 .get("content-type")
146 .and_then(|v| v.to_str().ok())
147 .unwrap_or("application/octet-stream");
148 let content_type = super::ContentType::from(content_type);
149
150 if !status.is_client_error() && !status.is_server_error() {
151 let content = resp.text().await?;
152 match content_type {
153 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
154 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::merchant_fulfillment_v0::CreateShipmentResponse`"))),
155 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::merchant_fulfillment_v0::CreateShipmentResponse`")))),
156 }
157 } else {
158 let content = resp.text().await?;
159 let entity: Option<CreateShipmentError> = serde_json::from_str(&content).ok();
160 Err(Error::ResponseError(ResponseContent { status, content, entity }))
161 }
162}
163
164pub async fn get_additional_seller_inputs(configuration: &configuration::Configuration, body: models::merchant_fulfillment_v0::GetAdditionalSellerInputsRequest) -> Result<models::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse, Error<GetAdditionalSellerInputsError>> {
166 let p_body = body;
168
169 let uri_str = format!("{}/mfn/v0/additionalSellerInputs", configuration.base_path);
170 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
171
172 if let Some(ref user_agent) = configuration.user_agent {
173 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
174 }
175 req_builder = req_builder.json(&p_body);
176
177 let req = req_builder.build()?;
178 let resp = configuration.client.execute(req).await?;
179
180 let status = resp.status();
181 let content_type = resp
182 .headers()
183 .get("content-type")
184 .and_then(|v| v.to_str().ok())
185 .unwrap_or("application/octet-stream");
186 let content_type = super::ContentType::from(content_type);
187
188 if !status.is_client_error() && !status.is_server_error() {
189 let content = resp.text().await?;
190 match content_type {
191 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
192 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse`"))),
193 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::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse`")))),
194 }
195 } else {
196 let content = resp.text().await?;
197 let entity: Option<GetAdditionalSellerInputsError> = serde_json::from_str(&content).ok();
198 Err(Error::ResponseError(ResponseContent { status, content, entity }))
199 }
200}
201
202pub async fn get_eligible_shipment_services(configuration: &configuration::Configuration, body: models::merchant_fulfillment_v0::GetEligibleShipmentServicesRequest) -> Result<models::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse, Error<GetEligibleShipmentServicesError>> {
204 let p_body = body;
206
207 let uri_str = format!("{}/mfn/v0/eligibleShippingServices", configuration.base_path);
208 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
209
210 if let Some(ref user_agent) = configuration.user_agent {
211 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
212 }
213 req_builder = req_builder.json(&p_body);
214
215 let req = req_builder.build()?;
216 let resp = configuration.client.execute(req).await?;
217
218 let status = resp.status();
219 let content_type = resp
220 .headers()
221 .get("content-type")
222 .and_then(|v| v.to_str().ok())
223 .unwrap_or("application/octet-stream");
224 let content_type = super::ContentType::from(content_type);
225
226 if !status.is_client_error() && !status.is_server_error() {
227 let content = resp.text().await?;
228 match content_type {
229 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
230 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse`"))),
231 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::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse`")))),
232 }
233 } else {
234 let content = resp.text().await?;
235 let entity: Option<GetEligibleShipmentServicesError> = serde_json::from_str(&content).ok();
236 Err(Error::ResponseError(ResponseContent { status, content, entity }))
237 }
238}
239
240pub async fn get_shipment(configuration: &configuration::Configuration, shipment_id: &str) -> Result<models::merchant_fulfillment_v0::GetShipmentResponse, Error<GetShipmentError>> {
242 let p_shipment_id = shipment_id;
244
245 let uri_str = format!("{}/mfn/v0/shipments/{shipmentId}", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_id));
246 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
247
248 if let Some(ref user_agent) = configuration.user_agent {
249 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
250 }
251
252 let req = req_builder.build()?;
253 let resp = configuration.client.execute(req).await?;
254
255 let status = resp.status();
256 let content_type = resp
257 .headers()
258 .get("content-type")
259 .and_then(|v| v.to_str().ok())
260 .unwrap_or("application/octet-stream");
261 let content_type = super::ContentType::from(content_type);
262
263 if !status.is_client_error() && !status.is_server_error() {
264 let content = resp.text().await?;
265 match content_type {
266 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
267 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::merchant_fulfillment_v0::GetShipmentResponse`"))),
268 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::merchant_fulfillment_v0::GetShipmentResponse`")))),
269 }
270 } else {
271 let content = resp.text().await?;
272 let entity: Option<GetShipmentError> = serde_json::from_str(&content).ok();
273 Err(Error::ResponseError(ResponseContent { status, content, entity }))
274 }
275}
276