#![allow(clippy::too_many_arguments)]
use crate::AxiamError;
use crate::client::AxiamClient;
use crate::management::models;
use crate::management::request::{Call, Verb};
use crate::management::scope::Scope;
#[derive(Clone, Copy)]
pub struct Privacy<'c> {
pub(crate) client: &'c AxiamClient,
pub(crate) scope: Scope,
}
impl std::fmt::Debug for Privacy<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Privacy")
.field("scope", &self.scope)
.finish()
}
}
impl<'c> Privacy<'c> {
pub(crate) fn new(client: &'c AxiamClient) -> Self {
Self {
client,
scope: Scope::default(),
}
}
pub async fn request_export(&self, body: &serde_json::Value) -> Result<(), AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "privacy.request_export",
verb: Verb::Post,
path_template: "/api/v1/account/export",
path: "/api/v1/account/export".to_string(),
query: &query,
};
self.client
.management_send_no_content(call, Some(body))
.await
}
pub async fn download_export(&self, token: &str) -> Result<(), AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "privacy.download_export",
verb: Verb::Get,
path_template: "/api/v1/account/export/{token}",
path: format!("/api/v1/account/export/{token}"),
query: &query,
};
self.client
.management_send_no_content(call, None::<&()>)
.await
}
pub async fn request_delete(&self, body: &serde_json::Value) -> Result<(), AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "privacy.request_delete",
verb: Verb::Post,
path_template: "/api/v1/account/delete",
path: "/api/v1/account/delete".to_string(),
query: &query,
};
self.client
.management_send_no_content(call, Some(body))
.await
}
pub async fn cancel_delete(&self, token: &str) -> Result<(), AxiamError> {
let query: Vec<(&'static str, String)> = vec![("token", token.to_string())];
let call = Call {
operation: "privacy.cancel_delete",
verb: Verb::Get,
path_template: "/api/v1/auth/account/delete/cancel",
path: "/api/v1/auth/account/delete/cancel".to_string(),
query: &query,
};
self.client
.management_send_no_content(call, None::<&()>)
.await
}
pub async fn list_consents(&self) -> Result<Vec<models::ConsentView>, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "privacy.list_consents",
verb: Verb::Get,
path_template: "/api/v1/account/consents",
path: "/api/v1/account/consents".to_string(),
query: &query,
};
self.client
.management_send::<_, Vec<models::ConsentView>>(call, None::<&()>)
.await
}
pub async fn grant_scope_consent(
&self,
body: &models::GrantScopeConsent,
) -> Result<(), AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "privacy.grant_scope_consent",
verb: Verb::Post,
path_template: "/api/v1/account/consents/oidc-scopes",
path: "/api/v1/account/consents/oidc-scopes".to_string(),
query: &query,
};
self.client
.management_send_no_content(call, Some(body))
.await
}
pub async fn withdraw_scope_consent(&self, client_id: &str) -> Result<(), AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "privacy.withdraw_scope_consent",
verb: Verb::Delete,
path_template: "/api/v1/account/consents/oidc-scopes/{client_id}",
path: format!("/api/v1/account/consents/oidc-scopes/{client_id}"),
query: &query,
};
self.client
.management_send_no_content(call, None::<&()>)
.await
}
}