1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CancelFeedError {
20 Status400(models::feeds_2021_06_30::ErrorList),
21 Status401(models::feeds_2021_06_30::ErrorList),
22 Status403(models::feeds_2021_06_30::ErrorList),
23 Status404(models::feeds_2021_06_30::ErrorList),
24 Status415(models::feeds_2021_06_30::ErrorList),
25 Status429(models::feeds_2021_06_30::ErrorList),
26 Status500(models::feeds_2021_06_30::ErrorList),
27 Status503(models::feeds_2021_06_30::ErrorList),
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum CreateFeedError {
35 Status400(models::feeds_2021_06_30::ErrorList),
36 Status401(models::feeds_2021_06_30::ErrorList),
37 Status403(models::feeds_2021_06_30::ErrorList),
38 Status404(models::feeds_2021_06_30::ErrorList),
39 Status415(models::feeds_2021_06_30::ErrorList),
40 Status429(models::feeds_2021_06_30::ErrorList),
41 Status500(models::feeds_2021_06_30::ErrorList),
42 Status503(models::feeds_2021_06_30::ErrorList),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum CreateFeedDocumentError {
50 Status400(models::feeds_2021_06_30::ErrorList),
51 Status403(models::feeds_2021_06_30::ErrorList),
52 Status404(models::feeds_2021_06_30::ErrorList),
53 Status413(models::feeds_2021_06_30::ErrorList),
54 Status415(models::feeds_2021_06_30::ErrorList),
55 Status429(models::feeds_2021_06_30::ErrorList),
56 Status500(models::feeds_2021_06_30::ErrorList),
57 Status503(models::feeds_2021_06_30::ErrorList),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum GetFeedError {
65 Status400(models::feeds_2021_06_30::ErrorList),
66 Status401(models::feeds_2021_06_30::ErrorList),
67 Status403(models::feeds_2021_06_30::ErrorList),
68 Status404(models::feeds_2021_06_30::ErrorList),
69 Status415(models::feeds_2021_06_30::ErrorList),
70 Status429(models::feeds_2021_06_30::ErrorList),
71 Status500(models::feeds_2021_06_30::ErrorList),
72 Status503(models::feeds_2021_06_30::ErrorList),
73 UnknownValue(serde_json::Value),
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum GetFeedDocumentError {
80 Status400(models::feeds_2021_06_30::ErrorList),
81 Status401(models::feeds_2021_06_30::ErrorList),
82 Status403(models::feeds_2021_06_30::ErrorList),
83 Status404(models::feeds_2021_06_30::ErrorList),
84 Status415(models::feeds_2021_06_30::ErrorList),
85 Status429(models::feeds_2021_06_30::ErrorList),
86 Status500(models::feeds_2021_06_30::ErrorList),
87 Status503(models::feeds_2021_06_30::ErrorList),
88 UnknownValue(serde_json::Value),
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum GetFeedsError {
95 Status400(models::feeds_2021_06_30::ErrorList),
96 Status401(models::feeds_2021_06_30::ErrorList),
97 Status403(models::feeds_2021_06_30::ErrorList),
98 Status404(models::feeds_2021_06_30::ErrorList),
99 Status415(models::feeds_2021_06_30::ErrorList),
100 Status429(models::feeds_2021_06_30::ErrorList),
101 Status500(models::feeds_2021_06_30::ErrorList),
102 Status503(models::feeds_2021_06_30::ErrorList),
103 UnknownValue(serde_json::Value),
104}
105
106pub async fn cancel_feed(
108 configuration: &configuration::Configuration,
109 feed_id: &str,
110) -> Result<(), Error<CancelFeedError>> {
111 let p_feed_id = feed_id;
113
114 let uri_str = format!(
115 "{}/feeds/2021-06-30/feeds/{feedId}",
116 configuration.base_path,
117 feedId = crate::apis::urlencode(p_feed_id)
118 );
119 let mut req_builder = configuration
120 .client
121 .request(reqwest::Method::DELETE, &uri_str);
122
123 if let Some(ref user_agent) = configuration.user_agent {
124 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
125 }
126
127 let req = req_builder.build()?;
128 let resp = configuration.client.execute(req).await?;
129
130 let status = resp.status();
131
132 if !status.is_client_error() && !status.is_server_error() {
133 Ok(())
134 } else {
135 let content = resp.text().await?;
136 let entity: Option<CancelFeedError> = serde_json::from_str(&content).ok();
137 Err(Error::ResponseError(ResponseContent {
138 status,
139 content,
140 entity,
141 }))
142 }
143}
144
145pub async fn create_feed(
147 configuration: &configuration::Configuration,
148 body: models::feeds_2021_06_30::CreateFeedSpecification,
149) -> Result<models::feeds_2021_06_30::CreateFeedResponse, Error<CreateFeedError>> {
150 let p_body = body;
152
153 let uri_str = format!("{}/feeds/2021-06-30/feeds", configuration.base_path);
154 let mut req_builder = configuration
155 .client
156 .request(reqwest::Method::POST, &uri_str);
157
158 if let Some(ref user_agent) = configuration.user_agent {
159 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
160 }
161 req_builder = req_builder.json(&p_body);
162
163 let req = req_builder.build()?;
164 let resp = configuration.client.execute(req).await?;
165
166 let status = resp.status();
167 let content_type = resp
168 .headers()
169 .get("content-type")
170 .and_then(|v| v.to_str().ok())
171 .unwrap_or("application/octet-stream");
172 let content_type = super::ContentType::from(content_type);
173
174 if !status.is_client_error() && !status.is_server_error() {
175 let content = resp.text().await?;
176 match content_type {
177 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
178 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::feeds_2021_06_30::CreateFeedResponse`"))),
179 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::feeds_2021_06_30::CreateFeedResponse`")))),
180 }
181 } else {
182 let content = resp.text().await?;
183 let entity: Option<CreateFeedError> = serde_json::from_str(&content).ok();
184 Err(Error::ResponseError(ResponseContent {
185 status,
186 content,
187 entity,
188 }))
189 }
190}
191
192pub async fn create_feed_document(
194 configuration: &configuration::Configuration,
195 body: models::feeds_2021_06_30::CreateFeedDocumentSpecification,
196) -> Result<models::feeds_2021_06_30::CreateFeedDocumentResponse, Error<CreateFeedDocumentError>> {
197 let p_body = body;
199
200 let uri_str = format!("{}/feeds/2021-06-30/documents", configuration.base_path);
201 let mut req_builder = configuration
202 .client
203 .request(reqwest::Method::POST, &uri_str);
204
205 if let Some(ref user_agent) = configuration.user_agent {
206 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
207 }
208 req_builder = req_builder.json(&p_body);
209
210 let req = req_builder.build()?;
211 let resp = configuration.client.execute(req).await?;
212
213 let status = resp.status();
214 let content_type = resp
215 .headers()
216 .get("content-type")
217 .and_then(|v| v.to_str().ok())
218 .unwrap_or("application/octet-stream");
219 let content_type = super::ContentType::from(content_type);
220
221 if !status.is_client_error() && !status.is_server_error() {
222 let content = resp.text().await?;
223 match content_type {
224 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
225 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::feeds_2021_06_30::CreateFeedDocumentResponse`"))),
226 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::feeds_2021_06_30::CreateFeedDocumentResponse`")))),
227 }
228 } else {
229 let content = resp.text().await?;
230 let entity: Option<CreateFeedDocumentError> = serde_json::from_str(&content).ok();
231 Err(Error::ResponseError(ResponseContent {
232 status,
233 content,
234 entity,
235 }))
236 }
237}
238
239pub async fn get_feed(
241 configuration: &configuration::Configuration,
242 feed_id: &str,
243) -> Result<models::feeds_2021_06_30::Feed, Error<GetFeedError>> {
244 let p_feed_id = feed_id;
246
247 let uri_str = format!(
248 "{}/feeds/2021-06-30/feeds/{feedId}",
249 configuration.base_path,
250 feedId = crate::apis::urlencode(p_feed_id)
251 );
252 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
253
254 if let Some(ref user_agent) = configuration.user_agent {
255 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
256 }
257
258 let req = req_builder.build()?;
259 let resp = configuration.client.execute(req).await?;
260
261 let status = resp.status();
262 let content_type = resp
263 .headers()
264 .get("content-type")
265 .and_then(|v| v.to_str().ok())
266 .unwrap_or("application/octet-stream");
267 let content_type = super::ContentType::from(content_type);
268
269 if !status.is_client_error() && !status.is_server_error() {
270 let content = resp.text().await?;
271 match content_type {
272 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
273 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::feeds_2021_06_30::Feed`"))),
274 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::feeds_2021_06_30::Feed`")))),
275 }
276 } else {
277 let content = resp.text().await?;
278 let entity: Option<GetFeedError> = serde_json::from_str(&content).ok();
279 Err(Error::ResponseError(ResponseContent {
280 status,
281 content,
282 entity,
283 }))
284 }
285}
286
287pub async fn get_feed_document(
289 configuration: &configuration::Configuration,
290 feed_document_id: &str,
291) -> Result<models::feeds_2021_06_30::FeedDocument, Error<GetFeedDocumentError>> {
292 let p_feed_document_id = feed_document_id;
294
295 let uri_str = format!(
296 "{}/feeds/2021-06-30/documents/{feedDocumentId}",
297 configuration.base_path,
298 feedDocumentId = crate::apis::urlencode(p_feed_document_id)
299 );
300 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
301
302 if let Some(ref user_agent) = configuration.user_agent {
303 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
304 }
305
306 let req = req_builder.build()?;
307 let resp = configuration.client.execute(req).await?;
308
309 let status = resp.status();
310 let content_type = resp
311 .headers()
312 .get("content-type")
313 .and_then(|v| v.to_str().ok())
314 .unwrap_or("application/octet-stream");
315 let content_type = super::ContentType::from(content_type);
316
317 if !status.is_client_error() && !status.is_server_error() {
318 let content = resp.text().await?;
319 match content_type {
320 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
321 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::feeds_2021_06_30::FeedDocument`"))),
322 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::feeds_2021_06_30::FeedDocument`")))),
323 }
324 } else {
325 let content = resp.text().await?;
326 let entity: Option<GetFeedDocumentError> = serde_json::from_str(&content).ok();
327 Err(Error::ResponseError(ResponseContent {
328 status,
329 content,
330 entity,
331 }))
332 }
333}
334
335pub async fn get_feeds(
337 configuration: &configuration::Configuration,
338 feed_types: Option<Vec<String>>,
339 marketplace_ids: Option<Vec<String>>,
340 page_size: Option<i32>,
341 processing_statuses: Option<Vec<String>>,
342 created_since: Option<String>,
343 created_until: Option<String>,
344 next_token: Option<&str>,
345) -> Result<models::feeds_2021_06_30::GetFeedsResponse, Error<GetFeedsError>> {
346 let p_feed_types = feed_types;
348 let p_marketplace_ids = marketplace_ids;
349 let p_page_size = page_size;
350 let p_processing_statuses = processing_statuses;
351 let p_created_since = created_since;
352 let p_created_until = created_until;
353 let p_next_token = next_token;
354
355 let uri_str = format!("{}/feeds/2021-06-30/feeds", configuration.base_path);
356 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
357
358 if let Some(ref param_value) = p_feed_types {
359 req_builder = match "csv" {
360 "multi" => req_builder.query(
361 ¶m_value
362 .into_iter()
363 .map(|p| ("feedTypes".to_owned(), p.to_string()))
364 .collect::<Vec<(std::string::String, std::string::String)>>(),
365 ),
366 _ => req_builder.query(&[(
367 "feedTypes",
368 ¶m_value
369 .into_iter()
370 .map(|p| p.to_string())
371 .collect::<Vec<String>>()
372 .join(",")
373 .to_string(),
374 )]),
375 };
376 }
377 if let Some(ref param_value) = p_marketplace_ids {
378 req_builder = match "csv" {
379 "multi" => req_builder.query(
380 ¶m_value
381 .into_iter()
382 .map(|p| ("marketplaceIds".to_owned(), p.to_string()))
383 .collect::<Vec<(std::string::String, std::string::String)>>(),
384 ),
385 _ => req_builder.query(&[(
386 "marketplaceIds",
387 ¶m_value
388 .into_iter()
389 .map(|p| p.to_string())
390 .collect::<Vec<String>>()
391 .join(",")
392 .to_string(),
393 )]),
394 };
395 }
396 if let Some(ref param_value) = p_page_size {
397 req_builder = req_builder.query(&[("pageSize", ¶m_value.to_string())]);
398 }
399 if let Some(ref param_value) = p_processing_statuses {
400 req_builder = match "csv" {
401 "multi" => req_builder.query(
402 ¶m_value
403 .into_iter()
404 .map(|p| ("processingStatuses".to_owned(), p.to_string()))
405 .collect::<Vec<(std::string::String, std::string::String)>>(),
406 ),
407 _ => req_builder.query(&[(
408 "processingStatuses",
409 ¶m_value
410 .into_iter()
411 .map(|p| p.to_string())
412 .collect::<Vec<String>>()
413 .join(",")
414 .to_string(),
415 )]),
416 };
417 }
418 if let Some(ref param_value) = p_created_since {
419 req_builder = req_builder.query(&[("createdSince", ¶m_value.to_string())]);
420 }
421 if let Some(ref param_value) = p_created_until {
422 req_builder = req_builder.query(&[("createdUntil", ¶m_value.to_string())]);
423 }
424 if let Some(ref param_value) = p_next_token {
425 req_builder = req_builder.query(&[("nextToken", ¶m_value.to_string())]);
426 }
427 if let Some(ref user_agent) = configuration.user_agent {
428 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
429 }
430
431 let req = req_builder.build()?;
432 let resp = configuration.client.execute(req).await?;
433
434 let status = resp.status();
435 let content_type = resp
436 .headers()
437 .get("content-type")
438 .and_then(|v| v.to_str().ok())
439 .unwrap_or("application/octet-stream");
440 let content_type = super::ContentType::from(content_type);
441
442 if !status.is_client_error() && !status.is_server_error() {
443 let content = resp.text().await?;
444 match content_type {
445 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
446 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::feeds_2021_06_30::GetFeedsResponse`"))),
447 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::feeds_2021_06_30::GetFeedsResponse`")))),
448 }
449 } else {
450 let content = resp.text().await?;
451 let entity: Option<GetFeedsError> = serde_json::from_str(&content).ok();
452 Err(Error::ResponseError(ResponseContent {
453 status,
454 content,
455 entity,
456 }))
457 }
458}