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//!
72//! For server-to-server access (no user interaction), use an App Access Token:
73//!
74//! ```no_run
75//! use kick_api::KickOAuth;
76//!
77//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
78//! // Only needs KICK_CLIENT_ID and KICK_CLIENT_SECRET
79//! let oauth = KickOAuth::from_env_server()?;
80//! let token = oauth.get_app_access_token().await?;
81//! let client = kick_api::KickApiClient::with_token(token.access_token);
82//! # Ok(())
83//! # }
84//! ```
85
86mod error;
87mod client;
88mod http;
89mod live_chat;
90mod models;
91mod oauth;
92mod api;
93
94pub use error::{KickApiError, Result};
95pub use client::KickApiClient;
96pub use live_chat::{LiveChatClient, fetch_channel_info};
97pub use models::*;
98pub use oauth::{KickOAuth, OAuthTokenResponse};
99pub use api::{ChannelsApi, ChatApi, EventsApi, LivestreamsApi, ModerationApi, RewardsApi, UsersApi};