/*
* Selling Partner API for Direct Fulfillment Orders
*
* The Selling Partner API for Direct Fulfillment Orders provides programmatic access to a direct fulfillment vendor's order data.
*
* 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 [`get_order`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetOrderError {
Status400(models::vendor_direct_fulfillment_orders_v1::GetOrderResponse),
Status401(models::vendor_direct_fulfillment_orders_v1::GetOrderResponse),
Status403(models::vendor_direct_fulfillment_orders_v1::GetOrderResponse),
Status404(models::vendor_direct_fulfillment_orders_v1::GetOrderResponse),
Status415(models::vendor_direct_fulfillment_orders_v1::GetOrderResponse),
Status429(models::vendor_direct_fulfillment_orders_v1::GetOrderResponse),
Status500(models::vendor_direct_fulfillment_orders_v1::GetOrderResponse),
Status503(models::vendor_direct_fulfillment_orders_v1::GetOrderResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_orders`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetOrdersError {
Status400(models::vendor_direct_fulfillment_orders_v1::GetOrdersResponse),
Status403(models::vendor_direct_fulfillment_orders_v1::GetOrdersResponse),
Status404(models::vendor_direct_fulfillment_orders_v1::GetOrdersResponse),
Status415(models::vendor_direct_fulfillment_orders_v1::GetOrdersResponse),
Status429(models::vendor_direct_fulfillment_orders_v1::GetOrdersResponse),
Status500(models::vendor_direct_fulfillment_orders_v1::GetOrdersResponse),
Status503(models::vendor_direct_fulfillment_orders_v1::GetOrdersResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`submit_acknowledgement`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SubmitAcknowledgementError {
Status400(models::vendor_direct_fulfillment_orders_v1::SubmitAcknowledgementResponse),
Status403(models::vendor_direct_fulfillment_orders_v1::SubmitAcknowledgementResponse),
Status404(models::vendor_direct_fulfillment_orders_v1::SubmitAcknowledgementResponse),
Status413(models::vendor_direct_fulfillment_orders_v1::SubmitAcknowledgementResponse),
Status415(models::vendor_direct_fulfillment_orders_v1::SubmitAcknowledgementResponse),
Status429(models::vendor_direct_fulfillment_orders_v1::SubmitAcknowledgementResponse),
Status500(models::vendor_direct_fulfillment_orders_v1::SubmitAcknowledgementResponse),
Status503(models::vendor_direct_fulfillment_orders_v1::SubmitAcknowledgementResponse),
UnknownValue(serde_json::Value),
}
/// Returns purchase order information for the purchaseOrderNumber that you specify. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 10 | 10 | 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](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn get_order(configuration: &configuration::Configuration, purchase_order_number: &str) -> Result<models::vendor_direct_fulfillment_orders_v1::GetOrderResponse, Error<GetOrderError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_purchase_order_number = purchase_order_number;
let uri_str = format!("{}/vendor/directFulfillment/orders/v1/purchaseOrders/{purchaseOrderNumber}", configuration.base_path, purchaseOrderNumber=crate::apis::urlencode(p_purchase_order_number));
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::GetOrderResponse`"))),
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::GetOrderResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetOrderError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns a list of purchase orders created during the time frame that you specify. You define the time frame using the createdAfter and createdBefore parameters. You must use both parameters. You can choose to get only the purchase order numbers by setting the includeDetails parameter to false. In that case, the operation returns a list of purchase order numbers. You can then call the getOrder operation to return the details of a specific order. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 10 | 10 | 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](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn get_orders(configuration: &configuration::Configuration, created_after: String, created_before: String, ship_from_party_id: Option<&str>, status: Option<&str>, limit: Option<i64>, sort_order: Option<&str>, next_token: Option<&str>, include_details: Option<&str>) -> Result<models::vendor_direct_fulfillment_orders_v1::GetOrdersResponse, Error<GetOrdersError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_created_after = created_after;
let p_created_before = created_before;
let p_ship_from_party_id = ship_from_party_id;
let p_status = status;
let p_limit = limit;
let p_sort_order = sort_order;
let p_next_token = next_token;
let p_include_details = include_details;
let uri_str = format!("{}/vendor/directFulfillment/orders/v1/purchaseOrders", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_ship_from_party_id {
req_builder = req_builder.query(&[("shipFromPartyId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_status {
req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("createdAfter", &p_created_after.to_string())]);
req_builder = req_builder.query(&[("createdBefore", &p_created_before.to_string())]);
if let Some(ref param_value) = p_sort_order {
req_builder = req_builder.query(&[("sortOrder", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_next_token {
req_builder = req_builder.query(&[("nextToken", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_include_details {
req_builder = req_builder.query(&[("includeDetails", ¶m_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::GetOrdersResponse`"))),
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::GetOrdersResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetOrdersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Submits acknowledgements for one or more purchase orders. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 10 | 10 | 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](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn submit_acknowledgement(configuration: &configuration::Configuration, body: models::vendor_direct_fulfillment_orders_v1::SubmitAcknowledgementRequest) -> Result<models::vendor_direct_fulfillment_orders_v1::SubmitAcknowledgementResponse, Error<SubmitAcknowledgementError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body = body;
let uri_str = format!("{}/vendor/directFulfillment/orders/v1/acknowledgements", 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::SubmitAcknowledgementResponse`"))),
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::SubmitAcknowledgementResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SubmitAcknowledgementError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}