1use reqwest::StatusCode;
8
9use super::{configuration, Error};
10use crate::apis::ResponseContent;
11
12#[derive(Debug, Clone)]
14pub enum AcceptContractSuccess {
15 Status200(crate::models::AcceptContract200Response),
17}
18
19impl AcceptContractSuccess {
20 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
21 match status.as_u16() {
23 200 => Some(match serde_json::from_str(body) {
24 Ok(data) => Ok(Self::Status200(data)),
25 Err(err) => Err(err),
26 }),
27 _ => None,
28 }
29 }
30}
31
32#[derive(Debug, Clone)]
34pub enum DeliverContractSuccess {
35 Status200(crate::models::DeliverContract200Response),
37}
38
39impl DeliverContractSuccess {
40 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
41 match status.as_u16() {
43 200 => Some(match serde_json::from_str(body) {
44 Ok(data) => Ok(Self::Status200(data)),
45 Err(err) => Err(err),
46 }),
47 _ => None,
48 }
49 }
50}
51
52#[derive(Debug, Clone)]
54pub enum FulfillContractSuccess {
55 Status200(crate::models::FulfillContract200Response),
57}
58
59impl FulfillContractSuccess {
60 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
61 match status.as_u16() {
63 200 => Some(match serde_json::from_str(body) {
64 Ok(data) => Ok(Self::Status200(data)),
65 Err(err) => Err(err),
66 }),
67 _ => None,
68 }
69 }
70}
71
72#[derive(Debug, Clone)]
74pub enum GetContractSuccess {
75 Status200(crate::models::GetContract200Response),
77}
78
79impl GetContractSuccess {
80 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
81 match status.as_u16() {
83 200 => Some(match serde_json::from_str(body) {
84 Ok(data) => Ok(Self::Status200(data)),
85 Err(err) => Err(err),
86 }),
87 _ => None,
88 }
89 }
90}
91
92#[derive(Debug, Clone)]
94pub enum GetContractsSuccess {
95 Status200(crate::models::GetContracts200Response),
97}
98
99impl GetContractsSuccess {
100 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
101 match status.as_u16() {
103 200 => Some(match serde_json::from_str(body) {
104 Ok(data) => Ok(Self::Status200(data)),
105 Err(err) => Err(err),
106 }),
107 _ => None,
108 }
109 }
110}
111
112#[derive(Debug, Clone)]
114pub enum AcceptContractError {}
115
116impl AcceptContractError {
117 #[allow(unused_variables, clippy::match_single_binding)]
118 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
119 match status.as_u16() {
121 _ => None,
122 }
123 }
124}
125
126#[derive(Debug, Clone)]
128pub enum DeliverContractError {}
129
130impl DeliverContractError {
131 #[allow(unused_variables, clippy::match_single_binding)]
132 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
133 match status.as_u16() {
135 _ => None,
136 }
137 }
138}
139
140#[derive(Debug, Clone)]
142pub enum FulfillContractError {}
143
144impl FulfillContractError {
145 #[allow(unused_variables, clippy::match_single_binding)]
146 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
147 match status.as_u16() {
149 _ => None,
150 }
151 }
152}
153
154#[derive(Debug, Clone)]
156pub enum GetContractError {}
157
158impl GetContractError {
159 #[allow(unused_variables, clippy::match_single_binding)]
160 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
161 match status.as_u16() {
163 _ => None,
164 }
165 }
166}
167
168#[derive(Debug, Clone)]
170pub enum GetContractsError {}
171
172impl GetContractsError {
173 #[allow(unused_variables, clippy::match_single_binding)]
174 fn from_body(status: StatusCode, body: &str) -> Option<serde_json::Result<Self>> {
175 match status.as_u16() {
177 _ => None,
178 }
179 }
180}
181
182pub async fn accept_contract(
184 configuration: &configuration::Configuration,
185 contract_id: &str,
186) -> Result<ResponseContent<AcceptContractSuccess>, Error<AcceptContractError>> {
187 let client = &configuration.client;
188
189 let uri_str = format!(
192 "{}/my/contracts/{contractId}/accept",
193 configuration.base_path,
194 contractId = crate::apis::urlencode(contract_id)
195 );
196 let mut req_builder = client.request(reqwest::Method::POST, &uri_str);
197
198 if let Some(user_agent) = &configuration.user_agent {
202 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
203 }
204
205 if let Some(token) = &configuration.bearer_access_token {
208 req_builder = req_builder.bearer_auth(token.to_owned());
209 };
210
211 let req = req_builder.build()?;
215 let resp = client.execute(req).await?;
216
217 let status = resp.status();
219 let response_body = resp.text().await?;
220
221 if !status.is_client_error() && !status.is_server_error() {
222 match AcceptContractSuccess::from_body(status, &response_body) {
224 Some(Ok(content)) => Ok(ResponseContent {
225 status,
226 response_body,
227 content,
228 }),
229 Some(Err(err)) => Err(err.into()),
230 None => Err(Error::UnknownResponse {
231 status,
232 is_error: false,
233 response_body,
234 }),
235 }
236 } else {
237 match AcceptContractError::from_body(status, &response_body) {
239 Some(Ok(content)) => Err(Error::ResponseError(ResponseContent {
240 status,
241 response_body,
242 content,
243 })),
244 Some(Err(err)) => Err(err.into()),
245 None => Err(Error::UnknownResponse {
246 status,
247 is_error: true,
248 response_body,
249 }),
250 }
251 }
252}
253
254pub async fn deliver_contract(
256 configuration: &configuration::Configuration,
257 contract_id: &str,
258 deliver_contract_request: Option<crate::models::DeliverContractRequest>,
259) -> Result<ResponseContent<DeliverContractSuccess>, Error<DeliverContractError>> {
260 let client = &configuration.client;
261
262 let uri_str = format!(
265 "{}/my/contracts/{contractId}/deliver",
266 configuration.base_path,
267 contractId = crate::apis::urlencode(contract_id)
268 );
269 let mut req_builder = client.request(reqwest::Method::POST, &uri_str);
270
271 if let Some(user_agent) = &configuration.user_agent {
275 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
276 }
277
278 if let Some(token) = &configuration.bearer_access_token {
281 req_builder = req_builder.bearer_auth(token.to_owned());
282 };
283
284 req_builder = req_builder.json(&deliver_contract_request);
287
288 let req = req_builder.build()?;
292 let resp = client.execute(req).await?;
293
294 let status = resp.status();
296 let response_body = resp.text().await?;
297
298 if !status.is_client_error() && !status.is_server_error() {
299 match DeliverContractSuccess::from_body(status, &response_body) {
301 Some(Ok(content)) => Ok(ResponseContent {
302 status,
303 response_body,
304 content,
305 }),
306 Some(Err(err)) => Err(err.into()),
307 None => Err(Error::UnknownResponse {
308 status,
309 is_error: false,
310 response_body,
311 }),
312 }
313 } else {
314 match DeliverContractError::from_body(status, &response_body) {
316 Some(Ok(content)) => Err(Error::ResponseError(ResponseContent {
317 status,
318 response_body,
319 content,
320 })),
321 Some(Err(err)) => Err(err.into()),
322 None => Err(Error::UnknownResponse {
323 status,
324 is_error: true,
325 response_body,
326 }),
327 }
328 }
329}
330
331pub async fn fulfill_contract(
333 configuration: &configuration::Configuration,
334 contract_id: &str,
335) -> Result<ResponseContent<FulfillContractSuccess>, Error<FulfillContractError>> {
336 let client = &configuration.client;
337
338 let uri_str = format!(
341 "{}/my/contracts/{contractId}/fulfill",
342 configuration.base_path,
343 contractId = crate::apis::urlencode(contract_id)
344 );
345 let mut req_builder = client.request(reqwest::Method::POST, &uri_str);
346
347 if let Some(user_agent) = &configuration.user_agent {
351 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
352 }
353
354 if let Some(token) = &configuration.bearer_access_token {
357 req_builder = req_builder.bearer_auth(token.to_owned());
358 };
359
360 let req = req_builder.build()?;
364 let resp = client.execute(req).await?;
365
366 let status = resp.status();
368 let response_body = resp.text().await?;
369
370 if !status.is_client_error() && !status.is_server_error() {
371 match FulfillContractSuccess::from_body(status, &response_body) {
373 Some(Ok(content)) => Ok(ResponseContent {
374 status,
375 response_body,
376 content,
377 }),
378 Some(Err(err)) => Err(err.into()),
379 None => Err(Error::UnknownResponse {
380 status,
381 is_error: false,
382 response_body,
383 }),
384 }
385 } else {
386 match FulfillContractError::from_body(status, &response_body) {
388 Some(Ok(content)) => Err(Error::ResponseError(ResponseContent {
389 status,
390 response_body,
391 content,
392 })),
393 Some(Err(err)) => Err(err.into()),
394 None => Err(Error::UnknownResponse {
395 status,
396 is_error: true,
397 response_body,
398 }),
399 }
400 }
401}
402
403pub async fn get_contract(
405 configuration: &configuration::Configuration,
406 contract_id: &str,
407) -> Result<ResponseContent<GetContractSuccess>, Error<GetContractError>> {
408 let client = &configuration.client;
409
410 let uri_str = format!(
413 "{}/my/contracts/{contractId}",
414 configuration.base_path,
415 contractId = crate::apis::urlencode(contract_id)
416 );
417 let mut req_builder = client.request(reqwest::Method::GET, &uri_str);
418
419 if let Some(user_agent) = &configuration.user_agent {
423 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
424 }
425
426 if let Some(token) = &configuration.bearer_access_token {
429 req_builder = req_builder.bearer_auth(token.to_owned());
430 };
431
432 let req = req_builder.build()?;
436 let resp = client.execute(req).await?;
437
438 let status = resp.status();
440 let response_body = resp.text().await?;
441
442 if !status.is_client_error() && !status.is_server_error() {
443 match GetContractSuccess::from_body(status, &response_body) {
445 Some(Ok(content)) => Ok(ResponseContent {
446 status,
447 response_body,
448 content,
449 }),
450 Some(Err(err)) => Err(err.into()),
451 None => Err(Error::UnknownResponse {
452 status,
453 is_error: false,
454 response_body,
455 }),
456 }
457 } else {
458 match GetContractError::from_body(status, &response_body) {
460 Some(Ok(content)) => Err(Error::ResponseError(ResponseContent {
461 status,
462 response_body,
463 content,
464 })),
465 Some(Err(err)) => Err(err.into()),
466 None => Err(Error::UnknownResponse {
467 status,
468 is_error: true,
469 response_body,
470 }),
471 }
472 }
473}
474
475pub async fn get_contracts(
477 configuration: &configuration::Configuration,
478 page: Option<u32>,
479 limit: Option<u32>,
480) -> Result<ResponseContent<GetContractsSuccess>, Error<GetContractsError>> {
481 let client = &configuration.client;
482
483 let uri_str = format!("{}/my/contracts", configuration.base_path);
486 let mut req_builder = client.request(reqwest::Method::GET, &uri_str);
487
488 if let Some(s) = &page {
491 req_builder = req_builder.query(&[("page", &s.to_string())]);
492 }
493 if let Some(s) = &limit {
496 req_builder = req_builder.query(&[("limit", &s.to_string())]);
497 }
498
499 if let Some(user_agent) = &configuration.user_agent {
503 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
504 }
505
506 if let Some(token) = &configuration.bearer_access_token {
509 req_builder = req_builder.bearer_auth(token.to_owned());
510 };
511
512 let req = req_builder.build()?;
516 let resp = client.execute(req).await?;
517
518 let status = resp.status();
520 let response_body = resp.text().await?;
521
522 if !status.is_client_error() && !status.is_server_error() {
523 match GetContractsSuccess::from_body(status, &response_body) {
525 Some(Ok(content)) => Ok(ResponseContent {
526 status,
527 response_body,
528 content,
529 }),
530 Some(Err(err)) => Err(err.into()),
531 None => Err(Error::UnknownResponse {
532 status,
533 is_error: false,
534 response_body,
535 }),
536 }
537 } else {
538 match GetContractsError::from_body(status, &response_body) {
540 Some(Ok(content)) => Err(Error::ResponseError(ResponseContent {
541 status,
542 response_body,
543 content,
544 })),
545 Some(Err(err)) => Err(err.into()),
546 None => Err(Error::UnknownResponse {
547 status,
548 is_error: true,
549 response_body,
550 }),
551 }
552 }
553}