hedgehog_rs/
lib.rs

1//!
2//! This library provides a client to interact with the Posthog API.
3//!
4//! # Example
5//! ```no_run
6//! use hedgehog_rs::client::PosthogClient;
7//! use hedgehog_rs::data::{Event, Person};
8//!
9//! #[tokio::main]
10//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
11//!     // Create a new Posthog client
12//!     let client = PosthogClient::builder()
13//!         .base_url("https://app.posthog.com")
14//!         .api_key("your-api-key")
15//!         .build()?;
16//!
17//!     // Create a new person
18//!     let mut person = Person::builder()
19//!         .distinct_id("12345")
20//!         .property("name", "John Doe")
21//!         .build()?;
22//!
23//!     // Identify the person
24//!     client.enqueue_identify(&person)?;
25//!
26//!     // Capture an event
27//!     Event::builder()
28//!         .name("test event")
29//!         .property("key", "value")
30//!         .build()?
31//!         .enqueue(&person, &client)?;
32//!
33//!     // Record a page view
34//!     client.enqueue_page_view_event(&person, "Test Page")?;
35//!
36//!     // Record a screen view
37//!     client.enqueue_screen_view_event(&person, "Test Screen")?;
38//!
39//!     // Evaluate feature flags
40//!     // Note: we use a mutable reference here so the retrieved feature flags can be stored in the person object,
41//!     //       which the client will automatically include in future events, and so the feature flags can be used
42//!     //       in the application without needing to be fetched again.
43//!     let feature_flags = client.feature_flags(&mut person).await?;
44//!
45//!     // Test a feature flag
46//!     if feature_flags.get_bool_flag("test_feature_flag").unwrap_or(false) {
47//!         println!("Feature flag is enabled");
48//!     } else {
49//!         println!("Feature flag is disabled");
50//!     }
51//!
52//!     // Print a feature flag
53//!     let json_flag = feature_flags.get_json_flag("json_feature_flag");
54//!     if let Some(json_flag) = json_flag {
55//!         println!("JSON feature flag: {:?}", json_flag);
56//!     }
57//!
58//!     Ok(())
59//! }
60//! ```
61
62pub mod client;
63pub mod data;
64pub mod error;