Skip to main content

kick_api/
lib.rs

1//! # kick-api
2//!
3//! Rust client for the [Kick.com](https://kick.com) API.
4//!
5//! Covers channels, users, chat, moderation, rewards, event subscriptions, and
6//! live chat over WebSocket. Handles OAuth 2.1 (PKCE) authentication and
7//! automatic retry on rate limits (429).
8//!
9//! ## Live Chat (no auth required)
10//!
11//! ```no_run
12//! use kick_api::LiveChatClient;
13//!
14//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
15//! // Connect by username
16//! let mut chat = LiveChatClient::connect_by_username("xqc").await?;
17//!
18//! // Or connect by chatroom ID directly
19//! // let mut chat = LiveChatClient::connect(668).await?;
20//!
21//! while let Some(msg) = chat.next_message().await? {
22//!     println!("{}: {}", msg.sender.username, msg.content);
23//! }
24//! # Ok(())
25//! # }
26//! ```
27//!
28//! ## REST API (requires OAuth token)
29//!
30//! ```no_run
31//! use kick_api::{KickApiClient, SendMessageRequest};
32//!
33//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
34//! let client = KickApiClient::with_token("your_oauth_token".to_string());
35//!
36//! // Channels
37//! let channel = client.channels().get("xqc").await?;
38//!
39//! // Users
40//! let me = client.users().get_me().await?;
41//!
42//! // Chat
43//! let msg = SendMessageRequest {
44//!     r#type: "user".to_string(),
45//!     content: "Hello chat!".to_string(),
46//!     broadcaster_user_id: Some(12345),
47//!     reply_to_message_id: None,
48//! };
49//! client.chat().send_message(msg).await?;
50//! # Ok(())
51//! # }
52//! ```
53//!
54//! ## Authentication
55//!
56//! Kick uses OAuth 2.1 with PKCE. Use [`KickOAuth`] to handle the flow:
57//!
58//! ```no_run
59//! use kick_api::KickOAuth;
60//!
61//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
62//! // Load from KICK_CLIENT_ID, KICK_CLIENT_SECRET, KICK_REDIRECT_URI
63//! let oauth = KickOAuth::from_env()?;
64//! let scopes = vec!["chat:write", "user:read", "channel:read"];
65//! let (auth_url, csrf_token, pkce_verifier) = oauth.get_authorization_url(scopes);
66//! // Send the user to auth_url, then exchange the code:
67//! // let token = oauth.exchange_code(code, pkce_verifier).await?;
68//! # Ok(())
69//! # }
70//! ```
71
72mod error;
73mod client;
74mod http;
75mod live_chat;
76mod models;
77mod oauth;
78mod api;
79
80pub use error::{KickApiError, Result};
81pub use client::KickApiClient;
82pub use live_chat::{LiveChatClient, fetch_channel_info};
83pub use models::*;
84pub use oauth::{KickOAuth, OAuthTokenResponse};
85pub use api::{ChannelsApi, ChatApi, EventsApi, ModerationApi, RewardsApi, UsersApi};