larkrs_client/lib.rs
1//! # larkrs-client
2//!
3//! A Rust client library for the Lark (Feishu) API.
4//!
5//! This library provides a convenient way to interact with Lark (Feishu) APIs,
6//! including authentication, Bitable operations, and bot messaging.
7//!
8//! ## Features
9//!
10//! - Authentication: Tenant access token management with automatic refresh
11//! - Bitable: Read and write operations for Feishu Bitable
12//! - Bot: Send messages and interact with chats
13//!
14//! ## Example
15//!
16//! ```rust,no_run
17//! use larkrs_client::auth::FeishuTokenManager;
18//! use larkrs_client::bot::chat::ChatClient;
19//!
20//! #[tokio::main]
21//! async fn main() -> anyhow::Result<()> {
22//! // Get a token
23//! let token_manager = FeishuTokenManager::new();
24//! let token = token_manager.get_token().await?;
25//!
26//! // Send a message
27//! let client = ChatClient::new();
28//! client.send_text_message("chat_id", "Hello from Rust!").await?;
29//!
30//! Ok(())
31//! }
32//! ```
33
34use serde::{Deserialize, Serialize};
35
36pub mod auth;
37pub mod bitable;
38pub mod bot;
39
40/// Response structure for Lark API calls.
41///
42/// All Lark API responses follow this common structure with a code, message, and data payload.
43#[derive(Debug, Serialize, Deserialize)]
44pub struct LarkApiResponse<T> {
45 /// Status code. 0 indicates success, other values indicate failure.
46 pub code: i32,
47 /// Status message. Empty when successful, error description when failed.
48 pub msg: String,
49 /// The actual response data. This is generic and depends on the specific API call.
50 #[serde(default)]
51 pub data: T,
52}
53
54impl<T> LarkApiResponse<T> {
55 /// Checks if the API call was successful.
56 ///
57 /// Returns `true` if the status code is 0, which indicates success in Lark API.
58 pub fn is_success(&self) -> bool {
59 self.code == 0
60 }
61}