bitwarden_api_api/apis/
plans_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 std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait PlansApi: Send + Sync {
29    /// GET /plans
30    async fn get(&self) -> Result<models::PlanResponseModelListResponseModel, Error<GetError>>;
31
32    /// GET /plans/premium
33    async fn get_premium_plan(&self) -> Result<(), Error<GetPremiumPlanError>>;
34}
35
36pub struct PlansApiClient {
37    configuration: Arc<configuration::Configuration>,
38}
39
40impl PlansApiClient {
41    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
42        Self { configuration }
43    }
44}
45
46#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
47#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
48impl PlansApi for PlansApiClient {
49    async fn get(&self) -> Result<models::PlanResponseModelListResponseModel, Error<GetError>> {
50        let local_var_configuration = &self.configuration;
51
52        let local_var_client = &local_var_configuration.client;
53
54        let local_var_uri_str = format!("{}/plans", local_var_configuration.base_path);
55        let mut local_var_req_builder =
56            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
57
58        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
59            local_var_req_builder = local_var_req_builder
60                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
61        }
62        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
63            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
64        };
65
66        let local_var_req = local_var_req_builder.build()?;
67        let local_var_resp = local_var_client.execute(local_var_req).await?;
68
69        let local_var_status = local_var_resp.status();
70        let local_var_content_type = local_var_resp
71            .headers()
72            .get("content-type")
73            .and_then(|v| v.to_str().ok())
74            .unwrap_or("application/octet-stream");
75        let local_var_content_type = super::ContentType::from(local_var_content_type);
76        let local_var_content = local_var_resp.text().await?;
77
78        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
79            match local_var_content_type {
80                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
81                ContentType::Text => {
82                    return Err(Error::from(serde_json::Error::custom(
83                        "Received `text/plain` content type response that cannot be converted to `models::PlanResponseModelListResponseModel`",
84                    )));
85                }
86                ContentType::Unsupported(local_var_unknown_type) => {
87                    return Err(Error::from(serde_json::Error::custom(format!(
88                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::PlanResponseModelListResponseModel`"
89                    ))));
90                }
91            }
92        } else {
93            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
94            let local_var_error = ResponseContent {
95                status: local_var_status,
96                content: local_var_content,
97                entity: local_var_entity,
98            };
99            Err(Error::ResponseError(local_var_error))
100        }
101    }
102
103    async fn get_premium_plan(&self) -> Result<(), Error<GetPremiumPlanError>> {
104        let local_var_configuration = &self.configuration;
105
106        let local_var_client = &local_var_configuration.client;
107
108        let local_var_uri_str = format!("{}/plans/premium", local_var_configuration.base_path);
109        let mut local_var_req_builder =
110            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
111
112        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
113            local_var_req_builder = local_var_req_builder
114                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
115        }
116        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
117            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
118        };
119
120        let local_var_req = local_var_req_builder.build()?;
121        let local_var_resp = local_var_client.execute(local_var_req).await?;
122
123        let local_var_status = local_var_resp.status();
124        let local_var_content = local_var_resp.text().await?;
125
126        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
127            Ok(())
128        } else {
129            let local_var_entity: Option<GetPremiumPlanError> =
130                serde_json::from_str(&local_var_content).ok();
131            let local_var_error = ResponseContent {
132                status: local_var_status,
133                content: local_var_content,
134                entity: local_var_entity,
135            };
136            Err(Error::ResponseError(local_var_error))
137        }
138    }
139}
140
141/// struct for typed errors of method [`PlansApi::get`]
142#[derive(Debug, Clone, Serialize, Deserialize)]
143#[serde(untagged)]
144pub enum GetError {
145    UnknownValue(serde_json::Value),
146}
147/// struct for typed errors of method [`PlansApi::get_premium_plan`]
148#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(untagged)]
150pub enum GetPremiumPlanError {
151    UnknownValue(serde_json::Value),
152}