amazon-spapi 2.0.3

A Rust client library for Amazon Selling Partner API (SP-API)
Documentation
/*
 * Selling Partner API for Supply Sources
 *
 * Manage configurations and capabilities of seller supply sources.
 *
 * The version of the OpenAPI document: 2020-07-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 [`archive_supply_source`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ArchiveSupplySourceError {
    Status400(models::supply_sources_2020_07_01::ErrorList),
    Status403(models::supply_sources_2020_07_01::ErrorList),
    Status404(models::supply_sources_2020_07_01::ErrorList),
    Status413(models::supply_sources_2020_07_01::ErrorList),
    Status415(models::supply_sources_2020_07_01::ErrorList),
    Status429(models::supply_sources_2020_07_01::ErrorList),
    Status500(models::supply_sources_2020_07_01::ErrorList),
    Status503(models::supply_sources_2020_07_01::ErrorList),
    UnknownValue(serde_json::Value),
}

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

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

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

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

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


/// Archive a supply source, making it inactive. Cannot be undone.
pub async fn archive_supply_source(configuration: &configuration::Configuration, supply_source_id: &str) -> Result<models::supply_sources_2020_07_01::ErrorList, Error<ArchiveSupplySourceError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_supply_source_id = supply_source_id;

    let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);

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

/// Create a new supply source.
pub async fn create_supply_source(configuration: &configuration::Configuration, payload: models::supply_sources_2020_07_01::CreateSupplySourceRequest) -> Result<models::supply_sources_2020_07_01::CreateSupplySourceResponse, Error<CreateSupplySourceError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_payload = payload;

    let uri_str = format!("{}/supplySources/2020-07-01/supplySources", 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_payload);

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

/// Retrieve a supply source.
pub async fn get_supply_source(configuration: &configuration::Configuration, supply_source_id: &str) -> Result<models::supply_sources_2020_07_01::SupplySource, Error<GetSupplySourceError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_supply_source_id = supply_source_id;

    let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

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

/// The path to retrieve paginated supply sources.
pub async fn get_supply_sources(configuration: &configuration::Configuration, next_page_token: Option<&str>, page_size: Option<f64>) -> Result<models::supply_sources_2020_07_01::GetSupplySourcesResponse, Error<GetSupplySourcesError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_next_page_token = next_page_token;
    let p_page_size = page_size;

    let uri_str = format!("{}/supplySources/2020-07-01/supplySources", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_next_page_token {
        req_builder = req_builder.query(&[("nextPageToken", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_page_size {
        req_builder = req_builder.query(&[("pageSize", &param_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::supply_sources_2020_07_01::GetSupplySourcesResponse`"))),
            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::supply_sources_2020_07_01::GetSupplySourcesResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetSupplySourcesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Update the configuration and capabilities of a supply source.
pub async fn update_supply_source(configuration: &configuration::Configuration, supply_source_id: &str, payload: Option<models::supply_sources_2020_07_01::UpdateSupplySourceRequest>) -> Result<models::supply_sources_2020_07_01::ErrorList, Error<UpdateSupplySourceError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_supply_source_id = supply_source_id;
    let p_payload = payload;

    let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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_payload);

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

/// Update the status of a supply source.
pub async fn update_supply_source_status(configuration: &configuration::Configuration, supply_source_id: &str, payload: Option<models::supply_sources_2020_07_01::UpdateSupplySourceStatusRequest>) -> Result<models::supply_sources_2020_07_01::ErrorList, Error<UpdateSupplySourceStatusError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_supply_source_id = supply_source_id;
    let p_payload = payload;

    let uri_str = format!("{}/supplySources/2020-07-01/supplySources/{supplySourceId}/status", configuration.base_path, supplySourceId=crate::apis::urlencode(p_supply_source_id));
    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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_payload);

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