amazon_spapi/apis/
offers_api.rs1use 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 ListOfferMetricsError {
22 Status400(models::replenishment_2022_11_07::ErrorList),
23 Status401(models::replenishment_2022_11_07::ErrorList),
24 Status403(models::replenishment_2022_11_07::ErrorList),
25 Status404(models::replenishment_2022_11_07::ErrorList),
26 Status413(models::replenishment_2022_11_07::ErrorList),
27 Status415(models::replenishment_2022_11_07::ErrorList),
28 Status429(models::replenishment_2022_11_07::ErrorList),
29 Status500(models::replenishment_2022_11_07::ErrorList),
30 Status503(models::replenishment_2022_11_07::ErrorList),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ListOffersError {
38 Status400(models::replenishment_2022_11_07::ErrorList),
39 Status401(models::replenishment_2022_11_07::ErrorList),
40 Status403(models::replenishment_2022_11_07::ErrorList),
41 Status404(models::replenishment_2022_11_07::ErrorList),
42 Status413(models::replenishment_2022_11_07::ErrorList),
43 Status415(models::replenishment_2022_11_07::ErrorList),
44 Status429(models::replenishment_2022_11_07::ErrorList),
45 Status500(models::replenishment_2022_11_07::ErrorList),
46 Status503(models::replenishment_2022_11_07::ErrorList),
47 UnknownValue(serde_json::Value),
48}
49
50
51pub async fn list_offer_metrics(configuration: &configuration::Configuration, body: Option<models::replenishment_2022_11_07::ListOfferMetricsRequest>) -> Result<models::replenishment_2022_11_07::ListOfferMetricsResponse, Error<ListOfferMetricsError>> {
53 let p_body = body;
55
56 let uri_str = format!("{}/replenishment/2022-11-07/offers/metrics/search", configuration.base_path);
57 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
58
59 if let Some(ref user_agent) = configuration.user_agent {
60 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
61 }
62 req_builder = req_builder.json(&p_body);
63
64 let req = req_builder.build()?;
65 let resp = configuration.client.execute(req).await?;
66
67 let status = resp.status();
68 let content_type = resp
69 .headers()
70 .get("content-type")
71 .and_then(|v| v.to_str().ok())
72 .unwrap_or("application/octet-stream");
73 let content_type = super::ContentType::from(content_type);
74
75 if !status.is_client_error() && !status.is_server_error() {
76 let content = resp.text().await?;
77 match content_type {
78 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
79 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::replenishment_2022_11_07::ListOfferMetricsResponse`"))),
80 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::replenishment_2022_11_07::ListOfferMetricsResponse`")))),
81 }
82 } else {
83 let content = resp.text().await?;
84 let entity: Option<ListOfferMetricsError> = serde_json::from_str(&content).ok();
85 Err(Error::ResponseError(ResponseContent { status, content, entity }))
86 }
87}
88
89pub async fn list_offers(configuration: &configuration::Configuration, body: Option<models::replenishment_2022_11_07::ListOffersRequest>) -> Result<models::replenishment_2022_11_07::ListOffersResponse, Error<ListOffersError>> {
91 let p_body = body;
93
94 let uri_str = format!("{}/replenishment/2022-11-07/offers/search", configuration.base_path);
95 let mut req_builder = configuration.client.request(reqwest::Method::POST, &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 req_builder = req_builder.json(&p_body);
101
102 let req = req_builder.build()?;
103 let resp = configuration.client.execute(req).await?;
104
105 let status = resp.status();
106 let content_type = resp
107 .headers()
108 .get("content-type")
109 .and_then(|v| v.to_str().ok())
110 .unwrap_or("application/octet-stream");
111 let content_type = super::ContentType::from(content_type);
112
113 if !status.is_client_error() && !status.is_server_error() {
114 let content = resp.text().await?;
115 match content_type {
116 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
117 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::replenishment_2022_11_07::ListOffersResponse`"))),
118 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::replenishment_2022_11_07::ListOffersResponse`")))),
119 }
120 } else {
121 let content = resp.text().await?;
122 let entity: Option<ListOffersError> = serde_json::from_str(&content).ok();
123 Err(Error::ResponseError(ResponseContent { status, content, entity }))
124 }
125}
126