/*
* Selling Partner API for Catalog Items
*
* The Selling Partner API for Catalog Items provides programmatic access to information about items in the Amazon catalog. For more information, see the [Catalog Items API Use Case Guide](doc:catalog-items-api-v2020-12-01-use-case-guide).
*
* The version of the OpenAPI document: 2020-12-01
*
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for typed errors of method [`get_catalog_item`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCatalogItemError {
Status400(models::catalog_items_2020_12_01::ErrorList),
Status403(models::catalog_items_2020_12_01::ErrorList),
Status404(models::catalog_items_2020_12_01::ErrorList),
Status413(models::catalog_items_2020_12_01::ErrorList),
Status415(models::catalog_items_2020_12_01::ErrorList),
Status429(models::catalog_items_2020_12_01::ErrorList),
Status500(models::catalog_items_2020_12_01::ErrorList),
Status503(models::catalog_items_2020_12_01::ErrorList),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`search_catalog_items`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchCatalogItemsError {
Status400(models::catalog_items_2020_12_01::ErrorList),
Status403(models::catalog_items_2020_12_01::ErrorList),
Status404(models::catalog_items_2020_12_01::ErrorList),
Status413(models::catalog_items_2020_12_01::ErrorList),
Status415(models::catalog_items_2020_12_01::ErrorList),
Status429(models::catalog_items_2020_12_01::ErrorList),
Status500(models::catalog_items_2020_12_01::ErrorList),
Status503(models::catalog_items_2020_12_01::ErrorList),
UnknownValue(serde_json::Value),
}
/// Retrieves details for an item in the Amazon catalog. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 2 | 2 | The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
pub 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>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_asin = asin;
let p_marketplace_ids = marketplace_ids;
let p_included_data = included_data;
let p_locale = locale;
let uri_str = format!("{}/catalog/2020-12-01/items/{asin}", configuration.base_path, asin=crate::apis::urlencode(p_asin));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = match "csv" {
"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)>>()),
_ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
if let Some(ref param_value) = p_included_data {
req_builder = match "csv" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("includedData".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("includedData", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_locale {
req_builder = req_builder.query(&[("locale", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
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`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetCatalogItemError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Search for and return a list of Amazon catalog items and associated information. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 2 | 2 | The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
pub 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>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_keywords = keywords;
let p_marketplace_ids = marketplace_ids;
let p_included_data = included_data;
let p_brand_names = brand_names;
let p_classification_ids = classification_ids;
let p_page_size = page_size;
let p_page_token = page_token;
let p_keywords_locale = keywords_locale;
let p_locale = locale;
let uri_str = format!("{}/catalog/2020-12-01/items", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = match "csv" {
"multi" => req_builder.query(&p_keywords.into_iter().map(|p| ("keywords".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("keywords", &p_keywords.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
req_builder = match "csv" {
"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)>>()),
_ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
if let Some(ref param_value) = p_included_data {
req_builder = match "csv" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("includedData".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("includedData", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_brand_names {
req_builder = match "csv" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("brandNames".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("brandNames", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_classification_ids {
req_builder = match "csv" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("classificationIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("classificationIds", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_page_size {
req_builder = req_builder.query(&[("pageSize", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_page_token {
req_builder = req_builder.query(&[("pageToken", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_keywords_locale {
req_builder = req_builder.query(&[("keywordsLocale", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_locale {
req_builder = req_builder.query(&[("locale", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
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`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SearchCatalogItemsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}