1use 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 GetOrderError {
22 Status400(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
23 Status401(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
24 Status403(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
25 Status404(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
26 Status415(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
27 Status429(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
28 Status500(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
29 Status503(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum GetOrdersError {
37 Status400(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
38 Status403(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
39 Status404(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
40 Status415(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
41 Status429(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
42 Status500(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
43 Status503(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
44 UnknownValue(serde_json::Value),
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum SubmitAcknowledgementError {
51 Status400(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
52 Status403(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
53 Status404(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
54 Status413(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
55 Status415(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
56 Status429(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
57 Status500(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
58 Status503(models::vendor_direct_fulfillment_orders_2021_12_28::ErrorList),
59 UnknownValue(serde_json::Value),
60}
61
62
63pub async fn get_order(configuration: &configuration::Configuration, purchase_order_number: &str) -> Result<models::vendor_direct_fulfillment_orders_2021_12_28::Order, Error<GetOrderError>> {
65 let p_purchase_order_number = purchase_order_number;
67
68 let uri_str = format!("{}/vendor/directFulfillment/orders/2021-12-28/purchaseOrders/{purchaseOrderNumber}", configuration.base_path, purchaseOrderNumber=crate::apis::urlencode(p_purchase_order_number));
69 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
70
71 if let Some(ref user_agent) = configuration.user_agent {
72 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
73 }
74
75 let req = req_builder.build()?;
76 let resp = configuration.client.execute(req).await?;
77
78 let status = resp.status();
79 let content_type = resp
80 .headers()
81 .get("content-type")
82 .and_then(|v| v.to_str().ok())
83 .unwrap_or("application/octet-stream");
84 let content_type = super::ContentType::from(content_type);
85
86 if !status.is_client_error() && !status.is_server_error() {
87 let content = resp.text().await?;
88 match content_type {
89 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
90 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::vendor_direct_fulfillment_orders_2021_12_28::Order`"))),
91 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::vendor_direct_fulfillment_orders_2021_12_28::Order`")))),
92 }
93 } else {
94 let content = resp.text().await?;
95 let entity: Option<GetOrderError> = serde_json::from_str(&content).ok();
96 Err(Error::ResponseError(ResponseContent { status, content, entity }))
97 }
98}
99
100pub 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_2021_12_28::OrderList, Error<GetOrdersError>> {
102 let p_created_after = created_after;
104 let p_created_before = created_before;
105 let p_ship_from_party_id = ship_from_party_id;
106 let p_status = status;
107 let p_limit = limit;
108 let p_sort_order = sort_order;
109 let p_next_token = next_token;
110 let p_include_details = include_details;
111
112 let uri_str = format!("{}/vendor/directFulfillment/orders/2021-12-28/purchaseOrders", configuration.base_path);
113 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
114
115 if let Some(ref param_value) = p_ship_from_party_id {
116 req_builder = req_builder.query(&[("shipFromPartyId", ¶m_value.to_string())]);
117 }
118 if let Some(ref param_value) = p_status {
119 req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
120 }
121 if let Some(ref param_value) = p_limit {
122 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
123 }
124 req_builder = req_builder.query(&[("createdAfter", &p_created_after.to_string())]);
125 req_builder = req_builder.query(&[("createdBefore", &p_created_before.to_string())]);
126 if let Some(ref param_value) = p_sort_order {
127 req_builder = req_builder.query(&[("sortOrder", ¶m_value.to_string())]);
128 }
129 if let Some(ref param_value) = p_next_token {
130 req_builder = req_builder.query(&[("nextToken", ¶m_value.to_string())]);
131 }
132 if let Some(ref param_value) = p_include_details {
133 req_builder = req_builder.query(&[("includeDetails", ¶m_value.to_string())]);
134 }
135 if let Some(ref user_agent) = configuration.user_agent {
136 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
137 }
138
139 let req = req_builder.build()?;
140 let resp = configuration.client.execute(req).await?;
141
142 let status = resp.status();
143 let content_type = resp
144 .headers()
145 .get("content-type")
146 .and_then(|v| v.to_str().ok())
147 .unwrap_or("application/octet-stream");
148 let content_type = super::ContentType::from(content_type);
149
150 if !status.is_client_error() && !status.is_server_error() {
151 let content = resp.text().await?;
152 match content_type {
153 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
154 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::vendor_direct_fulfillment_orders_2021_12_28::OrderList`"))),
155 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::vendor_direct_fulfillment_orders_2021_12_28::OrderList`")))),
156 }
157 } else {
158 let content = resp.text().await?;
159 let entity: Option<GetOrdersError> = serde_json::from_str(&content).ok();
160 Err(Error::ResponseError(ResponseContent { status, content, entity }))
161 }
162}
163
164pub async fn submit_acknowledgement(configuration: &configuration::Configuration, body: models::vendor_direct_fulfillment_orders_2021_12_28::SubmitAcknowledgementRequest) -> Result<models::vendor_direct_fulfillment_orders_2021_12_28::TransactionId, Error<SubmitAcknowledgementError>> {
166 let p_body = body;
168
169 let uri_str = format!("{}/vendor/directFulfillment/orders/2021-12-28/acknowledgements", configuration.base_path);
170 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
171
172 if let Some(ref user_agent) = configuration.user_agent {
173 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
174 }
175 req_builder = req_builder.json(&p_body);
176
177 let req = req_builder.build()?;
178 let resp = configuration.client.execute(req).await?;
179
180 let status = resp.status();
181 let content_type = resp
182 .headers()
183 .get("content-type")
184 .and_then(|v| v.to_str().ok())
185 .unwrap_or("application/octet-stream");
186 let content_type = super::ContentType::from(content_type);
187
188 if !status.is_client_error() && !status.is_server_error() {
189 let content = resp.text().await?;
190 match content_type {
191 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
192 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::vendor_direct_fulfillment_orders_2021_12_28::TransactionId`"))),
193 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::vendor_direct_fulfillment_orders_2021_12_28::TransactionId`")))),
194 }
195 } else {
196 let content = resp.text().await?;
197 let entity: Option<SubmitAcknowledgementError> = serde_json::from_str(&content).ok();
198 Err(Error::ResponseError(ResponseContent { status, content, entity }))
199 }
200}
201