hightorrent_api 0.3.0

Highlevel torrent API client, supporting Bittorrent v1, v2 and hybrid torrents
Documentation
use crate::ApiError;
use hightorrent::{SingleTarget, Torrent, TorrentContent, TorrentList, Tracker};

mod add;
pub use add::*;

#[async_trait]
pub trait Api: Send + Sync + for<'a> ApiAdd<'a> {
    // Build Api client
    async fn login(host: &str, user: &str, password: &str) -> Result<Self, ApiError>
    where
        Self: Sized;

    // Configuration values used to bootstrap API
    fn host(&self) -> String;
    fn user(&self) -> String;
    fn password(&self) -> String;

    // Torrent information
    async fn list(&self) -> Result<TorrentList, ApiError>;
    async fn get(&self, hash: &SingleTarget) -> Result<Option<Torrent>, ApiError>;
    async fn remove(&self, hash: &SingleTarget, delete_files: bool) -> Result<(), ApiError>;

    // Tracker manipulation
    // TODO: change to Result<Option<Vec<Tracker>> to express torrent not found
    async fn get_trackers(&self, hash: &SingleTarget) -> Result<Vec<Tracker>, ApiError>;
    async fn add_tracker(&self, hash: &SingleTarget, tracker: &str) -> Result<(), ApiError>;
    async fn remove_tracker(&self, hash: &SingleTarget, tracker: &str) -> Result<(), ApiError>;

    async fn get_files(&self, hash: &SingleTarget) -> Result<Vec<TorrentContent>, ApiError>;

    /// Adds a new torrent to the client backend.
    ///
    /// This method generates a builder to adjust settings, on which you then
    /// need to call the `send` method, like so:
    ///
    /// ```ignore
    /// qbittorrent.add().magnet(magnet_link).send().await?;
    /// ```
    ///
    /// Additional operation parameters are documented on the [`AddBuilder`] type.
    fn add(&self) -> AddBuilder<'_, NoAddSource>
    where
        Self: Sized,
    {
        AddBuilder::new(self)
    }
}