use crate::Client;
use anyhow::Result;
#[derive(Clone, Debug)]
pub struct Profile {
pub client: Client,
}
impl Profile {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Self { client }
}
#[doc = "Perform a `GET` request to `/api/profile/`.\n\nUser profile view, only available when logged in\n\n```rust,no_run\nasync fn example_profile_retrieve() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: paperless_api_client::types::Profile = client.profile().retrieve().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
#[allow(non_snake_case)]
pub async fn retrieve<'a>(
&'a self,
) -> Result<crate::types::Profile, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "api/profile/"),
);
req = req.header("Authorization", format!("Token {}", &self.client.token));
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Perform a `PATCH` request to `/api/profile/`.\n\nUser profile view, only available when logged in\n\n```rust,no_run\nasync fn example_profile_partial_update() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: paperless_api_client::types::Profile = client\n .profile()\n .partial_update(&paperless_api_client::types::PatchedProfileRequest {\n email: Some(\"email@example.com\".to_string()),\n password: Some(\"some-string\".to_string()),\n first_name: Some(\"some-string\".to_string()),\n last_name: Some(\"some-string\".to_string()),\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
#[allow(non_snake_case)]
pub async fn partial_update<'a>(
&'a self,
body: &crate::types::PatchedProfileRequest,
) -> Result<crate::types::Profile, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::PATCH,
format!("{}/{}", self.client.base_url, "api/profile/"),
);
req = req.header("Authorization", format!("Token {}", &self.client.token));
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Perform a `POST` request to `/api/profile/disconnect_social_account/`.\n\nDisconnects a social account provider from the user account\n\n```rust,no_run\nasync fn example_profile_disconnect_social_account_create() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: i64 = client\n .profile()\n .disconnect_social_account_create(\n &paperless_api_client::types::ProfileDisconnectSocialAccountCreateRequestBody { id: 4 as i64 },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
#[allow(non_snake_case)]
pub async fn disconnect_social_account_create<'a>(
&'a self,
body: &crate::types::ProfileDisconnectSocialAccountCreateRequestBody,
) -> Result<i64, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url, "api/profile/disconnect_social_account/"
),
);
req = req.header("Authorization", format!("Token {}", &self.client.token));
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Perform a `POST` request to `/api/profile/generate_auth_token/`.\n\nGenerates (or re-generates) an auth token, requires a logged in user\nunlike the default DRF endpoint\n\n```rust,no_run\nasync fn example_profile_generate_auth_token_create() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: String = client.profile().generate_auth_token_create().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
#[allow(non_snake_case)]
pub async fn generate_auth_token_create<'a>(
&'a self,
) -> Result<String, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url, "api/profile/generate_auth_token/"
),
);
req = req.header("Authorization", format!("Token {}", &self.client.token));
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Perform a `GET` request to `/api/profile/social_account_providers/`.\n\nList of social account providers\n\n```rust,no_run\nasync fn example_profile_social_account_providers_retrieve() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: std::collections::HashMap<String, serde_json::Value> =\n client.profile().social_account_providers_retrieve().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
#[allow(non_snake_case)]
pub async fn social_account_providers_retrieve<'a>(
&'a self,
) -> Result<std::collections::HashMap<String, serde_json::Value>, crate::types::error::Error>
{
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url, "api/profile/social_account_providers/"
),
);
req = req.header("Authorization", format!("Token {}", &self.client.token));
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Perform a `GET` request to `/api/profile/totp/`.\n\nGenerates a new TOTP secret and returns the URL and SVG\n\n```rust,no_run\nasync fn example_profile_totp_retrieve() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: std::collections::HashMap<String, serde_json::Value> =\n client.profile().totp_retrieve().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
#[allow(non_snake_case)]
pub async fn totp_retrieve<'a>(
&'a self,
) -> Result<std::collections::HashMap<String, serde_json::Value>, crate::types::error::Error>
{
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "api/profile/totp/"),
);
req = req.header("Authorization", format!("Token {}", &self.client.token));
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Perform a `POST` request to `/api/profile/totp/`.\n\nValidates a TOTP code and activates the TOTP authenticator\n\n```rust,no_run\nasync fn example_profile_totp_create() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: std::collections::HashMap<String, serde_json::Value> = client\n .profile()\n .totp_create(&paperless_api_client::types::ProfileTotpCreateRequestBody {\n secret: \"some-string\".to_string(),\n code: \"some-string\".to_string(),\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
#[allow(non_snake_case)]
pub async fn totp_create<'a>(
&'a self,
body: &crate::types::ProfileTotpCreateRequestBody,
) -> Result<std::collections::HashMap<String, serde_json::Value>, crate::types::error::Error>
{
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "api/profile/totp/"),
);
req = req.header("Authorization", format!("Token {}", &self.client.token));
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Perform a `DELETE` request to `/api/profile/totp/`.\n\nDeactivates the TOTP authenticator\n\n```rust,no_run\nasync fn example_profile_totp_destroy() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: bool = client.profile().totp_destroy().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
#[allow(non_snake_case)]
pub async fn totp_destroy<'a>(&'a self) -> Result<bool, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::DELETE,
format!("{}/{}", self.client.base_url, "api/profile/totp/"),
);
req = req.header("Authorization", format!("Token {}", &self.client.token));
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
}