paperless-api-client 6.0.1

Paperless-ngx API client
Documentation
use crate::Client;
use anyhow::Result;
#[derive(Clone, Debug)]
pub struct Oauth {
    pub client: Client,
}

impl Oauth {
    #[doc(hidden)]
    pub fn new(client: Client) -> Self {
        Self { client }
    }

    #[doc = "Perform a `GET` request to `/api/oauth/callback/`.\n\nCallback view for OAuth2 authentication\n\n```rust,no_run\nasync fn example_oauth_callback_retrieve() -> anyhow::Result<()> {\n    let client = paperless_api_client::Client::new_from_env();\n    client.oauth().callback_retrieve().await?;\n    Ok(())\n}\n```"]
    #[tracing::instrument]
    #[allow(non_snake_case)]
    pub async fn callback_retrieve<'a>(&'a self) -> Result<(), crate::types::error::Error> {
        let mut req = self.client.client.request(
            http::Method::GET,
            format!("{}/{}", self.client.base_url, "api/oauth/callback/"),
        );
        req = req.header("Authorization", format!("Token {}", &self.client.token));
        let resp = req.send().await?;
        let status = resp.status();
        if status.is_success() {
            Ok(())
        } else {
            let text = resp.text().await.unwrap_or_default();
            Err(crate::types::error::Error::Server {
                body: text.to_string(),
                status,
            })
        }
    }
}