bitwarden-api-api 3.0.0

Api bindings for the Bitwarden API.
Documentation
/*
 * Bitwarden Internal API
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: latest
 *
 * Generated by: https://openapi-generator.tech
 */

use std::sync::Arc;

use async_trait::async_trait;
#[cfg(feature = "mockall")]
use mockall::automock;
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};

use super::{Error, configuration};
use crate::{
    apis::{AuthRequired, ContentType, ResponseContent},
    models,
};

#[cfg_attr(feature = "mockall", automock)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait InstallationsApi: Send + Sync {
    /// GET /installations/{id}
    async fn get<'a>(&self, id: uuid::Uuid) -> Result<models::InstallationResponseModel, Error>;

    /// POST /installations
    async fn post<'a>(
        &self,
        installation_request_model: Option<models::InstallationRequestModel>,
    ) -> Result<models::InstallationResponseModel, Error>;
}

pub struct InstallationsApiClient {
    configuration: Arc<configuration::Configuration>,
}

impl InstallationsApiClient {
    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
        Self { configuration }
    }
}

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl InstallationsApi for InstallationsApiClient {
    async fn get<'a>(&self, id: uuid::Uuid) -> Result<models::InstallationResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/installations/{id}",
            local_var_configuration.base_path,
            id = id
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }

    async fn post<'a>(
        &self,
        installation_request_model: Option<models::InstallationRequestModel>,
    ) -> Result<models::InstallationResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!("{}/installations", local_var_configuration.base_path);
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
        local_var_req_builder = local_var_req_builder.json(&installation_request_model);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }
}