amazon_spapi/apis/
shipment_invoicing_v0.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetInvoiceStatusError {
22 Status400(models::shipment_invoicing_v0::GetInvoiceStatusResponse),
23 Status401(models::shipment_invoicing_v0::GetInvoiceStatusResponse),
24 Status403(models::shipment_invoicing_v0::GetInvoiceStatusResponse),
25 Status404(models::shipment_invoicing_v0::GetInvoiceStatusResponse),
26 Status415(models::shipment_invoicing_v0::GetInvoiceStatusResponse),
27 Status429(models::shipment_invoicing_v0::GetInvoiceStatusResponse),
28 Status500(models::shipment_invoicing_v0::GetInvoiceStatusResponse),
29 Status503(models::shipment_invoicing_v0::GetInvoiceStatusResponse),
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum GetShipmentDetailsError {
37 Status400(models::shipment_invoicing_v0::GetShipmentDetailsResponse),
38 Status401(models::shipment_invoicing_v0::GetShipmentDetailsResponse),
39 Status403(models::shipment_invoicing_v0::GetShipmentDetailsResponse),
40 Status404(models::shipment_invoicing_v0::GetShipmentDetailsResponse),
41 Status415(models::shipment_invoicing_v0::GetShipmentDetailsResponse),
42 Status429(models::shipment_invoicing_v0::GetShipmentDetailsResponse),
43 Status500(models::shipment_invoicing_v0::GetShipmentDetailsResponse),
44 Status503(models::shipment_invoicing_v0::GetShipmentDetailsResponse),
45 UnknownValue(serde_json::Value),
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum SubmitInvoiceError {
52 Status400(models::shipment_invoicing_v0::SubmitInvoiceResponse),
53 Status401(models::shipment_invoicing_v0::SubmitInvoiceResponse),
54 Status403(models::shipment_invoicing_v0::SubmitInvoiceResponse),
55 Status404(models::shipment_invoicing_v0::SubmitInvoiceResponse),
56 Status415(models::shipment_invoicing_v0::SubmitInvoiceResponse),
57 Status429(models::shipment_invoicing_v0::SubmitInvoiceResponse),
58 Status500(models::shipment_invoicing_v0::SubmitInvoiceResponse),
59 Status503(models::shipment_invoicing_v0::SubmitInvoiceResponse),
60 UnknownValue(serde_json::Value),
61}
62
63
64pub async fn get_invoice_status(configuration: &configuration::Configuration, shipment_id: &str) -> Result<models::shipment_invoicing_v0::GetInvoiceStatusResponse, Error<GetInvoiceStatusError>> {
66 let p_shipment_id = shipment_id;
68
69 let uri_str = format!("{}/fba/outbound/brazil/v0/shipments/{shipmentId}/invoice/status", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_id));
70 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
71
72 if let Some(ref user_agent) = configuration.user_agent {
73 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
74 }
75
76 let req = req_builder.build()?;
77 let resp = configuration.client.execute(req).await?;
78
79 let status = resp.status();
80 let content_type = resp
81 .headers()
82 .get("content-type")
83 .and_then(|v| v.to_str().ok())
84 .unwrap_or("application/octet-stream");
85 let content_type = super::ContentType::from(content_type);
86
87 if !status.is_client_error() && !status.is_server_error() {
88 let content = resp.text().await?;
89 match content_type {
90 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
91 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipment_invoicing_v0::GetInvoiceStatusResponse`"))),
92 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::shipment_invoicing_v0::GetInvoiceStatusResponse`")))),
93 }
94 } else {
95 let content = resp.text().await?;
96 let entity: Option<GetInvoiceStatusError> = serde_json::from_str(&content).ok();
97 Err(Error::ResponseError(ResponseContent { status, content, entity }))
98 }
99}
100
101pub async fn get_shipment_details(configuration: &configuration::Configuration, shipment_id: &str) -> Result<models::shipment_invoicing_v0::GetShipmentDetailsResponse, Error<GetShipmentDetailsError>> {
103 let p_shipment_id = shipment_id;
105
106 let uri_str = format!("{}/fba/outbound/brazil/v0/shipments/{shipmentId}", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_id));
107 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
108
109 if let Some(ref user_agent) = configuration.user_agent {
110 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
111 }
112
113 let req = req_builder.build()?;
114 let resp = configuration.client.execute(req).await?;
115
116 let status = resp.status();
117 let content_type = resp
118 .headers()
119 .get("content-type")
120 .and_then(|v| v.to_str().ok())
121 .unwrap_or("application/octet-stream");
122 let content_type = super::ContentType::from(content_type);
123
124 if !status.is_client_error() && !status.is_server_error() {
125 let content = resp.text().await?;
126 match content_type {
127 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
128 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipment_invoicing_v0::GetShipmentDetailsResponse`"))),
129 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::shipment_invoicing_v0::GetShipmentDetailsResponse`")))),
130 }
131 } else {
132 let content = resp.text().await?;
133 let entity: Option<GetShipmentDetailsError> = serde_json::from_str(&content).ok();
134 Err(Error::ResponseError(ResponseContent { status, content, entity }))
135 }
136}
137
138pub async fn submit_invoice(configuration: &configuration::Configuration, shipment_id: &str, body: models::shipment_invoicing_v0::SubmitInvoiceRequest) -> Result<models::shipment_invoicing_v0::SubmitInvoiceResponse, Error<SubmitInvoiceError>> {
140 let p_shipment_id = shipment_id;
142 let p_body = body;
143
144 let uri_str = format!("{}/fba/outbound/brazil/v0/shipments/{shipmentId}/invoice", configuration.base_path, shipmentId=crate::apis::urlencode(p_shipment_id));
145 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
146
147 if let Some(ref user_agent) = configuration.user_agent {
148 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
149 }
150 req_builder = req_builder.json(&p_body);
151
152 let req = req_builder.build()?;
153 let resp = configuration.client.execute(req).await?;
154
155 let status = resp.status();
156 let content_type = resp
157 .headers()
158 .get("content-type")
159 .and_then(|v| v.to_str().ok())
160 .unwrap_or("application/octet-stream");
161 let content_type = super::ContentType::from(content_type);
162
163 if !status.is_client_error() && !status.is_server_error() {
164 let content = resp.text().await?;
165 match content_type {
166 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
167 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::shipment_invoicing_v0::SubmitInvoiceResponse`"))),
168 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::shipment_invoicing_v0::SubmitInvoiceResponse`")))),
169 }
170 } else {
171 let content = resp.text().await?;
172 let entity: Option<SubmitInvoiceError> = serde_json::from_str(&content).ok();
173 Err(Error::ResponseError(ResponseContent { status, content, entity }))
174 }
175}
176