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 GetDefinitionsProductTypeError {
22 Status400(models::definitions_product_types_2020_09_01::ErrorList),
23 Status403(models::definitions_product_types_2020_09_01::ErrorList),
24 Status404(models::definitions_product_types_2020_09_01::ErrorList),
25 Status413(models::definitions_product_types_2020_09_01::ErrorList),
26 Status415(models::definitions_product_types_2020_09_01::ErrorList),
27 Status429(models::definitions_product_types_2020_09_01::ErrorList),
28 Status500(models::definitions_product_types_2020_09_01::ErrorList),
29 Status503(models::definitions_product_types_2020_09_01::ErrorList),
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum SearchDefinitionsProductTypesError {
37 Status400(models::definitions_product_types_2020_09_01::ErrorList),
38 Status403(models::definitions_product_types_2020_09_01::ErrorList),
39 Status404(models::definitions_product_types_2020_09_01::ErrorList),
40 Status413(models::definitions_product_types_2020_09_01::ErrorList),
41 Status415(models::definitions_product_types_2020_09_01::ErrorList),
42 Status429(models::definitions_product_types_2020_09_01::ErrorList),
43 Status500(models::definitions_product_types_2020_09_01::ErrorList),
44 Status503(models::definitions_product_types_2020_09_01::ErrorList),
45 UnknownValue(serde_json::Value),
46}
47
48
49pub async fn get_definitions_product_type(configuration: &configuration::Configuration, product_type: &str, marketplace_ids: Vec<String>, seller_id: Option<&str>, product_type_version: Option<&str>, requirements: Option<&str>, requirements_enforced: Option<&str>, locale: Option<&str>) -> Result<models::definitions_product_types_2020_09_01::ProductTypeDefinition, Error<GetDefinitionsProductTypeError>> {
51 let p_product_type = product_type;
53 let p_marketplace_ids = marketplace_ids;
54 let p_seller_id = seller_id;
55 let p_product_type_version = product_type_version;
56 let p_requirements = requirements;
57 let p_requirements_enforced = requirements_enforced;
58 let p_locale = locale;
59
60 let uri_str = format!("{}/definitions/2020-09-01/productTypes/{productType}", configuration.base_path, productType=crate::apis::urlencode(p_product_type));
61 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
62
63 if let Some(ref param_value) = p_seller_id {
64 req_builder = req_builder.query(&[("sellerId", ¶m_value.to_string())]);
65 }
66 req_builder = match "csv" {
67 "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)>>()),
68 _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
69 };
70 if let Some(ref param_value) = p_product_type_version {
71 req_builder = req_builder.query(&[("productTypeVersion", ¶m_value.to_string())]);
72 }
73 if let Some(ref param_value) = p_requirements {
74 req_builder = req_builder.query(&[("requirements", ¶m_value.to_string())]);
75 }
76 if let Some(ref param_value) = p_requirements_enforced {
77 req_builder = req_builder.query(&[("requirementsEnforced", ¶m_value.to_string())]);
78 }
79 if let Some(ref param_value) = p_locale {
80 req_builder = req_builder.query(&[("locale", ¶m_value.to_string())]);
81 }
82 if let Some(ref user_agent) = configuration.user_agent {
83 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
84 }
85
86 let req = req_builder.build()?;
87 let resp = configuration.client.execute(req).await?;
88
89 let status = resp.status();
90 let content_type = resp
91 .headers()
92 .get("content-type")
93 .and_then(|v| v.to_str().ok())
94 .unwrap_or("application/octet-stream");
95 let content_type = super::ContentType::from(content_type);
96
97 if !status.is_client_error() && !status.is_server_error() {
98 let content = resp.text().await?;
99 match content_type {
100 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
101 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::definitions_product_types_2020_09_01::ProductTypeDefinition`"))),
102 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::definitions_product_types_2020_09_01::ProductTypeDefinition`")))),
103 }
104 } else {
105 let content = resp.text().await?;
106 let entity: Option<GetDefinitionsProductTypeError> = serde_json::from_str(&content).ok();
107 Err(Error::ResponseError(ResponseContent { status, content, entity }))
108 }
109}
110
111pub async fn search_definitions_product_types(configuration: &configuration::Configuration, marketplace_ids: Vec<String>, keywords: Option<Vec<String>>, item_name: Option<&str>, locale: Option<&str>, search_locale: Option<&str>) -> Result<models::definitions_product_types_2020_09_01::ProductTypeList, Error<SearchDefinitionsProductTypesError>> {
113 let p_marketplace_ids = marketplace_ids;
115 let p_keywords = keywords;
116 let p_item_name = item_name;
117 let p_locale = locale;
118 let p_search_locale = search_locale;
119
120 let uri_str = format!("{}/definitions/2020-09-01/productTypes", configuration.base_path);
121 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
122
123 if let Some(ref param_value) = p_keywords {
124 req_builder = match "csv" {
125 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("keywords".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
126 _ => req_builder.query(&[("keywords", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
127 };
128 }
129 req_builder = match "csv" {
130 "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)>>()),
131 _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
132 };
133 if let Some(ref param_value) = p_item_name {
134 req_builder = req_builder.query(&[("itemName", ¶m_value.to_string())]);
135 }
136 if let Some(ref param_value) = p_locale {
137 req_builder = req_builder.query(&[("locale", ¶m_value.to_string())]);
138 }
139 if let Some(ref param_value) = p_search_locale {
140 req_builder = req_builder.query(&[("searchLocale", ¶m_value.to_string())]);
141 }
142 if let Some(ref user_agent) = configuration.user_agent {
143 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
144 }
145
146 let req = req_builder.build()?;
147 let resp = configuration.client.execute(req).await?;
148
149 let status = resp.status();
150 let content_type = resp
151 .headers()
152 .get("content-type")
153 .and_then(|v| v.to_str().ok())
154 .unwrap_or("application/octet-stream");
155 let content_type = super::ContentType::from(content_type);
156
157 if !status.is_client_error() && !status.is_server_error() {
158 let content = resp.text().await?;
159 match content_type {
160 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
161 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::definitions_product_types_2020_09_01::ProductTypeList`"))),
162 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::definitions_product_types_2020_09_01::ProductTypeList`")))),
163 }
164 } else {
165 let content = resp.text().await?;
166 let entity: Option<SearchDefinitionsProductTypesError> = serde_json::from_str(&content).ok();
167 Err(Error::ResponseError(ResponseContent { status, content, entity }))
168 }
169}
170