bitwarden_api_api/apis/
misc_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12use serde::{Deserialize, Serialize};
13
14use super::{configuration, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`bitpay_invoice_post`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum BitpayInvoicePostError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`setup_payment_post`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum SetupPaymentPostError {
28    UnknownValue(serde_json::Value),
29}
30
31pub async fn bitpay_invoice_post(
32    configuration: &configuration::Configuration,
33    bit_pay_invoice_request_model: Option<models::BitPayInvoiceRequestModel>,
34) -> Result<String, Error<BitpayInvoicePostError>> {
35    let local_var_configuration = configuration;
36
37    let local_var_client = &local_var_configuration.client;
38
39    let local_var_uri_str = format!("{}/bitpay-invoice", local_var_configuration.base_path);
40    let mut local_var_req_builder =
41        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
42
43    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
44        local_var_req_builder =
45            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
46    }
47    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
48        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
49    };
50    local_var_req_builder = local_var_req_builder.json(&bit_pay_invoice_request_model);
51
52    let local_var_req = local_var_req_builder.build()?;
53    let local_var_resp = local_var_client.execute(local_var_req).await?;
54
55    let local_var_status = local_var_resp.status();
56    let local_var_content = local_var_resp.text().await?;
57
58    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
59        serde_json::from_str(&local_var_content).map_err(Error::from)
60    } else {
61        let local_var_entity: Option<BitpayInvoicePostError> =
62            serde_json::from_str(&local_var_content).ok();
63        let local_var_error = ResponseContent {
64            status: local_var_status,
65            content: local_var_content,
66            entity: local_var_entity,
67        };
68        Err(Error::ResponseError(local_var_error))
69    }
70}
71
72pub async fn setup_payment_post(
73    configuration: &configuration::Configuration,
74) -> Result<String, Error<SetupPaymentPostError>> {
75    let local_var_configuration = configuration;
76
77    let local_var_client = &local_var_configuration.client;
78
79    let local_var_uri_str = format!("{}/setup-payment", local_var_configuration.base_path);
80    let mut local_var_req_builder =
81        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
82
83    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
84        local_var_req_builder =
85            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
86    }
87    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
88        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
89    };
90
91    let local_var_req = local_var_req_builder.build()?;
92    let local_var_resp = local_var_client.execute(local_var_req).await?;
93
94    let local_var_status = local_var_resp.status();
95    let local_var_content = local_var_resp.text().await?;
96
97    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
98        serde_json::from_str(&local_var_content).map_err(Error::from)
99    } else {
100        let local_var_entity: Option<SetupPaymentPostError> =
101            serde_json::from_str(&local_var_content).ok();
102        let local_var_error = ResponseContent {
103            status: local_var_status,
104            content: local_var_content,
105            entity: local_var_entity,
106        };
107        Err(Error::ResponseError(local_var_error))
108    }
109}