amazon-spapi 2.0.3

A Rust client library for Amazon Selling Partner API (SP-API)
Documentation
/*
 * The Selling Partner API for third party application integrations.
 *
 * With the AppIntegrations API v2024-04-01, you can send notifications to Amazon Selling Partners and display the notifications in Seller Central.
 *
 * The version of the OpenAPI document: 2024-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 [`create_notification`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateNotificationError {
    Status400(models::app_integrations_2024_04_01::ErrorList),
    Status401(models::app_integrations_2024_04_01::ErrorList),
    Status403(models::app_integrations_2024_04_01::ErrorList),
    Status404(models::app_integrations_2024_04_01::ErrorList),
    Status413(models::app_integrations_2024_04_01::ErrorList),
    Status415(models::app_integrations_2024_04_01::ErrorList),
    Status429(models::app_integrations_2024_04_01::ErrorList),
    Status500(models::app_integrations_2024_04_01::ErrorList),
    Status503(models::app_integrations_2024_04_01::ErrorList),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_notifications`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteNotificationsError {
    Status400(models::app_integrations_2024_04_01::ErrorList),
    Status413(models::app_integrations_2024_04_01::ErrorList),
    Status403(models::app_integrations_2024_04_01::ErrorList),
    Status404(models::app_integrations_2024_04_01::ErrorList),
    Status415(models::app_integrations_2024_04_01::ErrorList),
    Status429(models::app_integrations_2024_04_01::ErrorList),
    Status500(models::app_integrations_2024_04_01::ErrorList),
    Status503(models::app_integrations_2024_04_01::ErrorList),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`record_action_feedback`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RecordActionFeedbackError {
    Status400(models::app_integrations_2024_04_01::ErrorList),
    Status413(models::app_integrations_2024_04_01::ErrorList),
    Status401(models::app_integrations_2024_04_01::ErrorList),
    Status403(models::app_integrations_2024_04_01::ErrorList),
    Status404(models::app_integrations_2024_04_01::ErrorList),
    Status415(models::app_integrations_2024_04_01::ErrorList),
    Status429(models::app_integrations_2024_04_01::ErrorList),
    Status500(models::app_integrations_2024_04_01::ErrorList),
    Status503(models::app_integrations_2024_04_01::ErrorList),
    UnknownValue(serde_json::Value),
}


/// Create a notification for sellers in Seller Central.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 |  The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The preceding table indicates the default rate and burst values for this operation. Sellers whose business demands require higher throughput may have higher rate and burst values than those shown here. For more information, refer to [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn create_notification(configuration: &configuration::Configuration, body: models::app_integrations_2024_04_01::CreateNotificationRequest) -> Result<models::app_integrations_2024_04_01::CreateNotificationResponse, Error<CreateNotificationError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body = body;

    let uri_str = format!("{}/appIntegrations/2024-04-01/notifications", 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_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::app_integrations_2024_04_01::CreateNotificationResponse`"))),
            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::app_integrations_2024_04_01::CreateNotificationResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CreateNotificationError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Remove your application's notifications from the Appstore notifications dashboard.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 |  The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The preceding table indicates the default rate and burst values for this operation. Sellers whose business demands require higher throughput may have higher rate and burst values than those shown here. For more information, refer to [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn delete_notifications(configuration: &configuration::Configuration, body: models::app_integrations_2024_04_01::DeleteNotificationsRequest) -> Result<(), Error<DeleteNotificationsError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body = body;

    let uri_str = format!("{}/appIntegrations/2024-04-01/notifications/deletion", 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_body);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();

    if !status.is_client_error() && !status.is_server_error() {
        Ok(())
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteNotificationsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Records the seller's response to a notification.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 |  The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The preceding table indicates the default rate and burst values for this operation. Sellers whose business demands require higher throughput may have higher rate and burst values than those shown here. For more information, refer to [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn record_action_feedback(configuration: &configuration::Configuration, notification_id: &str, body: models::app_integrations_2024_04_01::RecordActionFeedbackRequest) -> Result<(), Error<RecordActionFeedbackError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_notification_id = notification_id;
    let p_body = body;

    let uri_str = format!("{}/appIntegrations/2024-04-01/notifications/{notificationId}/feedback", configuration.base_path, notificationId=crate::apis::urlencode(p_notification_id));
    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_body);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();

    if !status.is_client_error() && !status.is_server_error() {
        Ok(())
    } else {
        let content = resp.text().await?;
        let entity: Option<RecordActionFeedbackError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}