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 HibpApi: Send + Sync {
    /// GET /hibp/breach
    async fn get<'a>(&self, username: Option<&'a str>) -> Result<(), Error>;
}

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

impl HibpApiClient {
    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 HibpApi for HibpApiClient {
    async fn get<'a>(&self, username: Option<&'a str>) -> Result<(), Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

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

        if let Some(ref param_value) = username {
            local_var_req_builder =
                local_var_req_builder.query(&[("username", &param_value.to_string())]);
        }
        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);

        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
    }
}