redseat-api 0.2.0

Rust client for Redseat media servers
Documentation
//! Rust client for Redseat media servers.
//!
//! - [`CloudClient`]: the Redseat cloud: sign-in with a Google ID token, the user's
//!   servers, server tokens.
//! - [`google`] (feature `desktop-auth`, not on wasm): Google sign-in in the browser
//!   for desktop apps.
//! - [`RedseatClient`]: requests to one server through a [`Transport`], with the server
//!   token refreshed before it expires, and its events as a typed stream.
//! - [`ServerApi`] and [`LibraryApi`]: libraries, medias, thumbnails.
//! - [`http`] (feature `http`, default): the HTTP + SSE transport, and the choice of
//!   the server address.
//!
//! The data types are the server's own, from `rs-plugin-common-interfaces`
//! ([`types`]), and encrypted libraries use the server's own implementation, from
//! `redseat-crypto` ([`crypto`]).
//!
//! ```no_run
//! # #[cfg(feature = "http")]
//! # async fn run(google_id_token: &str) -> redseat_api::Result<()> {
//! use redseat_api::{CloudClient, RedseatClient, ServerApi};
//! use redseat_api::types::media::MediaQuery;
//!
//! let cloud = CloudClient::http()?;
//! let session = cloud.sign_in_with_google_id_token(google_id_token).await?;
//! let servers = cloud.list_servers(&session.token).await?;
//! let client =
//!     RedseatClient::connect_http(&servers[0], cloud, &session.token, Default::default())
//!         .await?;
//! let server = ServerApi::new(client);
//! let libraries = server.get_libraries().await?;
//! let library = server.library(libraries[0].clone());
//! let query = MediaQuery { limit: Some(10), ..Default::default() };
//! let page = library.get_medias_page(&query).await?;
//! let thumb = library.get_thumb(&page.medias[0].item).await?;
//! # Ok(()) }
//! ```

#![cfg_attr(
    not(test),
    deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)
)]
// On wasm, transports and token sources are not `Send` (JS handles): the client still
// shares them with `Arc`, so the code is the same on every target.
#![cfg_attr(target_arch = "wasm32", allow(clippy::arc_with_non_send_sync))]

/// Data exchanged with the server: libraries, medias, movies, series, events...
pub use rs_plugin_common_interfaces::domain as types;

/// Encryption of encrypted libraries, byte-compatible with the server.
pub use redseat_crypto as crypto;

pub mod client;
pub mod cloud;
pub mod direct;
pub mod error;
pub mod events;
pub mod library;
pub mod server;
pub mod sse;
pub mod transport;

#[cfg(feature = "http")]
pub mod http;

#[cfg(all(feature = "desktop-auth", not(target_arch = "wasm32")))]
pub mod google;

#[cfg(test)]
mod test_support;

pub use client::{
    AuthorizedUrl, ClientOptions, CloudTokenSource, EventOptions, RedseatClient, ServerEventStream,
    ServerTokenSource,
};
pub use cloud::{CloudClient, CloudServer, CloudSession, CloudUser, ServerToken};
pub use error::{Error, ErrorKind, Result};
pub use events::ServerEvent;
pub use library::{LibraryApi, MediaItem, MediaPage};
pub use server::ServerApi;
pub use transport::Transport;

#[cfg(test)]
mod tests {
    use super::types::library::{LibraryType, ServerLibrary};

    #[test]
    fn reads_a_library_as_the_server_sends_it() {
        let library: ServerLibrary = serde_json::from_value(serde_json::json!({
            "id": "lib1",
            "name": "Photos",
            "source": "PathProvider",
            "type": "photos",
            "settings": {}
        }))
        .unwrap();
        assert_eq!(library.kind, LibraryType::Photos);
    }
}