open_logistics/shiprocket/apis/
orders_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::shiprocket::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum OrdersCancelError {
22 DefaultResponse(models::ShiprocketError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum OrdersCreateError {
30 DefaultResponse(models::ShiprocketError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum OrdersGetError {
38 DefaultResponse(models::ShiprocketError),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum OrdersListError {
46 DefaultResponse(models::ShiprocketError),
47 UnknownValue(serde_json::Value),
48}
49
50
51pub async fn orders_cancel(configuration: &configuration::Configuration, cancel_orders_payload: models::CancelOrdersPayload) -> Result<models::MessageResponse, Error<OrdersCancelError>> {
52 let p_body_cancel_orders_payload = cancel_orders_payload;
54
55 let uri_str = format!("{}/orders/cancel", configuration.base_path);
56 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
57
58 if let Some(ref user_agent) = configuration.user_agent {
59 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
60 }
61 if let Some(ref token) = configuration.bearer_access_token {
62 req_builder = req_builder.bearer_auth(token.to_owned());
63 };
64 req_builder = req_builder.json(&p_body_cancel_orders_payload);
65
66 let req = req_builder.build()?;
67 let resp = configuration.client.execute(req).await?;
68
69 let status = resp.status();
70 let content_type = resp
71 .headers()
72 .get("content-type")
73 .and_then(|v| v.to_str().ok())
74 .unwrap_or("application/octet-stream");
75 let content_type = super::ContentType::from(content_type);
76
77 if !status.is_client_error() && !status.is_server_error() {
78 let content = resp.text().await?;
79 match content_type {
80 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
81 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageResponse`"))),
82 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::MessageResponse`")))),
83 }
84 } else {
85 let content = resp.text().await?;
86 let entity: Option<OrdersCancelError> = serde_json::from_str(&content).ok();
87 Err(Error::ResponseError(ResponseContent { status, content, entity }))
88 }
89}
90
91pub async fn orders_create(configuration: &configuration::Configuration, create_order_payload: models::CreateOrderPayload) -> Result<models::OrderResponse, Error<OrdersCreateError>> {
92 let p_body_create_order_payload = create_order_payload;
94
95 let uri_str = format!("{}/orders/create/adhoc", configuration.base_path);
96 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
97
98 if let Some(ref user_agent) = configuration.user_agent {
99 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100 }
101 if let Some(ref token) = configuration.bearer_access_token {
102 req_builder = req_builder.bearer_auth(token.to_owned());
103 };
104 req_builder = req_builder.json(&p_body_create_order_payload);
105
106 let req = req_builder.build()?;
107 let resp = configuration.client.execute(req).await?;
108
109 let status = resp.status();
110 let content_type = resp
111 .headers()
112 .get("content-type")
113 .and_then(|v| v.to_str().ok())
114 .unwrap_or("application/octet-stream");
115 let content_type = super::ContentType::from(content_type);
116
117 if !status.is_client_error() && !status.is_server_error() {
118 let content = resp.text().await?;
119 match content_type {
120 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
121 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OrderResponse`"))),
122 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::OrderResponse`")))),
123 }
124 } else {
125 let content = resp.text().await?;
126 let entity: Option<OrdersCreateError> = serde_json::from_str(&content).ok();
127 Err(Error::ResponseError(ResponseContent { status, content, entity }))
128 }
129}
130
131pub async fn orders_get(configuration: &configuration::Configuration, order_id: i32) -> Result<models::OrderResponse, Error<OrdersGetError>> {
132 let p_path_order_id = order_id;
134
135 let uri_str = format!("{}/orders/show/{orderId}", configuration.base_path, orderId=p_path_order_id);
136 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
137
138 if let Some(ref user_agent) = configuration.user_agent {
139 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
140 }
141 if let Some(ref token) = configuration.bearer_access_token {
142 req_builder = req_builder.bearer_auth(token.to_owned());
143 };
144
145 let req = req_builder.build()?;
146 let resp = configuration.client.execute(req).await?;
147
148 let status = resp.status();
149 let content_type = resp
150 .headers()
151 .get("content-type")
152 .and_then(|v| v.to_str().ok())
153 .unwrap_or("application/octet-stream");
154 let content_type = super::ContentType::from(content_type);
155
156 if !status.is_client_error() && !status.is_server_error() {
157 let content = resp.text().await?;
158 match content_type {
159 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
160 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OrderResponse`"))),
161 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::OrderResponse`")))),
162 }
163 } else {
164 let content = resp.text().await?;
165 let entity: Option<OrdersGetError> = serde_json::from_str(&content).ok();
166 Err(Error::ResponseError(ResponseContent { status, content, entity }))
167 }
168}
169
170pub async fn orders_list(configuration: &configuration::Configuration, page: Option<i32>, per_page: Option<i32>) -> Result<models::PaginatedOrders, Error<OrdersListError>> {
171 let p_query_page = page;
173 let p_query_per_page = per_page;
174
175 let uri_str = format!("{}/orders", configuration.base_path);
176 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
177
178 if let Some(ref param_value) = p_query_page {
179 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
180 }
181 if let Some(ref param_value) = p_query_per_page {
182 req_builder = req_builder.query(&[("per_page", ¶m_value.to_string())]);
183 }
184 if let Some(ref user_agent) = configuration.user_agent {
185 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
186 }
187 if let Some(ref token) = configuration.bearer_access_token {
188 req_builder = req_builder.bearer_auth(token.to_owned());
189 };
190
191 let req = req_builder.build()?;
192 let resp = configuration.client.execute(req).await?;
193
194 let status = resp.status();
195 let content_type = resp
196 .headers()
197 .get("content-type")
198 .and_then(|v| v.to_str().ok())
199 .unwrap_or("application/octet-stream");
200 let content_type = super::ContentType::from(content_type);
201
202 if !status.is_client_error() && !status.is_server_error() {
203 let content = resp.text().await?;
204 match content_type {
205 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
206 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedOrders`"))),
207 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::PaginatedOrders`")))),
208 }
209 } else {
210 let content = resp.text().await?;
211 let entity: Option<OrdersListError> = serde_json::from_str(&content).ok();
212 Err(Error::ResponseError(ResponseContent { status, content, entity }))
213 }
214}
215