/*
* Selling Partner API for Shipping
*
* Provides programmatic access to Amazon Shipping APIs. **Note:** If you are new to the Amazon Shipping API, refer to the latest version of <a href=\"https://developer-docs.amazon.com/amazon-shipping/docs/shipping-api-v2-reference\">Amazon Shipping API (v2)</a> on the <a href=\"https://developer-docs.amazon.com/amazon-shipping/\">Amazon Shipping Developer Documentation</a> site.
*
* The version of the OpenAPI document: v1
*
* 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::shipping::CancelShipmentResponse),
Status401(models::shipping::CancelShipmentResponse),
Status403(models::shipping::CancelShipmentResponse),
Status404(models::shipping::CancelShipmentResponse),
Status429(models::shipping::CancelShipmentResponse),
Status500(models::shipping::CancelShipmentResponse),
Status503(models::shipping::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::shipping::CreateShipmentResponse),
Status401(models::shipping::CreateShipmentResponse),
Status403(models::shipping::CreateShipmentResponse),
Status404(models::shipping::CreateShipmentResponse),
Status429(models::shipping::CreateShipmentResponse),
Status500(models::shipping::CreateShipmentResponse),
Status503(models::shipping::CreateShipmentResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_account`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAccountError {
Status400(models::shipping::GetAccountResponse),
Status401(models::shipping::GetAccountResponse),
Status403(models::shipping::GetAccountResponse),
Status404(models::shipping::GetAccountResponse),
Status429(models::shipping::GetAccountResponse),
Status500(models::shipping::GetAccountResponse),
Status503(models::shipping::GetAccountResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_rates`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetRatesError {
Status400(models::shipping::GetRatesResponse),
Status401(models::shipping::GetRatesResponse),
Status403(models::shipping::GetRatesResponse),
Status404(models::shipping::GetRatesResponse),
Status429(models::shipping::GetRatesResponse),
Status500(models::shipping::GetRatesResponse),
Status503(models::shipping::GetRatesResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_shipment`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetShipmentError {
Status400(models::shipping::GetShipmentResponse),
Status401(models::shipping::GetShipmentResponse),
Status403(models::shipping::GetShipmentResponse),
Status404(models::shipping::GetShipmentResponse),
Status429(models::shipping::GetShipmentResponse),
Status500(models::shipping::GetShipmentResponse),
Status503(models::shipping::GetShipmentResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_tracking_information`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetTrackingInformationError {
Status400(models::shipping::GetTrackingInformationResponse),
Status401(models::shipping::GetTrackingInformationResponse),
Status403(models::shipping::GetTrackingInformationResponse),
Status404(models::shipping::GetTrackingInformationResponse),
Status429(models::shipping::GetTrackingInformationResponse),
Status500(models::shipping::GetTrackingInformationResponse),
Status503(models::shipping::GetTrackingInformationResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`purchase_labels`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PurchaseLabelsError {
Status400(models::shipping::PurchaseLabelsResponse),
Status401(models::shipping::PurchaseLabelsResponse),
Status403(models::shipping::PurchaseLabelsResponse),
Status404(models::shipping::PurchaseLabelsResponse),
Status429(models::shipping::PurchaseLabelsResponse),
Status500(models::shipping::PurchaseLabelsResponse),
Status503(models::shipping::PurchaseLabelsResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`purchase_shipment`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PurchaseShipmentError {
Status400(models::shipping::PurchaseShipmentResponse),
Status401(models::shipping::PurchaseShipmentResponse),
Status403(models::shipping::PurchaseShipmentResponse),
Status404(models::shipping::PurchaseShipmentResponse),
Status429(models::shipping::PurchaseShipmentResponse),
Status500(models::shipping::PurchaseShipmentResponse),
Status503(models::shipping::PurchaseShipmentResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`retrieve_shipping_label`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RetrieveShippingLabelError {
Status400(models::shipping::RetrieveShippingLabelResponse),
Status401(models::shipping::RetrieveShippingLabelResponse),
Status403(models::shipping::RetrieveShippingLabelResponse),
Status404(models::shipping::RetrieveShippingLabelResponse),
Status429(models::shipping::RetrieveShippingLabelResponse),
Status500(models::shipping::RetrieveShippingLabelResponse),
Status503(models::shipping::RetrieveShippingLabelResponse),
UnknownValue(serde_json::Value),
}
/// Cancel a shipment by the given shipmentId. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 5 | 15 | For more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation.
pub async fn cancel_shipment(configuration: &configuration::Configuration, shipment_id: &str) -> Result<models::shipping::CancelShipmentResponse, Error<CancelShipmentError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_shipment_id = shipment_id;
let uri_str = format!("{}/shipping/v1/shipments/{shipmentId}/cancel", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_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());
}
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::shipping::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::shipping::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 new shipment. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 5 | 15 | The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
pub async fn create_shipment(configuration: &configuration::Configuration, body: models::shipping::CreateShipmentRequest) -> Result<models::shipping::CreateShipmentResponse, Error<CreateShipmentError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body = body;
let uri_str = format!("{}/shipping/v1/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::shipping::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::shipping::CreateShipmentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateShipmentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Verify if the current account is valid. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 5 | 15 | For more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation.
pub async fn get_account(configuration: &configuration::Configuration, ) -> Result<models::shipping::GetAccountResponse, Error<GetAccountError>> {
let uri_str = format!("{}/shipping/v1/account", configuration.base_path);
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::shipping::GetAccountResponse`"))),
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::shipping::GetAccountResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetAccountError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get service rates. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 5 | 15 | For more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation.
pub async fn get_rates(configuration: &configuration::Configuration, body: models::shipping::GetRatesRequest) -> Result<models::shipping::GetRatesResponse, Error<GetRatesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body = body;
let uri_str = format!("{}/shipping/v1/rates", 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::shipping::GetRatesResponse`"))),
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::shipping::GetRatesResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetRatesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Return the entire shipment object for the shipmentId. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 5 | 15 | For more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation.
pub async fn get_shipment(configuration: &configuration::Configuration, shipment_id: &str) -> Result<models::shipping::GetShipmentResponse, Error<GetShipmentError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_shipment_id = shipment_id;
let uri_str = format!("{}/shipping/v1/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::shipping::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::shipping::GetShipmentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetShipmentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Return the tracking information of a shipment. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 1 | For more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation.
pub async fn get_tracking_information(configuration: &configuration::Configuration, tracking_id: &str) -> Result<models::shipping::GetTrackingInformationResponse, Error<GetTrackingInformationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_tracking_id = tracking_id;
let uri_str = format!("{}/shipping/v1/tracking/{trackingId}", configuration.base_path, trackingId=crate::apis::urlencode(p_tracking_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::shipping::GetTrackingInformationResponse`"))),
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::shipping::GetTrackingInformationResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetTrackingInformationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Purchase shipping labels based on a given rate. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 5 | 15 | For more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation.
pub async fn purchase_labels(configuration: &configuration::Configuration, shipment_id: &str, body: models::shipping::PurchaseLabelsRequest) -> Result<models::shipping::PurchaseLabelsResponse, Error<PurchaseLabelsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_shipment_id = shipment_id;
let p_body = body;
let uri_str = format!("{}/shipping/v1/shipments/{shipmentId}/purchaseLabels", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_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();
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::shipping::PurchaseLabelsResponse`"))),
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::shipping::PurchaseLabelsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PurchaseLabelsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Purchase shipping labels. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 5 | 15 | For more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation.
pub async fn purchase_shipment(configuration: &configuration::Configuration, body: models::shipping::PurchaseShipmentRequest) -> Result<models::shipping::PurchaseShipmentResponse, Error<PurchaseShipmentError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body = body;
let uri_str = format!("{}/shipping/v1/purchaseShipment", 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::shipping::PurchaseShipmentResponse`"))),
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::shipping::PurchaseShipmentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PurchaseShipmentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Retrieve shipping label based on the shipment id and tracking id. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 5 | 15 | For more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation.
pub async fn retrieve_shipping_label(configuration: &configuration::Configuration, shipment_id: &str, tracking_id: &str, body: models::shipping::RetrieveShippingLabelRequest) -> Result<models::shipping::RetrieveShippingLabelResponse, Error<RetrieveShippingLabelError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_shipment_id = shipment_id;
let p_tracking_id = tracking_id;
let p_body = body;
let uri_str = format!("{}/shipping/v1/shipments/{shipmentId}/containers/{trackingId}/label", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_id), trackingId=crate::apis::urlencode(p_tracking_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();
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::shipping::RetrieveShippingLabelResponse`"))),
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::shipping::RetrieveShippingLabelResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<RetrieveShippingLabelError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}