qbit 0.3.0

A wrapper for qBittorrent Web API
Documentation
#![recursion_limit = "256"] // For serde_json

//! # Qbittorrent Web API wrapper
//!
//! This module provides a wrapper around the Qbit Web API, enabling
//! interaction with the API through a structured and type-safe interface.
//!
//! The wrapper includes functionality for managing authentication states,
//! handling credentials, and interacting with various API endpoints.
//!
//! The library is designed to support Qbittorrent version `5.1`
//!
//! # Example
//!
//! Basic usage to get all torrents
//! ```no_run
//! use qbit::{Api, Credentials};
//!
//! #[tokio::main]
//! async fn main() {
//!     let credentials = Credentials::Login("username".to_string(), "password".to_string());
//!     let client = Api::new_login("http://qBittorrent.server:6969", credentials)
//!         .await
//!         .unwrap();
//!
//!     let torrents = client.torrents(None).await.unwrap();
//!
//!     for torrent in torrents {
//!         println!("{:?}", torrent);
//!     }
//! }
//! ```
//!

mod client;
mod error;
pub(crate) mod utilities;

/// Data object models.
pub mod models;
/// Parameter objects.
pub mod parameters;

pub use client::Api;
pub use error::Error;

#[cfg(all(feature = "qBittorrent-5_1", feature = "qBittorrent-5_3"))]
compile_error!(
    "Features 'qBittorrent-5_1' and 'qBittorrent-5_3' are not intended to be used together. Please use only one of them."
);

/// Login state
///
/// Represents the authentication state of a user in the system.
#[derive(Debug)]
pub struct LoginState {
    pub credentials: Option<Credentials>,
    pub sid_cookie: Option<String>,
}

impl LoginState {
    pub fn new() -> Self {
        Self {
            credentials: None,
            sid_cookie: None,
        }
    }
}

/// Represents the credentials used for authentication.
///
/// This enum holds the credentials for either a username:password or API key authentication.
#[derive(Debug, Clone, PartialEq)]
pub enum Credentials {
    Login(String, String),
    #[cfg(not(feature = "qBittorrent-5_1"))]
    // [pr 23212](https://github.com/qbittorrent/qBittorrent/pull/23212)
    APIKey(String),
}