amazon-spapi 2.0.3

A Rust client library for Amazon Selling Partner API (SP-API)
Documentation
/*
 * Selling Partner API for Merchant Fulfillment
 *
 * With the Selling Partner API for Merchant Fulfillment, you can build applications that sellers can use to purchase shipping for non-Prime and Prime orders using Amazon's Buy Shipping Services.
 *
 * The version of the OpenAPI document: v0
 * 
 * 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 [`cancel_shipment`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CancelShipmentError {
    Status400(models::merchant_fulfillment_v0::CancelShipmentResponse),
    Status401(models::merchant_fulfillment_v0::CancelShipmentResponse),
    Status403(models::merchant_fulfillment_v0::CancelShipmentResponse),
    Status404(models::merchant_fulfillment_v0::CancelShipmentResponse),
    Status429(models::merchant_fulfillment_v0::CancelShipmentResponse),
    Status500(models::merchant_fulfillment_v0::CancelShipmentResponse),
    Status503(models::merchant_fulfillment_v0::CancelShipmentResponse),
    UnknownValue(serde_json::Value),
}

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

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

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

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


/// Cancel the shipment indicated by the specified shipment identifier.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 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 indicates the default rate and burst values for this operation. Selling partners 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 SP-API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn cancel_shipment(configuration: &configuration::Configuration, shipment_id: &str) -> Result<models::merchant_fulfillment_v0::CancelShipmentResponse, Error<CancelShipmentError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_shipment_id = shipment_id;

    let uri_str = format!("{}/mfn/v0/shipments/{shipmentId}", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_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::merchant_fulfillment_v0::CancelShipmentResponse`"))),
            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::merchant_fulfillment_v0::CancelShipmentResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CancelShipmentError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Create a shipment with the information provided.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 2 | 2 |  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 indicates the default rate and burst values for this operation. Selling partners 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 SP-API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn create_shipment(configuration: &configuration::Configuration, body: models::merchant_fulfillment_v0::CreateShipmentRequest) -> Result<models::merchant_fulfillment_v0::CreateShipmentResponse, Error<CreateShipmentError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body = body;

    let uri_str = format!("{}/mfn/v0/shipments", 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::merchant_fulfillment_v0::CreateShipmentResponse`"))),
            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::merchant_fulfillment_v0::CreateShipmentResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CreateShipmentError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Gets a list of additional seller inputs required for a ship method. This is generally used for international shipping.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 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 indicates the default rate and burst values for this operation. Selling partners 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 SP-API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn get_additional_seller_inputs(configuration: &configuration::Configuration, body: models::merchant_fulfillment_v0::GetAdditionalSellerInputsRequest) -> Result<models::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse, Error<GetAdditionalSellerInputsError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body = body;

    let uri_str = format!("{}/mfn/v0/additionalSellerInputs", 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::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse`"))),
            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::merchant_fulfillment_v0::GetAdditionalSellerInputsResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetAdditionalSellerInputsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Returns a list of shipping service offers that satisfy the specified shipment request details.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 6 | 12 |  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 indicates the default rate and burst values for this operation. Selling partners 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 SP-API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn get_eligible_shipment_services(configuration: &configuration::Configuration, body: models::merchant_fulfillment_v0::GetEligibleShipmentServicesRequest) -> Result<models::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse, Error<GetEligibleShipmentServicesError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body = body;

    let uri_str = format!("{}/mfn/v0/eligibleShippingServices", 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::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse`"))),
            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::merchant_fulfillment_v0::GetEligibleShipmentServicesResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetEligibleShipmentServicesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Returns the shipment information for an existing shipment.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 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 indicates the default rate and burst values for this operation. Selling partners 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 SP-API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn get_shipment(configuration: &configuration::Configuration, shipment_id: &str) -> Result<models::merchant_fulfillment_v0::GetShipmentResponse, Error<GetShipmentError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_shipment_id = shipment_id;

    let uri_str = format!("{}/mfn/v0/shipments/{shipmentId}", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_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::merchant_fulfillment_v0::GetShipmentResponse`"))),
            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::merchant_fulfillment_v0::GetShipmentResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetShipmentError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}