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 OrganizationSponsorshipsApi: Send + Sync {
    /// DELETE /organization/sponsorship/{organizationId}/{sponsoredFriendlyName}/revoke
    async fn admin_initiated_revoke_sponsorship<'a>(
        &self,
        organization_id: uuid::Uuid,
        sponsored_friendly_name: &'a str,
    ) -> Result<(), Error>;

    /// POST /organization/sponsorship/{sponsoringOrgId}/families-for-enterprise
    async fn create_sponsorship<'a>(
        &self,
        sponsoring_org_id: uuid::Uuid,
        organization_sponsorship_create_request_model: Option<
            models::OrganizationSponsorshipCreateRequestModel,
        >,
    ) -> Result<(), Error>;

    /// GET /organization/sponsorship/{sponsoringOrgId}/sponsored
    async fn get_sponsored_organizations<'a>(
        &self,
        sponsoring_org_id: uuid::Uuid,
    ) -> Result<models::OrganizationSponsorshipInvitesResponseModelListResponseModel, Error>;

    /// GET /organization/sponsorship/{sponsoringOrgId}/sync-status
    async fn get_sync_status<'a>(&self, sponsoring_org_id: uuid::Uuid) -> Result<(), Error>;

    /// POST /organization/sponsorship/validate-token
    async fn pre_validate_sponsorship_token<'a>(
        &self,
        sponsorship_token: Option<&'a str>,
    ) -> Result<models::PreValidateSponsorshipResponseModel, Error>;

    /// POST /organization/sponsorship/redeem
    async fn redeem_sponsorship<'a>(
        &self,
        sponsorship_token: Option<&'a str>,
        organization_sponsorship_redeem_request_model: Option<
            models::OrganizationSponsorshipRedeemRequestModel,
        >,
    ) -> Result<(), Error>;

    /// DELETE /organization/sponsorship/sponsored/{sponsoredOrgId}
    async fn remove_sponsorship<'a>(&self, sponsored_org_id: uuid::Uuid) -> Result<(), Error>;

    /// POST /organization/sponsorship/{organizationId}/families-for-enterprise/resend
    async fn resend_sponsorship_offer<'a>(
        &self,
        organization_id: uuid::Uuid,
        sponsored_friendly_name: Option<&'a str>,
    ) -> Result<(), Error>;

    /// DELETE /organization/sponsorship/{sponsoringOrganizationId}
    async fn revoke_sponsorship<'a>(
        &self,
        sponsoring_organization_id: uuid::Uuid,
    ) -> Result<(), Error>;

    /// POST /organization/sponsorship/sync
    async fn sync<'a>(
        &self,
        organization_sponsorship_sync_request_model: Option<
            models::OrganizationSponsorshipSyncRequestModel,
        >,
    ) -> Result<models::OrganizationSponsorshipSyncResponseModel, Error>;
}

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

impl OrganizationSponsorshipsApiClient {
    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 OrganizationSponsorshipsApi for OrganizationSponsorshipsApiClient {
    async fn admin_initiated_revoke_sponsorship<'a>(
        &self,
        organization_id: uuid::Uuid,
        sponsored_friendly_name: &'a str,
    ) -> Result<(), Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organization/sponsorship/{organizationId}/{sponsoredFriendlyName}/revoke",
            local_var_configuration.base_path,
            organizationId = organization_id,
            sponsoredFriendlyName = crate::apis::urlencode(sponsored_friendly_name)
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());

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

        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
    }

    async fn create_sponsorship<'a>(
        &self,
        sponsoring_org_id: uuid::Uuid,
        organization_sponsorship_create_request_model: Option<
            models::OrganizationSponsorshipCreateRequestModel,
        >,
    ) -> Result<(), Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organization/sponsorship/{sponsoringOrgId}/families-for-enterprise",
            local_var_configuration.base_path,
            sponsoringOrgId = sponsoring_org_id
        );
        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(&organization_sponsorship_create_request_model);

        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
    }

    async fn get_sponsored_organizations<'a>(
        &self,
        sponsoring_org_id: uuid::Uuid,
    ) -> Result<models::OrganizationSponsorshipInvitesResponseModelListResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organization/sponsorship/{sponsoringOrgId}/sponsored",
            local_var_configuration.base_path,
            sponsoringOrgId = sponsoring_org_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 get_sync_status<'a>(&self, sponsoring_org_id: uuid::Uuid) -> Result<(), Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organization/sponsorship/{sponsoringOrgId}/sync-status",
            local_var_configuration.base_path,
            sponsoringOrgId = sponsoring_org_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_empty_response(local_var_req_builder).await
    }

    async fn pre_validate_sponsorship_token<'a>(
        &self,
        sponsorship_token: Option<&'a str>,
    ) -> Result<models::PreValidateSponsorshipResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

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

        if let Some(ref param_value) = sponsorship_token {
            local_var_req_builder =
                local_var_req_builder.query(&[("sponsorshipToken", &param_value.to_string())]);
        }
        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 redeem_sponsorship<'a>(
        &self,
        sponsorship_token: Option<&'a str>,
        organization_sponsorship_redeem_request_model: Option<
            models::OrganizationSponsorshipRedeemRequestModel,
        >,
    ) -> Result<(), Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

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

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

        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
    }

    async fn remove_sponsorship<'a>(&self, sponsored_org_id: uuid::Uuid) -> Result<(), Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organization/sponsorship/sponsored/{sponsoredOrgId}",
            local_var_configuration.base_path,
            sponsoredOrgId = sponsored_org_id
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());

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

        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
    }

    async fn resend_sponsorship_offer<'a>(
        &self,
        organization_id: uuid::Uuid,
        sponsored_friendly_name: 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!(
            "{}/organization/sponsorship/{organizationId}/families-for-enterprise/resend",
            local_var_configuration.base_path,
            organizationId = organization_id
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

        if let Some(ref param_value) = sponsored_friendly_name {
            local_var_req_builder =
                local_var_req_builder.query(&[("sponsoredFriendlyName", &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
    }

    async fn revoke_sponsorship<'a>(
        &self,
        sponsoring_organization_id: uuid::Uuid,
    ) -> Result<(), Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organization/sponsorship/{sponsoringOrganizationId}",
            local_var_configuration.base_path,
            sponsoringOrganizationId = sponsoring_organization_id
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());

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

        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
    }

    async fn sync<'a>(
        &self,
        organization_sponsorship_sync_request_model: Option<
            models::OrganizationSponsorshipSyncRequestModel,
        >,
    ) -> Result<models::OrganizationSponsorshipSyncResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organization/sponsorship/sync",
            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(&organization_sponsorship_sync_request_model);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }
}