Skip to main content

sockudo_http/
lib.rs

1//! Sockudo HTTP API client for Rust
2//!
3//! This library provides a safe, fast, and idiomatic Rust client for the Sockudo HTTP API.
4//!
5//! # Features
6//!
7//! - `rustls-tls` (default): Use rustls for TLS (recommended for cross-compilation)
8//! - `native-tls`: Use native TLS (OpenSSL on Linux, Secure Transport on macOS, SChannel on Windows)
9//! - `encryption` (default): Enable support for end-to-end encrypted channels
10//!
11//! # Cross-Compilation
12//!
13//! This library is designed to work well with cross-compilation. The default features use
14//! pure-Rust dependencies that compile easily to different targets.
15//!
16//! ```bash
17//! # Cross-compile to ARM
18//! cross build --target armv7-unknown-linux-gnueabihf --release
19//! ```
20
21#![cfg_attr(docsrs, feature(doc_cfg))]
22
23pub mod auth;
24pub mod channel;
25pub mod config;
26pub mod errors;
27pub mod events;
28pub mod history;
29pub mod presence_history;
30pub mod push;
31pub mod sockudo;
32pub mod token;
33pub mod util;
34pub mod webhook;
35
36#[macro_use]
37extern crate zeroize;
38
39pub use channel::{Channel, ChannelName, ChannelType};
40pub use config::{Config, ConfigBuilder};
41pub use errors::{RequestError, SockudoError, WebhookError};
42pub use sockudo::Sockudo;
43pub use token::Token;
44pub use webhook::{Webhook, WebhookEvent};
45
46/// Result type alias for Sockudo operations
47pub type Result<T> = std::result::Result<T, SockudoError>;
48
49// Re-export commonly used types
50pub use auth::{SocketAuth, UserAuth};
51pub use events::{BatchEvent, Event, MessageExtras, TriggerParams, generate_idempotency_key};
52pub use history::{
53    AnnotationEventsParams, AnnotationEventsResponse, DeleteAnnotationResponse, GetMessageResponse,
54    HistoryBounds, HistoryContinuity, HistoryItem, HistoryPage, HistoryParams,
55    ListMessageVersionsResponse, MessageVersionsParams, MutationResponse, PublishAnnotationRequest,
56    PublishAnnotationResponse,
57};
58pub use presence_history::{
59    PresenceHistoryBounds, PresenceHistoryContinuity, PresenceHistoryItem, PresenceHistoryPage,
60    PresenceHistoryParams, PresenceSnapshot, PresenceSnapshotMember, PresenceSnapshotParams,
61};
62pub use push::{PushCursorParams, PushSubscriptionParams};
63
64/// Check if encryption support is available at compile time
65pub const ENCRYPTION_AVAILABLE: bool = cfg!(feature = "encryption");
66
67/// Information about the build configuration
68pub struct BuildInfo;
69
70impl BuildInfo {
71    /// Returns whether encryption support is available
72    pub fn has_encryption() -> bool {
73        ENCRYPTION_AVAILABLE
74    }
75
76    /// Returns the TLS backend being used
77    pub fn tls_backend() -> &'static str {
78        if cfg!(feature = "rustls-tls") {
79            "rustls"
80        } else if cfg!(feature = "native-tls") {
81            "native-tls"
82        } else {
83            "none"
84        }
85    }
86
87    /// Returns the encryption backend being used
88    #[cfg(feature = "encryption")]
89    pub fn encryption_backend() -> &'static str {
90        "crypto_secretbox"
91    }
92}
93
94#[cfg(test)]
95mod tests {
96    use super::*;
97
98    #[test]
99    fn test_build_info() {
100        println!("Encryption available: {}", BuildInfo::has_encryption());
101        println!("TLS backend: {}", BuildInfo::tls_backend());
102
103        #[cfg(feature = "encryption")]
104        println!("Encryption backend: {}", BuildInfo::encryption_backend());
105    }
106}