1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateCouponCollectionError {
20 Status400(models::ErrorModel),
21 Status401(models::ErrorModel),
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum CreateCouponsError {
29 Status400(models::ErrorModel),
30 Status401(models::ErrorModel),
31 Status404(models::ErrorModel),
32 UnknownValue(serde_json::Value),
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetCouponCollectionError {
39 Status400(models::ErrorModel),
40 Status401(models::ErrorModel),
41 Status404(models::ErrorModel),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetCouponCollectionsError {
49 Status400(models::ErrorModel),
50 Status401(models::ErrorModel),
51 UnknownValue(serde_json::Value),
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum UpdateCouponCollectionError {
58 Status400(models::ErrorModel),
59 Status401(models::ErrorModel),
60 UnknownValue(serde_json::Value),
61}
62
63pub async fn create_coupon_collection(
64 configuration: &configuration::Configuration,
65 create_coupon_collection_request: models::CreateCouponCollectionRequest,
66) -> Result<models::CreateCouponCollection201Response, Error<CreateCouponCollectionError>> {
67 let p_create_coupon_collection_request = create_coupon_collection_request;
69
70 let uri_str = format!("{}/couponCollections", configuration.base_path);
71 let mut req_builder = configuration
72 .client
73 .request(reqwest::Method::POST, &uri_str);
74
75 if let Some(ref user_agent) = configuration.user_agent {
76 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
77 }
78 if let Some(ref apikey) = configuration.api_key {
79 let key = apikey.key.clone();
80 let value = match apikey.prefix {
81 Some(ref prefix) => format!("{} {}", prefix, key),
82 None => key,
83 };
84 req_builder = req_builder.header("api-key", value);
85 };
86 req_builder = req_builder.json(&p_create_coupon_collection_request);
87
88 let req = req_builder.build()?;
89 let resp = configuration.client.execute(req).await?;
90
91 let status = resp.status();
92 let content_type = resp
93 .headers()
94 .get("content-type")
95 .and_then(|v| v.to_str().ok())
96 .unwrap_or("application/octet-stream");
97 let content_type = super::ContentType::from(content_type);
98
99 if !status.is_client_error() && !status.is_server_error() {
100 let content = resp.text().await?;
101 match content_type {
102 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
103 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateCouponCollection201Response`"))),
104 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateCouponCollection201Response`")))),
105 }
106 } else {
107 let content = resp.text().await?;
108 let entity: Option<CreateCouponCollectionError> = serde_json::from_str(&content).ok();
109 Err(Error::ResponseError(ResponseContent {
110 status,
111 content,
112 entity,
113 }))
114 }
115}
116
117pub async fn create_coupons(
118 configuration: &configuration::Configuration,
119 create_coupons_request: models::CreateCouponsRequest,
120) -> Result<(), Error<CreateCouponsError>> {
121 let p_create_coupons_request = create_coupons_request;
123
124 let uri_str = format!("{}/coupons", configuration.base_path);
125 let mut req_builder = configuration
126 .client
127 .request(reqwest::Method::POST, &uri_str);
128
129 if let Some(ref user_agent) = configuration.user_agent {
130 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
131 }
132 if let Some(ref apikey) = configuration.api_key {
133 let key = apikey.key.clone();
134 let value = match apikey.prefix {
135 Some(ref prefix) => format!("{} {}", prefix, key),
136 None => key,
137 };
138 req_builder = req_builder.header("api-key", value);
139 };
140 req_builder = req_builder.json(&p_create_coupons_request);
141
142 let req = req_builder.build()?;
143 let resp = configuration.client.execute(req).await?;
144
145 let status = resp.status();
146
147 if !status.is_client_error() && !status.is_server_error() {
148 Ok(())
149 } else {
150 let content = resp.text().await?;
151 let entity: Option<CreateCouponsError> = serde_json::from_str(&content).ok();
152 Err(Error::ResponseError(ResponseContent {
153 status,
154 content,
155 entity,
156 }))
157 }
158}
159
160pub async fn get_coupon_collection(
161 configuration: &configuration::Configuration,
162 id: &str,
163) -> Result<models::GetCouponCollection, Error<GetCouponCollectionError>> {
164 let p_id = id;
166
167 let uri_str = format!(
168 "{}/couponCollections/{id}",
169 configuration.base_path,
170 id = crate::apis::urlencode(p_id)
171 );
172 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
173
174 if let Some(ref user_agent) = configuration.user_agent {
175 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
176 }
177 if let Some(ref apikey) = configuration.api_key {
178 let key = apikey.key.clone();
179 let value = match apikey.prefix {
180 Some(ref prefix) => format!("{} {}", prefix, key),
181 None => key,
182 };
183 req_builder = req_builder.header("api-key", value);
184 };
185
186 let req = req_builder.build()?;
187 let resp = configuration.client.execute(req).await?;
188
189 let status = resp.status();
190 let content_type = resp
191 .headers()
192 .get("content-type")
193 .and_then(|v| v.to_str().ok())
194 .unwrap_or("application/octet-stream");
195 let content_type = super::ContentType::from(content_type);
196
197 if !status.is_client_error() && !status.is_server_error() {
198 let content = resp.text().await?;
199 match content_type {
200 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
201 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetCouponCollection`"))),
202 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetCouponCollection`")))),
203 }
204 } else {
205 let content = resp.text().await?;
206 let entity: Option<GetCouponCollectionError> = serde_json::from_str(&content).ok();
207 Err(Error::ResponseError(ResponseContent {
208 status,
209 content,
210 entity,
211 }))
212 }
213}
214
215pub async fn get_coupon_collections(
216 configuration: &configuration::Configuration,
217 limit: Option<i64>,
218 offset: Option<i64>,
219 sort: Option<&str>,
220 sort_by: Option<&str>,
221) -> Result<models::GetCouponCollection, Error<GetCouponCollectionsError>> {
222 let p_limit = limit;
224 let p_offset = offset;
225 let p_sort = sort;
226 let p_sort_by = sort_by;
227
228 let uri_str = format!("{}/couponCollections", configuration.base_path);
229 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
230
231 if let Some(ref param_value) = p_limit {
232 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
233 }
234 if let Some(ref param_value) = p_offset {
235 req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
236 }
237 if let Some(ref param_value) = p_sort {
238 req_builder = req_builder.query(&[("sort", ¶m_value.to_string())]);
239 }
240 if let Some(ref param_value) = p_sort_by {
241 req_builder = req_builder.query(&[("sortBy", ¶m_value.to_string())]);
242 }
243 if let Some(ref user_agent) = configuration.user_agent {
244 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
245 }
246 if let Some(ref apikey) = configuration.api_key {
247 let key = apikey.key.clone();
248 let value = match apikey.prefix {
249 Some(ref prefix) => format!("{} {}", prefix, key),
250 None => key,
251 };
252 req_builder = req_builder.header("api-key", value);
253 };
254
255 let req = req_builder.build()?;
256 let resp = configuration.client.execute(req).await?;
257
258 let status = resp.status();
259 let content_type = resp
260 .headers()
261 .get("content-type")
262 .and_then(|v| v.to_str().ok())
263 .unwrap_or("application/octet-stream");
264 let content_type = super::ContentType::from(content_type);
265
266 if !status.is_client_error() && !status.is_server_error() {
267 let content = resp.text().await?;
268 match content_type {
269 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
270 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetCouponCollection`"))),
271 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetCouponCollection`")))),
272 }
273 } else {
274 let content = resp.text().await?;
275 let entity: Option<GetCouponCollectionsError> = serde_json::from_str(&content).ok();
276 Err(Error::ResponseError(ResponseContent {
277 status,
278 content,
279 entity,
280 }))
281 }
282}
283
284pub async fn update_coupon_collection(
285 configuration: &configuration::Configuration,
286 id: &str,
287 update_coupon_collection_request: Option<models::UpdateCouponCollectionRequest>,
288) -> Result<models::UpdateCouponCollection200Response, Error<UpdateCouponCollectionError>> {
289 let p_id = id;
291 let p_update_coupon_collection_request = update_coupon_collection_request;
292
293 let uri_str = format!(
294 "{}/couponCollections/{id}",
295 configuration.base_path,
296 id = crate::apis::urlencode(p_id)
297 );
298 let mut req_builder = configuration
299 .client
300 .request(reqwest::Method::PATCH, &uri_str);
301
302 if let Some(ref user_agent) = configuration.user_agent {
303 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
304 }
305 if let Some(ref apikey) = configuration.api_key {
306 let key = apikey.key.clone();
307 let value = match apikey.prefix {
308 Some(ref prefix) => format!("{} {}", prefix, key),
309 None => key,
310 };
311 req_builder = req_builder.header("api-key", value);
312 };
313 req_builder = req_builder.json(&p_update_coupon_collection_request);
314
315 let req = req_builder.build()?;
316 let resp = configuration.client.execute(req).await?;
317
318 let status = resp.status();
319 let content_type = resp
320 .headers()
321 .get("content-type")
322 .and_then(|v| v.to_str().ok())
323 .unwrap_or("application/octet-stream");
324 let content_type = super::ContentType::from(content_type);
325
326 if !status.is_client_error() && !status.is_server_error() {
327 let content = resp.text().await?;
328 match content_type {
329 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
330 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateCouponCollection200Response`"))),
331 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UpdateCouponCollection200Response`")))),
332 }
333 } else {
334 let content = resp.text().await?;
335 let entity: Option<UpdateCouponCollectionError> = serde_json::from_str(&content).ok();
336 Err(Error::ResponseError(ResponseContent {
337 status,
338 content,
339 entity,
340 }))
341 }
342}