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 GetCatalogItemError {
22 Status400(models::catalog_items_2020_12_01::ErrorList),
23 Status403(models::catalog_items_2020_12_01::ErrorList),
24 Status404(models::catalog_items_2020_12_01::ErrorList),
25 Status413(models::catalog_items_2020_12_01::ErrorList),
26 Status415(models::catalog_items_2020_12_01::ErrorList),
27 Status429(models::catalog_items_2020_12_01::ErrorList),
28 Status500(models::catalog_items_2020_12_01::ErrorList),
29 Status503(models::catalog_items_2020_12_01::ErrorList),
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum SearchCatalogItemsError {
37 Status400(models::catalog_items_2020_12_01::ErrorList),
38 Status403(models::catalog_items_2020_12_01::ErrorList),
39 Status404(models::catalog_items_2020_12_01::ErrorList),
40 Status413(models::catalog_items_2020_12_01::ErrorList),
41 Status415(models::catalog_items_2020_12_01::ErrorList),
42 Status429(models::catalog_items_2020_12_01::ErrorList),
43 Status500(models::catalog_items_2020_12_01::ErrorList),
44 Status503(models::catalog_items_2020_12_01::ErrorList),
45 UnknownValue(serde_json::Value),
46}
47
48
49pub async fn get_catalog_item(configuration: &configuration::Configuration, asin: &str, marketplace_ids: Vec<String>, included_data: Option<Vec<String>>, locale: Option<&str>) -> Result<models::catalog_items_2020_12_01::Item, Error<GetCatalogItemError>> {
51 let p_asin = asin;
53 let p_marketplace_ids = marketplace_ids;
54 let p_included_data = included_data;
55 let p_locale = locale;
56
57 let uri_str = format!("{}/catalog/2020-12-01/items/{asin}", configuration.base_path, asin=crate::apis::urlencode(p_asin));
58 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
59
60 req_builder = match "csv" {
61 "multi" => req_builder.query(&p_marketplace_ids.into_iter().map(|p| ("marketplaceIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
62 _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
63 };
64 if let Some(ref param_value) = p_included_data {
65 req_builder = match "csv" {
66 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("includedData".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
67 _ => req_builder.query(&[("includedData", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
68 };
69 }
70 if let Some(ref param_value) = p_locale {
71 req_builder = req_builder.query(&[("locale", ¶m_value.to_string())]);
72 }
73 if let Some(ref user_agent) = configuration.user_agent {
74 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
75 }
76
77 let req = req_builder.build()?;
78 let resp = configuration.client.execute(req).await?;
79
80 let status = resp.status();
81 let content_type = resp
82 .headers()
83 .get("content-type")
84 .and_then(|v| v.to_str().ok())
85 .unwrap_or("application/octet-stream");
86 let content_type = super::ContentType::from(content_type);
87
88 if !status.is_client_error() && !status.is_server_error() {
89 let content = resp.text().await?;
90 match content_type {
91 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
92 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::catalog_items_2020_12_01::Item`"))),
93 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::catalog_items_2020_12_01::Item`")))),
94 }
95 } else {
96 let content = resp.text().await?;
97 let entity: Option<GetCatalogItemError> = serde_json::from_str(&content).ok();
98 Err(Error::ResponseError(ResponseContent { status, content, entity }))
99 }
100}
101
102pub async fn search_catalog_items(configuration: &configuration::Configuration, keywords: Vec<String>, marketplace_ids: Vec<String>, included_data: Option<Vec<String>>, brand_names: Option<Vec<String>>, classification_ids: Option<Vec<String>>, page_size: Option<i32>, page_token: Option<&str>, keywords_locale: Option<&str>, locale: Option<&str>) -> Result<models::catalog_items_2020_12_01::ItemSearchResults, Error<SearchCatalogItemsError>> {
104 let p_keywords = keywords;
106 let p_marketplace_ids = marketplace_ids;
107 let p_included_data = included_data;
108 let p_brand_names = brand_names;
109 let p_classification_ids = classification_ids;
110 let p_page_size = page_size;
111 let p_page_token = page_token;
112 let p_keywords_locale = keywords_locale;
113 let p_locale = locale;
114
115 let uri_str = format!("{}/catalog/2020-12-01/items", configuration.base_path);
116 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
117
118 req_builder = match "csv" {
119 "multi" => req_builder.query(&p_keywords.into_iter().map(|p| ("keywords".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
120 _ => req_builder.query(&[("keywords", &p_keywords.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
121 };
122 req_builder = match "csv" {
123 "multi" => req_builder.query(&p_marketplace_ids.into_iter().map(|p| ("marketplaceIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
124 _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
125 };
126 if let Some(ref param_value) = p_included_data {
127 req_builder = match "csv" {
128 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("includedData".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
129 _ => req_builder.query(&[("includedData", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
130 };
131 }
132 if let Some(ref param_value) = p_brand_names {
133 req_builder = match "csv" {
134 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("brandNames".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
135 _ => req_builder.query(&[("brandNames", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
136 };
137 }
138 if let Some(ref param_value) = p_classification_ids {
139 req_builder = match "csv" {
140 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("classificationIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
141 _ => req_builder.query(&[("classificationIds", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
142 };
143 }
144 if let Some(ref param_value) = p_page_size {
145 req_builder = req_builder.query(&[("pageSize", ¶m_value.to_string())]);
146 }
147 if let Some(ref param_value) = p_page_token {
148 req_builder = req_builder.query(&[("pageToken", ¶m_value.to_string())]);
149 }
150 if let Some(ref param_value) = p_keywords_locale {
151 req_builder = req_builder.query(&[("keywordsLocale", ¶m_value.to_string())]);
152 }
153 if let Some(ref param_value) = p_locale {
154 req_builder = req_builder.query(&[("locale", ¶m_value.to_string())]);
155 }
156 if let Some(ref user_agent) = configuration.user_agent {
157 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
158 }
159
160 let req = req_builder.build()?;
161 let resp = configuration.client.execute(req).await?;
162
163 let status = resp.status();
164 let content_type = resp
165 .headers()
166 .get("content-type")
167 .and_then(|v| v.to_str().ok())
168 .unwrap_or("application/octet-stream");
169 let content_type = super::ContentType::from(content_type);
170
171 if !status.is_client_error() && !status.is_server_error() {
172 let content = resp.text().await?;
173 match content_type {
174 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
175 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::catalog_items_2020_12_01::ItemSearchResults`"))),
176 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::catalog_items_2020_12_01::ItemSearchResults`")))),
177 }
178 } else {
179 let content = resp.text().await?;
180 let entity: Option<SearchCatalogItemsError> = serde_json::from_str(&content).ok();
181 Err(Error::ResponseError(ResponseContent { status, content, entity }))
182 }
183}
184