amazon_spapi/apis/
product_pricing_2022_05_01.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 GetCompetitiveSummaryError {
22 Status400(models::product_pricing_2022_05_01::Errors),
23 Status403(models::product_pricing_2022_05_01::Errors),
24 Status404(models::product_pricing_2022_05_01::Errors),
25 Status429(models::product_pricing_2022_05_01::Errors),
26 Status500(models::product_pricing_2022_05_01::Errors),
27 Status503(models::product_pricing_2022_05_01::Errors),
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum GetFeaturedOfferExpectedPriceBatchError {
35 Status400(models::product_pricing_2022_05_01::Errors),
36 Status401(models::product_pricing_2022_05_01::Errors),
37 Status403(models::product_pricing_2022_05_01::Errors),
38 Status404(models::product_pricing_2022_05_01::Errors),
39 Status429(models::product_pricing_2022_05_01::Errors),
40 Status500(models::product_pricing_2022_05_01::Errors),
41 Status503(models::product_pricing_2022_05_01::Errors),
42 UnknownValue(serde_json::Value),
43}
44
45
46pub async fn get_competitive_summary(configuration: &configuration::Configuration, requests: models::product_pricing_2022_05_01::CompetitiveSummaryBatchRequest) -> Result<models::product_pricing_2022_05_01::CompetitiveSummaryBatchResponse, Error<GetCompetitiveSummaryError>> {
48 let p_requests = requests;
50
51 let uri_str = format!("{}/batches/products/pricing/2022-05-01/items/competitiveSummary", configuration.base_path);
52 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
53
54 if let Some(ref user_agent) = configuration.user_agent {
55 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
56 }
57 req_builder = req_builder.json(&p_requests);
58
59 let req = req_builder.build()?;
60 let resp = configuration.client.execute(req).await?;
61
62 let status = resp.status();
63 let content_type = resp
64 .headers()
65 .get("content-type")
66 .and_then(|v| v.to_str().ok())
67 .unwrap_or("application/octet-stream");
68 let content_type = super::ContentType::from(content_type);
69
70 if !status.is_client_error() && !status.is_server_error() {
71 let content = resp.text().await?;
72 match content_type {
73 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
74 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::product_pricing_2022_05_01::CompetitiveSummaryBatchResponse`"))),
75 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::product_pricing_2022_05_01::CompetitiveSummaryBatchResponse`")))),
76 }
77 } else {
78 let content = resp.text().await?;
79 let entity: Option<GetCompetitiveSummaryError> = serde_json::from_str(&content).ok();
80 Err(Error::ResponseError(ResponseContent { status, content, entity }))
81 }
82}
83
84pub async fn get_featured_offer_expected_price_batch(configuration: &configuration::Configuration, get_featured_offer_expected_price_batch_request_body: models::product_pricing_2022_05_01::GetFeaturedOfferExpectedPriceBatchRequest) -> Result<models::product_pricing_2022_05_01::GetFeaturedOfferExpectedPriceBatchResponse, Error<GetFeaturedOfferExpectedPriceBatchError>> {
86 let p_get_featured_offer_expected_price_batch_request_body = get_featured_offer_expected_price_batch_request_body;
88
89 let uri_str = format!("{}/batches/products/pricing/2022-05-01/offer/featuredOfferExpectedPrice", configuration.base_path);
90 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
91
92 if let Some(ref user_agent) = configuration.user_agent {
93 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
94 }
95 req_builder = req_builder.json(&p_get_featured_offer_expected_price_batch_request_body);
96
97 let req = req_builder.build()?;
98 let resp = configuration.client.execute(req).await?;
99
100 let status = resp.status();
101 let content_type = resp
102 .headers()
103 .get("content-type")
104 .and_then(|v| v.to_str().ok())
105 .unwrap_or("application/octet-stream");
106 let content_type = super::ContentType::from(content_type);
107
108 if !status.is_client_error() && !status.is_server_error() {
109 let content = resp.text().await?;
110 match content_type {
111 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
112 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::product_pricing_2022_05_01::GetFeaturedOfferExpectedPriceBatchResponse`"))),
113 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::product_pricing_2022_05_01::GetFeaturedOfferExpectedPriceBatchResponse`")))),
114 }
115 } else {
116 let content = resp.text().await?;
117 let entity: Option<GetFeaturedOfferExpectedPriceBatchError> = serde_json::from_str(&content).ok();
118 Err(Error::ResponseError(ResponseContent { status, content, entity }))
119 }
120}
121