Skip to content

Commit b1f6b29

Browse files
committed
Updating readme
1 parent 4ec892a commit b1f6b29

File tree

1 file changed

+216
-9
lines changed

1 file changed

+216
-9
lines changed

README.md

Lines changed: 216 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,225 @@
1-
# fastcomments-rust
1+
# FastComments Rust SDK
22

3-
Fastcomments Rust SDK
3+
The official Rust SDK for FastComments, a fast and developer-friendly commenting platform. This SDK provides typed API clients and utilities for integrating FastComments into your Rust applications.
44

5-
# Usage
6-
7-
## Client
5+
## Installation
86

97
```bash
10-
cargo add fastcomments-client
8+
cargo add fastcomments-sdk
119
```
1210

13-
## Core
11+
The SDK requires Rust 2021 edition or later.
1412

15-
```bash
16-
cargo add fastcomments-core
13+
## Library Contents
14+
15+
The FastComments Rust SDK consists of several modules:
16+
17+
- **Client Module** - Auto-generated API client for FastComments REST APIs
18+
- Complete type definitions for all API models
19+
- Both authenticated (`DefaultApi`) and public (`PublicApi`) endpoints
20+
- Full async/await support with tokio
21+
- See [client/README.md](client/README.md) for detailed API documentation
22+
23+
- **SSO Module** - Server-side Single Sign-On utilities
24+
- Secure token generation for user authentication
25+
- Support for both simple and secure SSO modes
26+
- HMAC-SHA256 based token signing
27+
28+
- **Core Types** - Shared type definitions and utilities
29+
- Comment models and metadata structures
30+
- User and tenant configurations
31+
- Helper functions for common operations
32+
33+
## Quick Start
34+
35+
### Using the Public API
36+
37+
```rust
38+
use fastcomments_sdk::client::apis::configuration::Configuration;
39+
use fastcomments_sdk::client::apis::public_api;
40+
41+
#[tokio::main]
42+
async fn main() {
43+
// Create API configuration
44+
let config = Configuration::new();
45+
46+
// Fetch comments for a page
47+
let result = public_api::get_comments_public(
48+
&config,
49+
public_api::GetCommentsPublicParams {
50+
tenant_id: "your-tenant-id".to_string(),
51+
urlid: Some("page-url-id".to_string()),
52+
url: None,
53+
count_only: None,
54+
skip: None,
55+
limit: None,
56+
sort_dir: None,
57+
page: None,
58+
sso_hash: None,
59+
simple_sso_hash: None,
60+
has_no_comment: None,
61+
has_comment: None,
62+
comment_id_filter: None,
63+
child_ids: None,
64+
start_date_time: None,
65+
starts_with: None,
66+
},
67+
)
68+
.await;
69+
70+
match result {
71+
Ok(response) => {
72+
println!("Found {} comments", response.comments.len());
73+
for comment in response.comments {
74+
println!("Comment: {:?}", comment);
75+
}
76+
}
77+
Err(e) => eprintln!("Error fetching comments: {:?}", e),
78+
}
79+
}
1780
```
1881

82+
### Using the Authenticated API
83+
84+
```rust
85+
use fastcomments_sdk::client::apis::configuration::{ApiKey, Configuration};
86+
use fastcomments_sdk::client::apis::default_api;
87+
88+
#[tokio::main]
89+
async fn main() {
90+
// Create configuration with API key
91+
let mut config = Configuration::new();
92+
config.api_key = Some(ApiKey {
93+
prefix: None,
94+
key: "your-api-key".to_string(),
95+
});
96+
97+
// Fetch comments using authenticated API
98+
let result = default_api::get_comments(
99+
&config,
100+
default_api::GetCommentsParams {
101+
tenant_id: "your-tenant-id".to_string(),
102+
skip: None,
103+
limit: None,
104+
sort_dir: None,
105+
urlid: Some("page-url-id".to_string()),
106+
url: None,
107+
is_spam: None,
108+
user_id: None,
109+
all_comments: None,
110+
for_moderation: None,
111+
parent_id: None,
112+
is_flagged: None,
113+
is_flagged_tag: None,
114+
is_by_verified: None,
115+
is_pinned: None,
116+
asc: None,
117+
include_imported: None,
118+
origin: None,
119+
tags: None,
120+
},
121+
)
122+
.await;
123+
124+
match result {
125+
Ok(response) => {
126+
println!("Total comments: {}", response.count);
127+
for comment in response.comments {
128+
println!("Comment ID: {}, Text: {}", comment.id, comment.comment);
129+
}
130+
}
131+
Err(e) => eprintln!("Error: {:?}", e),
132+
}
133+
}
134+
```
135+
136+
### Using SSO for Authentication
137+
138+
```rust
139+
use fastcomments_sdk::sso::{
140+
fastcomments_sso::FastCommentsSSO,
141+
secure_sso_user_data::SecureSSOUserData,
142+
};
143+
144+
fn main() {
145+
let api_key = "your-api-key".to_string();
146+
147+
// Create secure SSO user data (server-side only!)
148+
let user_data = SecureSSOUserData::new(
149+
"user-123".to_string(), // User ID
150+
"[email protected]".to_string(), // Email
151+
"John Doe".to_string(), // Username
152+
"https://example.com/avatar.jpg".to_string(), // Avatar URL
153+
);
154+
155+
// Generate SSO token
156+
let sso = FastCommentsSSO::new_secure(api_key, &user_data).unwrap();
157+
let token = sso.create_token().unwrap();
158+
159+
println!("SSO Token: {}", token);
160+
// Pass this token to your frontend for authentication
161+
}
162+
```
163+
164+
## Common Issues
165+
166+
### 401 Unauthorized Errors
167+
168+
If you're getting 401 errors when using the authenticated API:
169+
170+
1. **Check your API key**: Ensure you're using the correct API key from your FastComments dashboard
171+
2. **Verify the tenant ID**: Make sure the tenant ID matches your account
172+
3. **API key format**: The API key should be passed in the Configuration:
173+
174+
```rust
175+
let mut config = Configuration::new();
176+
config.api_key = Some(ApiKey {
177+
prefix: None,
178+
key: "YOUR_API_KEY".to_string(),
179+
});
180+
```
181+
182+
### SSO Token Issues
183+
184+
If SSO tokens aren't working:
185+
186+
1. **Use secure mode for production**: Always use `FastCommentsSSO::new_secure()` with your API key for production
187+
2. **Server-side only**: Generate SSO tokens on your server, never expose your API key to clients
188+
3. **Check user data**: Ensure all required fields (id, email, username) are provided
189+
190+
### Async Runtime Errors
191+
192+
The SDK uses tokio for async operations. Make sure to:
193+
194+
1. Add tokio to your dependencies:
195+
```toml
196+
[dependencies]
197+
tokio = { version = "1", features = ["full"] }
198+
```
199+
200+
2. Use the tokio runtime:
201+
```rust
202+
#[tokio::main]
203+
async fn main() {
204+
// Your async code here
205+
}
206+
```
207+
208+
## Notes
209+
210+
### Broadcast IDs
211+
212+
You'll see you're supposed to pass a `broadcastId` in some API calls. When you receive events, you'll get this ID back, so you know to ignore the event if you plan to optimistically apply changes on the client
213+
(which you'll probably want to do since it offers the best experience). Pass a UUID here. The ID should be unique enough to not occur twice in a browser session.
214+
215+
## Support
216+
217+
For issues, questions, or feature requests:
218+
219+
- GitHub Issues: [https://github.com/fastcomments/fastcomments-rust](https://github.com/fastcomments/fastcomments-rust)
220+
- Documentation: [https://docs.fastcomments.com](https://docs.fastcomments.com)
221+
222+
223+
## License
224+
225+
MIT - See [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)