kick_api/client.rs
1use crate::api::{ChannelsApi, ChatApi, EventsApi, ModerationApi, RewardsApi, UsersApi};
2
3const KICK_BASE_URL: &str = "https://api.kick.com/public/v1";
4
5/// Main Kick API client
6///
7/// # Example
8/// ```no_run
9/// use kick_api::KickApiClient;
10///
11/// // Without authentication (limited endpoints)
12/// let client = KickApiClient::new();
13///
14/// // With OAuth token
15/// let client = KickApiClient::with_token("your_token_here".to_string());
16///
17/// // Use the API modules
18/// let channel = client.channels().get("xqc").await?;
19/// let rewards = client.rewards().get_all().await?;
20/// ```
21#[derive(Debug, Clone)]
22pub struct KickApiClient {
23 base_url: String,
24 client: reqwest::Client,
25 oauth_token: Option<String>,
26}
27
28impl KickApiClient {
29 /// Create a new client without authentication (for public endpoints only)
30 pub fn new() -> Self {
31 KickApiClient {
32 base_url: KICK_BASE_URL.to_string(),
33 client: reqwest::Client::new(),
34 oauth_token: None,
35 }
36 }
37
38 /// Create a client with OAuth authentication
39 ///
40 /// # Parameters
41 /// - `token`: Your OAuth access token from the authorization flow
42 pub fn with_token(token: String) -> Self {
43 KickApiClient {
44 base_url: KICK_BASE_URL.to_string(),
45 client: reqwest::Client::new(),
46 oauth_token: Some(token),
47 }
48 }
49
50 /// Access the Channels API
51 ///
52 /// # Example
53 /// ```no_run
54 /// let channel = client.channels().get("xqc").await?;
55 /// let my_channels = client.channels().get_mine().await?;
56 /// ```
57 pub fn channels(&self) -> ChannelsApi<'_> {
58 ChannelsApi::new(&self.client, &self.oauth_token, &self.base_url)
59 }
60
61 /// Access the Rewards API
62 ///
63 /// # Example
64 /// ```no_run
65 /// let rewards = client.rewards().get_all().await?;
66 /// let reward = client.rewards().create(request).await?;
67 /// ```
68 pub fn rewards(&self) -> RewardsApi<'_> {
69 RewardsApi::new(&self.client, &self.oauth_token, &self.base_url)
70 }
71
72 /// Access the Users API
73 ///
74 /// # Example
75 /// ```no_run
76 /// let me = client.users().get_me().await?;
77 /// let users = client.users().get(vec![123, 456]).await?;
78 /// let token_info = client.users().introspect_token().await?;
79 /// ```
80 pub fn users(&self) -> UsersApi<'_> {
81 UsersApi::new(&self.client, &self.oauth_token, &self.base_url)
82 }
83
84 /// Access the Chat API
85 ///
86 /// # Example
87 /// ```no_run
88 /// let response = client.chat().send_message(request).await?;
89 /// client.chat().delete_message("msg_id").await?;
90 /// ```
91 pub fn chat(&self) -> ChatApi<'_> {
92 ChatApi::new(&self.client, &self.oauth_token, &self.base_url)
93 }
94
95 /// Access the Moderation API
96 ///
97 /// # Example
98 /// ```no_run
99 /// client.moderation().ban(ban_request).await?;
100 /// client.moderation().unban(unban_request).await?;
101 /// ```
102 pub fn moderation(&self) -> ModerationApi<'_> {
103 ModerationApi::new(&self.client, &self.oauth_token, &self.base_url)
104 }
105
106 /// Access the Events/Webhooks API
107 ///
108 /// # Example
109 /// ```no_run
110 /// let subs = client.events().list(None).await?;
111 /// let results = client.events().subscribe(request).await?;
112 /// client.events().unsubscribe(vec!["id".to_string()]).await?;
113 /// ```
114 pub fn events(&self) -> EventsApi<'_> {
115 EventsApi::new(&self.client, &self.oauth_token, &self.base_url)
116 }
117}
118
119impl Default for KickApiClient {
120 fn default() -> Self {
121 Self::new()
122 }
123}