/*
* Selling Partner API for Catalog Items
*
* Use the Selling Partner API for Catalog Items to retrieve information about items in the Amazon catalog. For more information, refer to the [Catalog Items API Use Case Guide](https://developer-docs.amazon.com/sp-api/docs/:catalog-items-api-v2022-04-01-use-case-guide).
*
* The version of the OpenAPI document: 2022-04-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_2022_04_01::ErrorList),
Status403(models::catalog_items_2022_04_01::ErrorList),
Status404(models::catalog_items_2022_04_01::ErrorList),
Status413(models::catalog_items_2022_04_01::ErrorList),
Status415(models::catalog_items_2022_04_01::ErrorList),
Status429(models::catalog_items_2022_04_01::ErrorList),
Status500(models::catalog_items_2022_04_01::ErrorList),
Status503(models::catalog_items_2022_04_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_2022_04_01::ErrorList),
Status403(models::catalog_items_2022_04_01::ErrorList),
Status404(models::catalog_items_2022_04_01::ErrorList),
Status413(models::catalog_items_2022_04_01::ErrorList),
Status415(models::catalog_items_2022_04_01::ErrorList),
Status429(models::catalog_items_2022_04_01::ErrorList),
Status500(models::catalog_items_2022_04_01::ErrorList),
Status503(models::catalog_items_2022_04_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 contains the usage plan rate limits for the operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput might have higher rate and burst values than those shown here. For more information, refer to [Usage Plans and Rate Limits](https://developer-docs.amazon.com/sp-api/docs/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_2022_04_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/2022-04-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_2022_04_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_2022_04_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 a list of Amazon catalog items and item-related information. You can search by identifier or by keywords. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 2 | 2 | The `x-amzn-RateLimit-Limit` response header contains the usage plan rate limits for the operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput might have higher rate and burst values than those shown here. For more information, refer to [Usage Plans and Rate Limits](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn search_catalog_items(configuration: &configuration::Configuration, marketplace_ids: Vec<String>, identifiers: Option<Vec<String>>, identifiers_type: Option<&str>, included_data: Option<Vec<String>>, locale: Option<&str>, seller_id: Option<&str>, keywords: 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>) -> Result<models::catalog_items_2022_04_01::ItemSearchResults, Error<SearchCatalogItemsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_marketplace_ids = marketplace_ids;
let p_identifiers = identifiers;
let p_identifiers_type = identifiers_type;
let p_included_data = included_data;
let p_locale = locale;
let p_seller_id = seller_id;
let p_keywords = keywords;
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 uri_str = format!("{}/catalog/2022-04-01/items", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_identifiers {
req_builder = match "csv" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("identifiers".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("identifiers", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_identifiers_type {
req_builder = req_builder.query(&[("identifiersType", ¶m_value.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_locale {
req_builder = req_builder.query(&[("locale", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_seller_id {
req_builder = req_builder.query(&[("sellerId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_keywords {
req_builder = match "csv" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("keywords".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("keywords", ¶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 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_2022_04_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_2022_04_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 }))
}
}