redseat_api/lib.rs
1//! Rust client for Redseat media servers.
2//!
3//! - [`CloudClient`]: the Redseat cloud: sign-in with a Google ID token, the user's
4//! servers, server tokens.
5//! - [`google`] (feature `desktop-auth`, not on wasm): Google sign-in in the browser
6//! for desktop apps.
7//! - [`RedseatClient`]: requests to one server through a [`Transport`], with the server
8//! token refreshed before it expires, and its events as a typed stream.
9//! - [`ServerApi`] and [`LibraryApi`]: libraries, medias, thumbnails.
10//! - [`http`] (feature `http`, default): the HTTP + SSE transport, and the choice of
11//! the server address.
12//!
13//! The data types are the server's own, from `rs-plugin-common-interfaces`
14//! ([`types`]), and encrypted libraries use the server's own implementation, from
15//! `redseat-crypto` ([`crypto`]).
16//!
17//! ```no_run
18//! # #[cfg(feature = "http")]
19//! # async fn run(google_id_token: &str) -> redseat_api::Result<()> {
20//! use redseat_api::{CloudClient, RedseatClient, ServerApi};
21//! use redseat_api::types::media::MediaQuery;
22//!
23//! let cloud = CloudClient::http()?;
24//! let session = cloud.sign_in_with_google_id_token(google_id_token).await?;
25//! let servers = cloud.list_servers(&session.token).await?;
26//! let client =
27//! RedseatClient::connect_http(&servers[0], cloud, &session.token, Default::default())
28//! .await?;
29//! let server = ServerApi::new(client);
30//! let libraries = server.get_libraries().await?;
31//! let library = server.library(libraries[0].clone());
32//! let query = MediaQuery { limit: Some(10), ..Default::default() };
33//! let page = library.get_medias_page(&query).await?;
34//! let thumb = library.get_thumb(&page.medias[0].item).await?;
35//! # Ok(()) }
36//! ```
37
38#![cfg_attr(
39 not(test),
40 deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)
41)]
42// On wasm, transports and token sources are not `Send` (JS handles): the client still
43// shares them with `Arc`, so the code is the same on every target.
44#![cfg_attr(target_arch = "wasm32", allow(clippy::arc_with_non_send_sync))]
45
46/// Data exchanged with the server: libraries, medias, movies, series, events...
47pub use rs_plugin_common_interfaces::domain as types;
48
49/// Encryption of encrypted libraries, byte-compatible with the server.
50pub use redseat_crypto as crypto;
51
52pub mod client;
53pub mod cloud;
54pub mod direct;
55pub mod encrypted;
56pub mod error;
57pub mod events;
58pub mod library;
59pub mod server;
60pub mod sse;
61pub mod transport;
62
63#[cfg(feature = "http")]
64pub mod http;
65
66#[cfg(all(feature = "desktop-auth", not(target_arch = "wasm32")))]
67pub mod google;
68
69#[cfg(test)]
70mod test_support;
71
72pub use client::{
73 AuthorizedUrl, ClientOptions, CloudTokenSource, EventOptions, RedseatClient, ServerEventStream,
74 ServerTokenSource,
75};
76pub use cloud::{CloudClient, CloudServer, CloudSession, CloudUser, ServerToken};
77pub use encrypted::EncryptedMediaReader;
78pub use error::{Error, ErrorKind, Result};
79pub use events::ServerEvent;
80pub use library::{LibraryApi, MediaItem, MediaPage};
81pub use server::ServerApi;
82pub use transport::Transport;
83
84#[cfg(test)]
85mod tests {
86 use super::types::library::{LibraryType, ServerLibrary};
87
88 #[test]
89 fn reads_a_library_as_the_server_sends_it() {
90 let library: ServerLibrary = serde_json::from_value(serde_json::json!({
91 "id": "lib1",
92 "name": "Photos",
93 "source": "PathProvider",
94 "type": "photos",
95 "settings": {}
96 }))
97 .unwrap();
98 assert_eq!(library.kind, LibraryType::Photos);
99 }
100}