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