amazon-spapi 2.0.3

A Rust client library for Amazon Selling Partner API (SP-API)
Documentation
/*
 * Selling Partner API for Pricing
 *
 * The Selling Partner API for Pricing helps you programmatically retrieve product pricing and offer pricing information for Amazon Marketplace products.  For more information, refer to the [Product Pricing v2022-05-01 Use Case Guide](https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-use-case-guide).
 *
 * The version of the OpenAPI document: 2022-05-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_competitive_summary`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCompetitiveSummaryError {
    Status400(models::product_pricing_2022_05_01::Errors),
    Status403(models::product_pricing_2022_05_01::Errors),
    Status404(models::product_pricing_2022_05_01::Errors),
    Status429(models::product_pricing_2022_05_01::Errors),
    Status500(models::product_pricing_2022_05_01::Errors),
    Status503(models::product_pricing_2022_05_01::Errors),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_featured_offer_expected_price_batch`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFeaturedOfferExpectedPriceBatchError {
    Status400(models::product_pricing_2022_05_01::Errors),
    Status401(models::product_pricing_2022_05_01::Errors),
    Status403(models::product_pricing_2022_05_01::Errors),
    Status404(models::product_pricing_2022_05_01::Errors),
    Status429(models::product_pricing_2022_05_01::Errors),
    Status500(models::product_pricing_2022_05_01::Errors),
    Status503(models::product_pricing_2022_05_01::Errors),
    UnknownValue(serde_json::Value),
}


/// Returns the competitive summary response, including featured buying options for the ASIN and `marketplaceId` combination.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.033 | 1 |  The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that are applied to the requested operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may receive 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) in the Selling Partner API.
pub 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>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_requests = requests;

    let uri_str = format!("{}/batches/products/pricing/2022-05-01/items/competitiveSummary", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    req_builder = req_builder.json(&p_requests);

    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::product_pricing_2022_05_01::CompetitiveSummaryBatchResponse`"))),
            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`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetCompetitiveSummaryError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Returns the set of responses that correspond to the batched list of up to 40 requests defined in the request body. The response for each successful (HTTP status code 200) request in the set includes the computed listing price at or below which a seller can expect to become the featured offer (before applicable promotions). This is called the featured offer expected price (FOEP). Featured offer is not guaranteed because competing offers might change. Other offers might be featured based on factors such as fulfillment capabilities to a specific customer. The response to an unsuccessful request includes the available error text.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.033 | 1 |  The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that are applied to the requested operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may receive 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) in the Selling Partner API.
pub 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>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_get_featured_offer_expected_price_batch_request_body = get_featured_offer_expected_price_batch_request_body;

    let uri_str = format!("{}/batches/products/pricing/2022-05-01/offer/featuredOfferExpectedPrice", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    req_builder = req_builder.json(&p_get_featured_offer_expected_price_batch_request_body);

    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::product_pricing_2022_05_01::GetFeaturedOfferExpectedPriceBatchResponse`"))),
            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`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetFeaturedOfferExpectedPriceBatchError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}