Struct ApiClient

Source
pub struct ApiClient { /* private fields */ }

Implementationsยง

Sourceยง

impl ApiClient

Source

pub fn new(access_token: &str) -> Result<Self>

Examples found in repository?
examples/basic_usage.rs (line 6)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Create API client
6    let client = ApiClient::new("your_access_token_here")?;
7
8    // Get user information
9    match client.get_me().await {
10        Ok(user) => {
11            println!("User: {} ({})", user.name, user.email.unwrap_or_default());
12            println!("User path: {}", user.user_path);
13            println!("Teams: {}", user.teams.len());
14        }
15        Err(e) => {
16            eprintln!("Error getting user info: {}", e);
17        }
18    }
19
20    // Create a new note
21    let note_options = CreateNoteOptions {
22        title: Some("Test Note from Rust".to_string()),
23        content: Some(
24            "# Hello from Rust\n\nThis note was created using the Rust HackMD API client."
25                .to_string(),
26        ),
27        read_permission: None,
28        write_permission: None,
29        comment_permission: None,
30        permalink: None,
31    };
32
33    match client.create_note(&note_options).await {
34        Ok(note) => {
35            println!("Created note: {} (ID: {})", note.note.title, note.note.id);
36
37            // Update note content
38            let updated_content = "# Updated from Rust\n\nThis content has been updated!";
39            match client
40                .update_note_content(&note.note.id, updated_content)
41                .await
42            {
43                Ok(_) => println!("Note content updated successfully"),
44                Err(e) => eprintln!("Error updating note: {}", e),
45            }
46        }
47        Err(e) => {
48            eprintln!("Error creating note: {}", e);
49        }
50    }
51
52    // Get notes list
53    match client.get_note_list().await {
54        Ok(notes) => {
55            println!("Found {} notes", notes.len());
56            for note in notes.iter().take(5) {
57                println!("  - {} ({})", note.title, note.id);
58            }
59        }
60        Err(e) => {
61            eprintln!("Error getting notes: {}", e);
62        }
63    }
64
65    Ok(())
66}
Source

pub fn with_base_url(access_token: &str, base_url: &str) -> Result<Self>

Source

pub fn with_options( access_token: &str, base_url: Option<&str>, options: Option<ApiClientOptions>, ) -> Result<Self>

Examples found in repository?
examples/advanced_usage.rs (lines 16-20)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Example with custom configuration
7    let options = ApiClientOptions {
8        wrap_response_errors: true,
9        timeout: Some(Duration::from_secs(30)),
10        retry_config: Some(RetryConfig {
11            max_retries: 3,
12            base_delay: Duration::from_millis(200),
13        }),
14    };
15
16    let client = ApiClient::with_options(
17        "your_access_token_here",
18        None, // Use default API endpoint
19        Some(options),
20    )?;
21
22    println!("=== HackMD API Client Advanced Example ===\n");
23
24    // 1. Get user information
25    println!("๐Ÿ“‹ Getting user information...");
26    match client.get_me().await {
27        Ok(user) => {
28            println!("โœ… User: {} ({})", user.name, user.email.unwrap_or("no email".to_string()));
29            println!("   Path: {}", user.user_path);
30            println!("   Teams: {}", user.teams.len());
31            for team in &user.teams {
32                println!("     - {} ({})", team.name, team.path);
33            }
34        }
35        Err(e) => {
36            eprintln!("โŒ Error getting user info: {}", e);
37            return Ok(());
38        }
39    }
40
41    println!();
42
43    // 2. Create a new note with various permissions
44    println!("๐Ÿ“ Creating a new note...");
45    let note_options = CreateNoteOptions {
46        title: Some("Advanced Rust Example".to_string()),
47        content: Some("# Advanced HackMD Rust Client Example\n\n## Features\n\n- โœ… Async/await support\n- โœ… Retry mechanism with exponential backoff\n- โœ… Comprehensive error handling\n- โœ… Type-safe API\n\n## Code\n\n```rust\nlet client = ApiClient::new(\"token\")?;\nlet user = client.get_me().await?;\nprintln!(\"Hello, {}!\", user.name);\n```\n\nThis note was created using the Rust HackMD API client! ๐Ÿฆ€".to_string()),
48        read_permission: Some(NotePermissionRole::SignedIn),
49        write_permission: Some(NotePermissionRole::Owner),
50        comment_permission: Some(CommentPermissionType::Owners),
51        permalink: Some(format!("rust-example-{}", chrono::Utc::now().timestamp())),
52    };
53
54    let created_note = match client.create_note(&note_options).await {
55        Ok(note) => {
56            println!("โœ… Created note: {} (ID: {})", note.note.title, note.note.id);
57            println!("   Short ID: {}", note.note.short_id);
58            println!("   Publish Link: {}", note.note.publish_link);
59            note
60        }
61        Err(e) => {
62            eprintln!("โŒ Error creating note: {}", e);
63            return Ok(());
64        }
65    };
66
67    println!();
68
69    // 3. Update the note content
70    println!("โœ๏ธ  Updating note content...");
71    let updated_content = format!(
72        "{}\n\n## Update\n\nThis content was updated at {} using the Rust API client.\n\n### Statistics\n\n- Original content length: {} characters\n- Update timestamp: {}\n- API client: hackmd-api-client-rs v0.1.0",
73        created_note.content,
74        chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
75        created_note.content.len(),
76        chrono::Utc::now().timestamp()
77    );
78
79    match client.update_note_content(&created_note.note.id, &updated_content).await {
80        Ok(_) => println!("โœ… Note content updated successfully"),
81        Err(e) => eprintln!("โŒ Error updating note: {}", e),
82    }
83
84    println!();
85
86    // 4. Update note permissions
87    println!("๐Ÿ”’ Updating note permissions...");
88    let permission_update = UpdateNoteOptions {
89        content: None,
90        read_permission: Some(NotePermissionRole::Guest), // Make it publicly readable
91        write_permission: Some(NotePermissionRole::SignedIn),
92        permalink: None,
93    };
94
95    match client.update_note(&created_note.note.id, &permission_update).await {
96        Ok(_) => println!("โœ… Note permissions updated successfully"),
97        Err(e) => eprintln!("โŒ Error updating permissions: {}", e),
98    }
99
100    println!();
101
102    // 5. Get updated note
103    println!("๐Ÿ” Fetching updated note...");
104    match client.get_note(&created_note.note.id).await {
105        Ok(note) => {
106            println!("โœ… Fetched note: {}", note.note.title);
107            println!("   Content length: {} characters", note.content.len());
108            println!("   Read permission: {:?}", note.note.read_permission);
109            println!("   Write permission: {:?}", note.note.write_permission);
110            println!("   Last changed: {}", note.note.last_changed_at);
111        }
112        Err(e) => eprintln!("โŒ Error fetching note: {}", e),
113    }
114
115    println!();
116
117    // 6. List recent notes
118    println!("๐Ÿ“š Getting note list...");
119    match client.get_note_list().await {
120        Ok(notes) => {
121            println!("โœ… Found {} notes", notes.len());
122            println!("   Recent notes:");
123            for note in notes.iter().take(5) {
124                println!("     - {} ({})", note.title, note.short_id);
125                println!("       Tags: {}", note.tags.join(", "));
126                println!("       Last changed: {}", note.last_changed_at);
127            }
128        }
129        Err(e) => eprintln!("โŒ Error getting notes: {}", e),
130    }
131
132    println!();
133
134    // 7. Get teams and team notes (if any)
135    println!("๐Ÿ‘ฅ Getting teams...");
136    match client.get_teams().await {
137        Ok(teams) => {
138            if teams.is_empty() {
139                println!("โ„น๏ธ  No teams found");
140            } else {
141                println!("โœ… Found {} teams", teams.len());
142                for team in &teams {
143                    println!("   - Team: {} ({})", team.name, team.path);
144                    println!("     Description: {}", team.description);
145                    
146                    // Get team notes
147                    match client.get_team_notes(&team.path).await {
148                        Ok(team_notes) => {
149                            println!("     Notes: {} notes", team_notes.len());
150                            for note in team_notes.iter().take(3) {
151                                println!("       - {}", note.title);
152                            }
153                        }
154                        Err(e) => eprintln!("     โŒ Error getting team notes: {}", e),
155                    }
156                }
157            }
158        }
159        Err(e) => eprintln!("โŒ Error getting teams: {}", e),
160    }
161
162    println!("\n๐ŸŽ‰ Advanced example completed!");
163    println!("   Created note ID: {}", created_note.note.id);
164    println!("   View at: {}", created_note.note.publish_link);
165
166    Ok(())
167}
Source

pub async fn get_me(&self) -> Result<User>

Examples found in repository?
examples/basic_usage.rs (line 9)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Create API client
6    let client = ApiClient::new("your_access_token_here")?;
7
8    // Get user information
9    match client.get_me().await {
10        Ok(user) => {
11            println!("User: {} ({})", user.name, user.email.unwrap_or_default());
12            println!("User path: {}", user.user_path);
13            println!("Teams: {}", user.teams.len());
14        }
15        Err(e) => {
16            eprintln!("Error getting user info: {}", e);
17        }
18    }
19
20    // Create a new note
21    let note_options = CreateNoteOptions {
22        title: Some("Test Note from Rust".to_string()),
23        content: Some(
24            "# Hello from Rust\n\nThis note was created using the Rust HackMD API client."
25                .to_string(),
26        ),
27        read_permission: None,
28        write_permission: None,
29        comment_permission: None,
30        permalink: None,
31    };
32
33    match client.create_note(&note_options).await {
34        Ok(note) => {
35            println!("Created note: {} (ID: {})", note.note.title, note.note.id);
36
37            // Update note content
38            let updated_content = "# Updated from Rust\n\nThis content has been updated!";
39            match client
40                .update_note_content(&note.note.id, updated_content)
41                .await
42            {
43                Ok(_) => println!("Note content updated successfully"),
44                Err(e) => eprintln!("Error updating note: {}", e),
45            }
46        }
47        Err(e) => {
48            eprintln!("Error creating note: {}", e);
49        }
50    }
51
52    // Get notes list
53    match client.get_note_list().await {
54        Ok(notes) => {
55            println!("Found {} notes", notes.len());
56            for note in notes.iter().take(5) {
57                println!("  - {} ({})", note.title, note.id);
58            }
59        }
60        Err(e) => {
61            eprintln!("Error getting notes: {}", e);
62        }
63    }
64
65    Ok(())
66}
More examples
Hide additional examples
examples/advanced_usage.rs (line 26)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Example with custom configuration
7    let options = ApiClientOptions {
8        wrap_response_errors: true,
9        timeout: Some(Duration::from_secs(30)),
10        retry_config: Some(RetryConfig {
11            max_retries: 3,
12            base_delay: Duration::from_millis(200),
13        }),
14    };
15
16    let client = ApiClient::with_options(
17        "your_access_token_here",
18        None, // Use default API endpoint
19        Some(options),
20    )?;
21
22    println!("=== HackMD API Client Advanced Example ===\n");
23
24    // 1. Get user information
25    println!("๐Ÿ“‹ Getting user information...");
26    match client.get_me().await {
27        Ok(user) => {
28            println!("โœ… User: {} ({})", user.name, user.email.unwrap_or("no email".to_string()));
29            println!("   Path: {}", user.user_path);
30            println!("   Teams: {}", user.teams.len());
31            for team in &user.teams {
32                println!("     - {} ({})", team.name, team.path);
33            }
34        }
35        Err(e) => {
36            eprintln!("โŒ Error getting user info: {}", e);
37            return Ok(());
38        }
39    }
40
41    println!();
42
43    // 2. Create a new note with various permissions
44    println!("๐Ÿ“ Creating a new note...");
45    let note_options = CreateNoteOptions {
46        title: Some("Advanced Rust Example".to_string()),
47        content: Some("# Advanced HackMD Rust Client Example\n\n## Features\n\n- โœ… Async/await support\n- โœ… Retry mechanism with exponential backoff\n- โœ… Comprehensive error handling\n- โœ… Type-safe API\n\n## Code\n\n```rust\nlet client = ApiClient::new(\"token\")?;\nlet user = client.get_me().await?;\nprintln!(\"Hello, {}!\", user.name);\n```\n\nThis note was created using the Rust HackMD API client! ๐Ÿฆ€".to_string()),
48        read_permission: Some(NotePermissionRole::SignedIn),
49        write_permission: Some(NotePermissionRole::Owner),
50        comment_permission: Some(CommentPermissionType::Owners),
51        permalink: Some(format!("rust-example-{}", chrono::Utc::now().timestamp())),
52    };
53
54    let created_note = match client.create_note(&note_options).await {
55        Ok(note) => {
56            println!("โœ… Created note: {} (ID: {})", note.note.title, note.note.id);
57            println!("   Short ID: {}", note.note.short_id);
58            println!("   Publish Link: {}", note.note.publish_link);
59            note
60        }
61        Err(e) => {
62            eprintln!("โŒ Error creating note: {}", e);
63            return Ok(());
64        }
65    };
66
67    println!();
68
69    // 3. Update the note content
70    println!("โœ๏ธ  Updating note content...");
71    let updated_content = format!(
72        "{}\n\n## Update\n\nThis content was updated at {} using the Rust API client.\n\n### Statistics\n\n- Original content length: {} characters\n- Update timestamp: {}\n- API client: hackmd-api-client-rs v0.1.0",
73        created_note.content,
74        chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
75        created_note.content.len(),
76        chrono::Utc::now().timestamp()
77    );
78
79    match client.update_note_content(&created_note.note.id, &updated_content).await {
80        Ok(_) => println!("โœ… Note content updated successfully"),
81        Err(e) => eprintln!("โŒ Error updating note: {}", e),
82    }
83
84    println!();
85
86    // 4. Update note permissions
87    println!("๐Ÿ”’ Updating note permissions...");
88    let permission_update = UpdateNoteOptions {
89        content: None,
90        read_permission: Some(NotePermissionRole::Guest), // Make it publicly readable
91        write_permission: Some(NotePermissionRole::SignedIn),
92        permalink: None,
93    };
94
95    match client.update_note(&created_note.note.id, &permission_update).await {
96        Ok(_) => println!("โœ… Note permissions updated successfully"),
97        Err(e) => eprintln!("โŒ Error updating permissions: {}", e),
98    }
99
100    println!();
101
102    // 5. Get updated note
103    println!("๐Ÿ” Fetching updated note...");
104    match client.get_note(&created_note.note.id).await {
105        Ok(note) => {
106            println!("โœ… Fetched note: {}", note.note.title);
107            println!("   Content length: {} characters", note.content.len());
108            println!("   Read permission: {:?}", note.note.read_permission);
109            println!("   Write permission: {:?}", note.note.write_permission);
110            println!("   Last changed: {}", note.note.last_changed_at);
111        }
112        Err(e) => eprintln!("โŒ Error fetching note: {}", e),
113    }
114
115    println!();
116
117    // 6. List recent notes
118    println!("๐Ÿ“š Getting note list...");
119    match client.get_note_list().await {
120        Ok(notes) => {
121            println!("โœ… Found {} notes", notes.len());
122            println!("   Recent notes:");
123            for note in notes.iter().take(5) {
124                println!("     - {} ({})", note.title, note.short_id);
125                println!("       Tags: {}", note.tags.join(", "));
126                println!("       Last changed: {}", note.last_changed_at);
127            }
128        }
129        Err(e) => eprintln!("โŒ Error getting notes: {}", e),
130    }
131
132    println!();
133
134    // 7. Get teams and team notes (if any)
135    println!("๐Ÿ‘ฅ Getting teams...");
136    match client.get_teams().await {
137        Ok(teams) => {
138            if teams.is_empty() {
139                println!("โ„น๏ธ  No teams found");
140            } else {
141                println!("โœ… Found {} teams", teams.len());
142                for team in &teams {
143                    println!("   - Team: {} ({})", team.name, team.path);
144                    println!("     Description: {}", team.description);
145                    
146                    // Get team notes
147                    match client.get_team_notes(&team.path).await {
148                        Ok(team_notes) => {
149                            println!("     Notes: {} notes", team_notes.len());
150                            for note in team_notes.iter().take(3) {
151                                println!("       - {}", note.title);
152                            }
153                        }
154                        Err(e) => eprintln!("     โŒ Error getting team notes: {}", e),
155                    }
156                }
157            }
158        }
159        Err(e) => eprintln!("โŒ Error getting teams: {}", e),
160    }
161
162    println!("\n๐ŸŽ‰ Advanced example completed!");
163    println!("   Created note ID: {}", created_note.note.id);
164    println!("   View at: {}", created_note.note.publish_link);
165
166    Ok(())
167}
Source

pub async fn get_history(&self) -> Result<Vec<Note>>

Source

pub async fn get_note_list(&self) -> Result<Vec<Note>>

Examples found in repository?
examples/basic_usage.rs (line 53)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Create API client
6    let client = ApiClient::new("your_access_token_here")?;
7
8    // Get user information
9    match client.get_me().await {
10        Ok(user) => {
11            println!("User: {} ({})", user.name, user.email.unwrap_or_default());
12            println!("User path: {}", user.user_path);
13            println!("Teams: {}", user.teams.len());
14        }
15        Err(e) => {
16            eprintln!("Error getting user info: {}", e);
17        }
18    }
19
20    // Create a new note
21    let note_options = CreateNoteOptions {
22        title: Some("Test Note from Rust".to_string()),
23        content: Some(
24            "# Hello from Rust\n\nThis note was created using the Rust HackMD API client."
25                .to_string(),
26        ),
27        read_permission: None,
28        write_permission: None,
29        comment_permission: None,
30        permalink: None,
31    };
32
33    match client.create_note(&note_options).await {
34        Ok(note) => {
35            println!("Created note: {} (ID: {})", note.note.title, note.note.id);
36
37            // Update note content
38            let updated_content = "# Updated from Rust\n\nThis content has been updated!";
39            match client
40                .update_note_content(&note.note.id, updated_content)
41                .await
42            {
43                Ok(_) => println!("Note content updated successfully"),
44                Err(e) => eprintln!("Error updating note: {}", e),
45            }
46        }
47        Err(e) => {
48            eprintln!("Error creating note: {}", e);
49        }
50    }
51
52    // Get notes list
53    match client.get_note_list().await {
54        Ok(notes) => {
55            println!("Found {} notes", notes.len());
56            for note in notes.iter().take(5) {
57                println!("  - {} ({})", note.title, note.id);
58            }
59        }
60        Err(e) => {
61            eprintln!("Error getting notes: {}", e);
62        }
63    }
64
65    Ok(())
66}
More examples
Hide additional examples
examples/advanced_usage.rs (line 119)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Example with custom configuration
7    let options = ApiClientOptions {
8        wrap_response_errors: true,
9        timeout: Some(Duration::from_secs(30)),
10        retry_config: Some(RetryConfig {
11            max_retries: 3,
12            base_delay: Duration::from_millis(200),
13        }),
14    };
15
16    let client = ApiClient::with_options(
17        "your_access_token_here",
18        None, // Use default API endpoint
19        Some(options),
20    )?;
21
22    println!("=== HackMD API Client Advanced Example ===\n");
23
24    // 1. Get user information
25    println!("๐Ÿ“‹ Getting user information...");
26    match client.get_me().await {
27        Ok(user) => {
28            println!("โœ… User: {} ({})", user.name, user.email.unwrap_or("no email".to_string()));
29            println!("   Path: {}", user.user_path);
30            println!("   Teams: {}", user.teams.len());
31            for team in &user.teams {
32                println!("     - {} ({})", team.name, team.path);
33            }
34        }
35        Err(e) => {
36            eprintln!("โŒ Error getting user info: {}", e);
37            return Ok(());
38        }
39    }
40
41    println!();
42
43    // 2. Create a new note with various permissions
44    println!("๐Ÿ“ Creating a new note...");
45    let note_options = CreateNoteOptions {
46        title: Some("Advanced Rust Example".to_string()),
47        content: Some("# Advanced HackMD Rust Client Example\n\n## Features\n\n- โœ… Async/await support\n- โœ… Retry mechanism with exponential backoff\n- โœ… Comprehensive error handling\n- โœ… Type-safe API\n\n## Code\n\n```rust\nlet client = ApiClient::new(\"token\")?;\nlet user = client.get_me().await?;\nprintln!(\"Hello, {}!\", user.name);\n```\n\nThis note was created using the Rust HackMD API client! ๐Ÿฆ€".to_string()),
48        read_permission: Some(NotePermissionRole::SignedIn),
49        write_permission: Some(NotePermissionRole::Owner),
50        comment_permission: Some(CommentPermissionType::Owners),
51        permalink: Some(format!("rust-example-{}", chrono::Utc::now().timestamp())),
52    };
53
54    let created_note = match client.create_note(&note_options).await {
55        Ok(note) => {
56            println!("โœ… Created note: {} (ID: {})", note.note.title, note.note.id);
57            println!("   Short ID: {}", note.note.short_id);
58            println!("   Publish Link: {}", note.note.publish_link);
59            note
60        }
61        Err(e) => {
62            eprintln!("โŒ Error creating note: {}", e);
63            return Ok(());
64        }
65    };
66
67    println!();
68
69    // 3. Update the note content
70    println!("โœ๏ธ  Updating note content...");
71    let updated_content = format!(
72        "{}\n\n## Update\n\nThis content was updated at {} using the Rust API client.\n\n### Statistics\n\n- Original content length: {} characters\n- Update timestamp: {}\n- API client: hackmd-api-client-rs v0.1.0",
73        created_note.content,
74        chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
75        created_note.content.len(),
76        chrono::Utc::now().timestamp()
77    );
78
79    match client.update_note_content(&created_note.note.id, &updated_content).await {
80        Ok(_) => println!("โœ… Note content updated successfully"),
81        Err(e) => eprintln!("โŒ Error updating note: {}", e),
82    }
83
84    println!();
85
86    // 4. Update note permissions
87    println!("๐Ÿ”’ Updating note permissions...");
88    let permission_update = UpdateNoteOptions {
89        content: None,
90        read_permission: Some(NotePermissionRole::Guest), // Make it publicly readable
91        write_permission: Some(NotePermissionRole::SignedIn),
92        permalink: None,
93    };
94
95    match client.update_note(&created_note.note.id, &permission_update).await {
96        Ok(_) => println!("โœ… Note permissions updated successfully"),
97        Err(e) => eprintln!("โŒ Error updating permissions: {}", e),
98    }
99
100    println!();
101
102    // 5. Get updated note
103    println!("๐Ÿ” Fetching updated note...");
104    match client.get_note(&created_note.note.id).await {
105        Ok(note) => {
106            println!("โœ… Fetched note: {}", note.note.title);
107            println!("   Content length: {} characters", note.content.len());
108            println!("   Read permission: {:?}", note.note.read_permission);
109            println!("   Write permission: {:?}", note.note.write_permission);
110            println!("   Last changed: {}", note.note.last_changed_at);
111        }
112        Err(e) => eprintln!("โŒ Error fetching note: {}", e),
113    }
114
115    println!();
116
117    // 6. List recent notes
118    println!("๐Ÿ“š Getting note list...");
119    match client.get_note_list().await {
120        Ok(notes) => {
121            println!("โœ… Found {} notes", notes.len());
122            println!("   Recent notes:");
123            for note in notes.iter().take(5) {
124                println!("     - {} ({})", note.title, note.short_id);
125                println!("       Tags: {}", note.tags.join(", "));
126                println!("       Last changed: {}", note.last_changed_at);
127            }
128        }
129        Err(e) => eprintln!("โŒ Error getting notes: {}", e),
130    }
131
132    println!();
133
134    // 7. Get teams and team notes (if any)
135    println!("๐Ÿ‘ฅ Getting teams...");
136    match client.get_teams().await {
137        Ok(teams) => {
138            if teams.is_empty() {
139                println!("โ„น๏ธ  No teams found");
140            } else {
141                println!("โœ… Found {} teams", teams.len());
142                for team in &teams {
143                    println!("   - Team: {} ({})", team.name, team.path);
144                    println!("     Description: {}", team.description);
145                    
146                    // Get team notes
147                    match client.get_team_notes(&team.path).await {
148                        Ok(team_notes) => {
149                            println!("     Notes: {} notes", team_notes.len());
150                            for note in team_notes.iter().take(3) {
151                                println!("       - {}", note.title);
152                            }
153                        }
154                        Err(e) => eprintln!("     โŒ Error getting team notes: {}", e),
155                    }
156                }
157            }
158        }
159        Err(e) => eprintln!("โŒ Error getting teams: {}", e),
160    }
161
162    println!("\n๐ŸŽ‰ Advanced example completed!");
163    println!("   Created note ID: {}", created_note.note.id);
164    println!("   View at: {}", created_note.note.publish_link);
165
166    Ok(())
167}
Source

pub async fn get_note(&self, note_id: &str) -> Result<SingleNote>

Examples found in repository?
examples/advanced_usage.rs (line 104)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Example with custom configuration
7    let options = ApiClientOptions {
8        wrap_response_errors: true,
9        timeout: Some(Duration::from_secs(30)),
10        retry_config: Some(RetryConfig {
11            max_retries: 3,
12            base_delay: Duration::from_millis(200),
13        }),
14    };
15
16    let client = ApiClient::with_options(
17        "your_access_token_here",
18        None, // Use default API endpoint
19        Some(options),
20    )?;
21
22    println!("=== HackMD API Client Advanced Example ===\n");
23
24    // 1. Get user information
25    println!("๐Ÿ“‹ Getting user information...");
26    match client.get_me().await {
27        Ok(user) => {
28            println!("โœ… User: {} ({})", user.name, user.email.unwrap_or("no email".to_string()));
29            println!("   Path: {}", user.user_path);
30            println!("   Teams: {}", user.teams.len());
31            for team in &user.teams {
32                println!("     - {} ({})", team.name, team.path);
33            }
34        }
35        Err(e) => {
36            eprintln!("โŒ Error getting user info: {}", e);
37            return Ok(());
38        }
39    }
40
41    println!();
42
43    // 2. Create a new note with various permissions
44    println!("๐Ÿ“ Creating a new note...");
45    let note_options = CreateNoteOptions {
46        title: Some("Advanced Rust Example".to_string()),
47        content: Some("# Advanced HackMD Rust Client Example\n\n## Features\n\n- โœ… Async/await support\n- โœ… Retry mechanism with exponential backoff\n- โœ… Comprehensive error handling\n- โœ… Type-safe API\n\n## Code\n\n```rust\nlet client = ApiClient::new(\"token\")?;\nlet user = client.get_me().await?;\nprintln!(\"Hello, {}!\", user.name);\n```\n\nThis note was created using the Rust HackMD API client! ๐Ÿฆ€".to_string()),
48        read_permission: Some(NotePermissionRole::SignedIn),
49        write_permission: Some(NotePermissionRole::Owner),
50        comment_permission: Some(CommentPermissionType::Owners),
51        permalink: Some(format!("rust-example-{}", chrono::Utc::now().timestamp())),
52    };
53
54    let created_note = match client.create_note(&note_options).await {
55        Ok(note) => {
56            println!("โœ… Created note: {} (ID: {})", note.note.title, note.note.id);
57            println!("   Short ID: {}", note.note.short_id);
58            println!("   Publish Link: {}", note.note.publish_link);
59            note
60        }
61        Err(e) => {
62            eprintln!("โŒ Error creating note: {}", e);
63            return Ok(());
64        }
65    };
66
67    println!();
68
69    // 3. Update the note content
70    println!("โœ๏ธ  Updating note content...");
71    let updated_content = format!(
72        "{}\n\n## Update\n\nThis content was updated at {} using the Rust API client.\n\n### Statistics\n\n- Original content length: {} characters\n- Update timestamp: {}\n- API client: hackmd-api-client-rs v0.1.0",
73        created_note.content,
74        chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
75        created_note.content.len(),
76        chrono::Utc::now().timestamp()
77    );
78
79    match client.update_note_content(&created_note.note.id, &updated_content).await {
80        Ok(_) => println!("โœ… Note content updated successfully"),
81        Err(e) => eprintln!("โŒ Error updating note: {}", e),
82    }
83
84    println!();
85
86    // 4. Update note permissions
87    println!("๐Ÿ”’ Updating note permissions...");
88    let permission_update = UpdateNoteOptions {
89        content: None,
90        read_permission: Some(NotePermissionRole::Guest), // Make it publicly readable
91        write_permission: Some(NotePermissionRole::SignedIn),
92        permalink: None,
93    };
94
95    match client.update_note(&created_note.note.id, &permission_update).await {
96        Ok(_) => println!("โœ… Note permissions updated successfully"),
97        Err(e) => eprintln!("โŒ Error updating permissions: {}", e),
98    }
99
100    println!();
101
102    // 5. Get updated note
103    println!("๐Ÿ” Fetching updated note...");
104    match client.get_note(&created_note.note.id).await {
105        Ok(note) => {
106            println!("โœ… Fetched note: {}", note.note.title);
107            println!("   Content length: {} characters", note.content.len());
108            println!("   Read permission: {:?}", note.note.read_permission);
109            println!("   Write permission: {:?}", note.note.write_permission);
110            println!("   Last changed: {}", note.note.last_changed_at);
111        }
112        Err(e) => eprintln!("โŒ Error fetching note: {}", e),
113    }
114
115    println!();
116
117    // 6. List recent notes
118    println!("๐Ÿ“š Getting note list...");
119    match client.get_note_list().await {
120        Ok(notes) => {
121            println!("โœ… Found {} notes", notes.len());
122            println!("   Recent notes:");
123            for note in notes.iter().take(5) {
124                println!("     - {} ({})", note.title, note.short_id);
125                println!("       Tags: {}", note.tags.join(", "));
126                println!("       Last changed: {}", note.last_changed_at);
127            }
128        }
129        Err(e) => eprintln!("โŒ Error getting notes: {}", e),
130    }
131
132    println!();
133
134    // 7. Get teams and team notes (if any)
135    println!("๐Ÿ‘ฅ Getting teams...");
136    match client.get_teams().await {
137        Ok(teams) => {
138            if teams.is_empty() {
139                println!("โ„น๏ธ  No teams found");
140            } else {
141                println!("โœ… Found {} teams", teams.len());
142                for team in &teams {
143                    println!("   - Team: {} ({})", team.name, team.path);
144                    println!("     Description: {}", team.description);
145                    
146                    // Get team notes
147                    match client.get_team_notes(&team.path).await {
148                        Ok(team_notes) => {
149                            println!("     Notes: {} notes", team_notes.len());
150                            for note in team_notes.iter().take(3) {
151                                println!("       - {}", note.title);
152                            }
153                        }
154                        Err(e) => eprintln!("     โŒ Error getting team notes: {}", e),
155                    }
156                }
157            }
158        }
159        Err(e) => eprintln!("โŒ Error getting teams: {}", e),
160    }
161
162    println!("\n๐ŸŽ‰ Advanced example completed!");
163    println!("   Created note ID: {}", created_note.note.id);
164    println!("   View at: {}", created_note.note.publish_link);
165
166    Ok(())
167}
Source

pub async fn create_note( &self, payload: &CreateNoteOptions, ) -> Result<SingleNote>

Examples found in repository?
examples/basic_usage.rs (line 33)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Create API client
6    let client = ApiClient::new("your_access_token_here")?;
7
8    // Get user information
9    match client.get_me().await {
10        Ok(user) => {
11            println!("User: {} ({})", user.name, user.email.unwrap_or_default());
12            println!("User path: {}", user.user_path);
13            println!("Teams: {}", user.teams.len());
14        }
15        Err(e) => {
16            eprintln!("Error getting user info: {}", e);
17        }
18    }
19
20    // Create a new note
21    let note_options = CreateNoteOptions {
22        title: Some("Test Note from Rust".to_string()),
23        content: Some(
24            "# Hello from Rust\n\nThis note was created using the Rust HackMD API client."
25                .to_string(),
26        ),
27        read_permission: None,
28        write_permission: None,
29        comment_permission: None,
30        permalink: None,
31    };
32
33    match client.create_note(&note_options).await {
34        Ok(note) => {
35            println!("Created note: {} (ID: {})", note.note.title, note.note.id);
36
37            // Update note content
38            let updated_content = "# Updated from Rust\n\nThis content has been updated!";
39            match client
40                .update_note_content(&note.note.id, updated_content)
41                .await
42            {
43                Ok(_) => println!("Note content updated successfully"),
44                Err(e) => eprintln!("Error updating note: {}", e),
45            }
46        }
47        Err(e) => {
48            eprintln!("Error creating note: {}", e);
49        }
50    }
51
52    // Get notes list
53    match client.get_note_list().await {
54        Ok(notes) => {
55            println!("Found {} notes", notes.len());
56            for note in notes.iter().take(5) {
57                println!("  - {} ({})", note.title, note.id);
58            }
59        }
60        Err(e) => {
61            eprintln!("Error getting notes: {}", e);
62        }
63    }
64
65    Ok(())
66}
More examples
Hide additional examples
examples/advanced_usage.rs (line 54)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Example with custom configuration
7    let options = ApiClientOptions {
8        wrap_response_errors: true,
9        timeout: Some(Duration::from_secs(30)),
10        retry_config: Some(RetryConfig {
11            max_retries: 3,
12            base_delay: Duration::from_millis(200),
13        }),
14    };
15
16    let client = ApiClient::with_options(
17        "your_access_token_here",
18        None, // Use default API endpoint
19        Some(options),
20    )?;
21
22    println!("=== HackMD API Client Advanced Example ===\n");
23
24    // 1. Get user information
25    println!("๐Ÿ“‹ Getting user information...");
26    match client.get_me().await {
27        Ok(user) => {
28            println!("โœ… User: {} ({})", user.name, user.email.unwrap_or("no email".to_string()));
29            println!("   Path: {}", user.user_path);
30            println!("   Teams: {}", user.teams.len());
31            for team in &user.teams {
32                println!("     - {} ({})", team.name, team.path);
33            }
34        }
35        Err(e) => {
36            eprintln!("โŒ Error getting user info: {}", e);
37            return Ok(());
38        }
39    }
40
41    println!();
42
43    // 2. Create a new note with various permissions
44    println!("๐Ÿ“ Creating a new note...");
45    let note_options = CreateNoteOptions {
46        title: Some("Advanced Rust Example".to_string()),
47        content: Some("# Advanced HackMD Rust Client Example\n\n## Features\n\n- โœ… Async/await support\n- โœ… Retry mechanism with exponential backoff\n- โœ… Comprehensive error handling\n- โœ… Type-safe API\n\n## Code\n\n```rust\nlet client = ApiClient::new(\"token\")?;\nlet user = client.get_me().await?;\nprintln!(\"Hello, {}!\", user.name);\n```\n\nThis note was created using the Rust HackMD API client! ๐Ÿฆ€".to_string()),
48        read_permission: Some(NotePermissionRole::SignedIn),
49        write_permission: Some(NotePermissionRole::Owner),
50        comment_permission: Some(CommentPermissionType::Owners),
51        permalink: Some(format!("rust-example-{}", chrono::Utc::now().timestamp())),
52    };
53
54    let created_note = match client.create_note(&note_options).await {
55        Ok(note) => {
56            println!("โœ… Created note: {} (ID: {})", note.note.title, note.note.id);
57            println!("   Short ID: {}", note.note.short_id);
58            println!("   Publish Link: {}", note.note.publish_link);
59            note
60        }
61        Err(e) => {
62            eprintln!("โŒ Error creating note: {}", e);
63            return Ok(());
64        }
65    };
66
67    println!();
68
69    // 3. Update the note content
70    println!("โœ๏ธ  Updating note content...");
71    let updated_content = format!(
72        "{}\n\n## Update\n\nThis content was updated at {} using the Rust API client.\n\n### Statistics\n\n- Original content length: {} characters\n- Update timestamp: {}\n- API client: hackmd-api-client-rs v0.1.0",
73        created_note.content,
74        chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
75        created_note.content.len(),
76        chrono::Utc::now().timestamp()
77    );
78
79    match client.update_note_content(&created_note.note.id, &updated_content).await {
80        Ok(_) => println!("โœ… Note content updated successfully"),
81        Err(e) => eprintln!("โŒ Error updating note: {}", e),
82    }
83
84    println!();
85
86    // 4. Update note permissions
87    println!("๐Ÿ”’ Updating note permissions...");
88    let permission_update = UpdateNoteOptions {
89        content: None,
90        read_permission: Some(NotePermissionRole::Guest), // Make it publicly readable
91        write_permission: Some(NotePermissionRole::SignedIn),
92        permalink: None,
93    };
94
95    match client.update_note(&created_note.note.id, &permission_update).await {
96        Ok(_) => println!("โœ… Note permissions updated successfully"),
97        Err(e) => eprintln!("โŒ Error updating permissions: {}", e),
98    }
99
100    println!();
101
102    // 5. Get updated note
103    println!("๐Ÿ” Fetching updated note...");
104    match client.get_note(&created_note.note.id).await {
105        Ok(note) => {
106            println!("โœ… Fetched note: {}", note.note.title);
107            println!("   Content length: {} characters", note.content.len());
108            println!("   Read permission: {:?}", note.note.read_permission);
109            println!("   Write permission: {:?}", note.note.write_permission);
110            println!("   Last changed: {}", note.note.last_changed_at);
111        }
112        Err(e) => eprintln!("โŒ Error fetching note: {}", e),
113    }
114
115    println!();
116
117    // 6. List recent notes
118    println!("๐Ÿ“š Getting note list...");
119    match client.get_note_list().await {
120        Ok(notes) => {
121            println!("โœ… Found {} notes", notes.len());
122            println!("   Recent notes:");
123            for note in notes.iter().take(5) {
124                println!("     - {} ({})", note.title, note.short_id);
125                println!("       Tags: {}", note.tags.join(", "));
126                println!("       Last changed: {}", note.last_changed_at);
127            }
128        }
129        Err(e) => eprintln!("โŒ Error getting notes: {}", e),
130    }
131
132    println!();
133
134    // 7. Get teams and team notes (if any)
135    println!("๐Ÿ‘ฅ Getting teams...");
136    match client.get_teams().await {
137        Ok(teams) => {
138            if teams.is_empty() {
139                println!("โ„น๏ธ  No teams found");
140            } else {
141                println!("โœ… Found {} teams", teams.len());
142                for team in &teams {
143                    println!("   - Team: {} ({})", team.name, team.path);
144                    println!("     Description: {}", team.description);
145                    
146                    // Get team notes
147                    match client.get_team_notes(&team.path).await {
148                        Ok(team_notes) => {
149                            println!("     Notes: {} notes", team_notes.len());
150                            for note in team_notes.iter().take(3) {
151                                println!("       - {}", note.title);
152                            }
153                        }
154                        Err(e) => eprintln!("     โŒ Error getting team notes: {}", e),
155                    }
156                }
157            }
158        }
159        Err(e) => eprintln!("โŒ Error getting teams: {}", e),
160    }
161
162    println!("\n๐ŸŽ‰ Advanced example completed!");
163    println!("   Created note ID: {}", created_note.note.id);
164    println!("   View at: {}", created_note.note.publish_link);
165
166    Ok(())
167}
Source

pub async fn update_note_content( &self, note_id: &str, content: &str, ) -> Result<SingleNote>

Examples found in repository?
examples/basic_usage.rs (line 40)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Create API client
6    let client = ApiClient::new("your_access_token_here")?;
7
8    // Get user information
9    match client.get_me().await {
10        Ok(user) => {
11            println!("User: {} ({})", user.name, user.email.unwrap_or_default());
12            println!("User path: {}", user.user_path);
13            println!("Teams: {}", user.teams.len());
14        }
15        Err(e) => {
16            eprintln!("Error getting user info: {}", e);
17        }
18    }
19
20    // Create a new note
21    let note_options = CreateNoteOptions {
22        title: Some("Test Note from Rust".to_string()),
23        content: Some(
24            "# Hello from Rust\n\nThis note was created using the Rust HackMD API client."
25                .to_string(),
26        ),
27        read_permission: None,
28        write_permission: None,
29        comment_permission: None,
30        permalink: None,
31    };
32
33    match client.create_note(&note_options).await {
34        Ok(note) => {
35            println!("Created note: {} (ID: {})", note.note.title, note.note.id);
36
37            // Update note content
38            let updated_content = "# Updated from Rust\n\nThis content has been updated!";
39            match client
40                .update_note_content(&note.note.id, updated_content)
41                .await
42            {
43                Ok(_) => println!("Note content updated successfully"),
44                Err(e) => eprintln!("Error updating note: {}", e),
45            }
46        }
47        Err(e) => {
48            eprintln!("Error creating note: {}", e);
49        }
50    }
51
52    // Get notes list
53    match client.get_note_list().await {
54        Ok(notes) => {
55            println!("Found {} notes", notes.len());
56            for note in notes.iter().take(5) {
57                println!("  - {} ({})", note.title, note.id);
58            }
59        }
60        Err(e) => {
61            eprintln!("Error getting notes: {}", e);
62        }
63    }
64
65    Ok(())
66}
More examples
Hide additional examples
examples/advanced_usage.rs (line 79)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Example with custom configuration
7    let options = ApiClientOptions {
8        wrap_response_errors: true,
9        timeout: Some(Duration::from_secs(30)),
10        retry_config: Some(RetryConfig {
11            max_retries: 3,
12            base_delay: Duration::from_millis(200),
13        }),
14    };
15
16    let client = ApiClient::with_options(
17        "your_access_token_here",
18        None, // Use default API endpoint
19        Some(options),
20    )?;
21
22    println!("=== HackMD API Client Advanced Example ===\n");
23
24    // 1. Get user information
25    println!("๐Ÿ“‹ Getting user information...");
26    match client.get_me().await {
27        Ok(user) => {
28            println!("โœ… User: {} ({})", user.name, user.email.unwrap_or("no email".to_string()));
29            println!("   Path: {}", user.user_path);
30            println!("   Teams: {}", user.teams.len());
31            for team in &user.teams {
32                println!("     - {} ({})", team.name, team.path);
33            }
34        }
35        Err(e) => {
36            eprintln!("โŒ Error getting user info: {}", e);
37            return Ok(());
38        }
39    }
40
41    println!();
42
43    // 2. Create a new note with various permissions
44    println!("๐Ÿ“ Creating a new note...");
45    let note_options = CreateNoteOptions {
46        title: Some("Advanced Rust Example".to_string()),
47        content: Some("# Advanced HackMD Rust Client Example\n\n## Features\n\n- โœ… Async/await support\n- โœ… Retry mechanism with exponential backoff\n- โœ… Comprehensive error handling\n- โœ… Type-safe API\n\n## Code\n\n```rust\nlet client = ApiClient::new(\"token\")?;\nlet user = client.get_me().await?;\nprintln!(\"Hello, {}!\", user.name);\n```\n\nThis note was created using the Rust HackMD API client! ๐Ÿฆ€".to_string()),
48        read_permission: Some(NotePermissionRole::SignedIn),
49        write_permission: Some(NotePermissionRole::Owner),
50        comment_permission: Some(CommentPermissionType::Owners),
51        permalink: Some(format!("rust-example-{}", chrono::Utc::now().timestamp())),
52    };
53
54    let created_note = match client.create_note(&note_options).await {
55        Ok(note) => {
56            println!("โœ… Created note: {} (ID: {})", note.note.title, note.note.id);
57            println!("   Short ID: {}", note.note.short_id);
58            println!("   Publish Link: {}", note.note.publish_link);
59            note
60        }
61        Err(e) => {
62            eprintln!("โŒ Error creating note: {}", e);
63            return Ok(());
64        }
65    };
66
67    println!();
68
69    // 3. Update the note content
70    println!("โœ๏ธ  Updating note content...");
71    let updated_content = format!(
72        "{}\n\n## Update\n\nThis content was updated at {} using the Rust API client.\n\n### Statistics\n\n- Original content length: {} characters\n- Update timestamp: {}\n- API client: hackmd-api-client-rs v0.1.0",
73        created_note.content,
74        chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
75        created_note.content.len(),
76        chrono::Utc::now().timestamp()
77    );
78
79    match client.update_note_content(&created_note.note.id, &updated_content).await {
80        Ok(_) => println!("โœ… Note content updated successfully"),
81        Err(e) => eprintln!("โŒ Error updating note: {}", e),
82    }
83
84    println!();
85
86    // 4. Update note permissions
87    println!("๐Ÿ”’ Updating note permissions...");
88    let permission_update = UpdateNoteOptions {
89        content: None,
90        read_permission: Some(NotePermissionRole::Guest), // Make it publicly readable
91        write_permission: Some(NotePermissionRole::SignedIn),
92        permalink: None,
93    };
94
95    match client.update_note(&created_note.note.id, &permission_update).await {
96        Ok(_) => println!("โœ… Note permissions updated successfully"),
97        Err(e) => eprintln!("โŒ Error updating permissions: {}", e),
98    }
99
100    println!();
101
102    // 5. Get updated note
103    println!("๐Ÿ” Fetching updated note...");
104    match client.get_note(&created_note.note.id).await {
105        Ok(note) => {
106            println!("โœ… Fetched note: {}", note.note.title);
107            println!("   Content length: {} characters", note.content.len());
108            println!("   Read permission: {:?}", note.note.read_permission);
109            println!("   Write permission: {:?}", note.note.write_permission);
110            println!("   Last changed: {}", note.note.last_changed_at);
111        }
112        Err(e) => eprintln!("โŒ Error fetching note: {}", e),
113    }
114
115    println!();
116
117    // 6. List recent notes
118    println!("๐Ÿ“š Getting note list...");
119    match client.get_note_list().await {
120        Ok(notes) => {
121            println!("โœ… Found {} notes", notes.len());
122            println!("   Recent notes:");
123            for note in notes.iter().take(5) {
124                println!("     - {} ({})", note.title, note.short_id);
125                println!("       Tags: {}", note.tags.join(", "));
126                println!("       Last changed: {}", note.last_changed_at);
127            }
128        }
129        Err(e) => eprintln!("โŒ Error getting notes: {}", e),
130    }
131
132    println!();
133
134    // 7. Get teams and team notes (if any)
135    println!("๐Ÿ‘ฅ Getting teams...");
136    match client.get_teams().await {
137        Ok(teams) => {
138            if teams.is_empty() {
139                println!("โ„น๏ธ  No teams found");
140            } else {
141                println!("โœ… Found {} teams", teams.len());
142                for team in &teams {
143                    println!("   - Team: {} ({})", team.name, team.path);
144                    println!("     Description: {}", team.description);
145                    
146                    // Get team notes
147                    match client.get_team_notes(&team.path).await {
148                        Ok(team_notes) => {
149                            println!("     Notes: {} notes", team_notes.len());
150                            for note in team_notes.iter().take(3) {
151                                println!("       - {}", note.title);
152                            }
153                        }
154                        Err(e) => eprintln!("     โŒ Error getting team notes: {}", e),
155                    }
156                }
157            }
158        }
159        Err(e) => eprintln!("โŒ Error getting teams: {}", e),
160    }
161
162    println!("\n๐ŸŽ‰ Advanced example completed!");
163    println!("   Created note ID: {}", created_note.note.id);
164    println!("   View at: {}", created_note.note.publish_link);
165
166    Ok(())
167}
Source

pub async fn update_note( &self, note_id: &str, payload: &UpdateNoteOptions, ) -> Result<SingleNote>

Examples found in repository?
examples/advanced_usage.rs (line 95)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Example with custom configuration
7    let options = ApiClientOptions {
8        wrap_response_errors: true,
9        timeout: Some(Duration::from_secs(30)),
10        retry_config: Some(RetryConfig {
11            max_retries: 3,
12            base_delay: Duration::from_millis(200),
13        }),
14    };
15
16    let client = ApiClient::with_options(
17        "your_access_token_here",
18        None, // Use default API endpoint
19        Some(options),
20    )?;
21
22    println!("=== HackMD API Client Advanced Example ===\n");
23
24    // 1. Get user information
25    println!("๐Ÿ“‹ Getting user information...");
26    match client.get_me().await {
27        Ok(user) => {
28            println!("โœ… User: {} ({})", user.name, user.email.unwrap_or("no email".to_string()));
29            println!("   Path: {}", user.user_path);
30            println!("   Teams: {}", user.teams.len());
31            for team in &user.teams {
32                println!("     - {} ({})", team.name, team.path);
33            }
34        }
35        Err(e) => {
36            eprintln!("โŒ Error getting user info: {}", e);
37            return Ok(());
38        }
39    }
40
41    println!();
42
43    // 2. Create a new note with various permissions
44    println!("๐Ÿ“ Creating a new note...");
45    let note_options = CreateNoteOptions {
46        title: Some("Advanced Rust Example".to_string()),
47        content: Some("# Advanced HackMD Rust Client Example\n\n## Features\n\n- โœ… Async/await support\n- โœ… Retry mechanism with exponential backoff\n- โœ… Comprehensive error handling\n- โœ… Type-safe API\n\n## Code\n\n```rust\nlet client = ApiClient::new(\"token\")?;\nlet user = client.get_me().await?;\nprintln!(\"Hello, {}!\", user.name);\n```\n\nThis note was created using the Rust HackMD API client! ๐Ÿฆ€".to_string()),
48        read_permission: Some(NotePermissionRole::SignedIn),
49        write_permission: Some(NotePermissionRole::Owner),
50        comment_permission: Some(CommentPermissionType::Owners),
51        permalink: Some(format!("rust-example-{}", chrono::Utc::now().timestamp())),
52    };
53
54    let created_note = match client.create_note(&note_options).await {
55        Ok(note) => {
56            println!("โœ… Created note: {} (ID: {})", note.note.title, note.note.id);
57            println!("   Short ID: {}", note.note.short_id);
58            println!("   Publish Link: {}", note.note.publish_link);
59            note
60        }
61        Err(e) => {
62            eprintln!("โŒ Error creating note: {}", e);
63            return Ok(());
64        }
65    };
66
67    println!();
68
69    // 3. Update the note content
70    println!("โœ๏ธ  Updating note content...");
71    let updated_content = format!(
72        "{}\n\n## Update\n\nThis content was updated at {} using the Rust API client.\n\n### Statistics\n\n- Original content length: {} characters\n- Update timestamp: {}\n- API client: hackmd-api-client-rs v0.1.0",
73        created_note.content,
74        chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
75        created_note.content.len(),
76        chrono::Utc::now().timestamp()
77    );
78
79    match client.update_note_content(&created_note.note.id, &updated_content).await {
80        Ok(_) => println!("โœ… Note content updated successfully"),
81        Err(e) => eprintln!("โŒ Error updating note: {}", e),
82    }
83
84    println!();
85
86    // 4. Update note permissions
87    println!("๐Ÿ”’ Updating note permissions...");
88    let permission_update = UpdateNoteOptions {
89        content: None,
90        read_permission: Some(NotePermissionRole::Guest), // Make it publicly readable
91        write_permission: Some(NotePermissionRole::SignedIn),
92        permalink: None,
93    };
94
95    match client.update_note(&created_note.note.id, &permission_update).await {
96        Ok(_) => println!("โœ… Note permissions updated successfully"),
97        Err(e) => eprintln!("โŒ Error updating permissions: {}", e),
98    }
99
100    println!();
101
102    // 5. Get updated note
103    println!("๐Ÿ” Fetching updated note...");
104    match client.get_note(&created_note.note.id).await {
105        Ok(note) => {
106            println!("โœ… Fetched note: {}", note.note.title);
107            println!("   Content length: {} characters", note.content.len());
108            println!("   Read permission: {:?}", note.note.read_permission);
109            println!("   Write permission: {:?}", note.note.write_permission);
110            println!("   Last changed: {}", note.note.last_changed_at);
111        }
112        Err(e) => eprintln!("โŒ Error fetching note: {}", e),
113    }
114
115    println!();
116
117    // 6. List recent notes
118    println!("๐Ÿ“š Getting note list...");
119    match client.get_note_list().await {
120        Ok(notes) => {
121            println!("โœ… Found {} notes", notes.len());
122            println!("   Recent notes:");
123            for note in notes.iter().take(5) {
124                println!("     - {} ({})", note.title, note.short_id);
125                println!("       Tags: {}", note.tags.join(", "));
126                println!("       Last changed: {}", note.last_changed_at);
127            }
128        }
129        Err(e) => eprintln!("โŒ Error getting notes: {}", e),
130    }
131
132    println!();
133
134    // 7. Get teams and team notes (if any)
135    println!("๐Ÿ‘ฅ Getting teams...");
136    match client.get_teams().await {
137        Ok(teams) => {
138            if teams.is_empty() {
139                println!("โ„น๏ธ  No teams found");
140            } else {
141                println!("โœ… Found {} teams", teams.len());
142                for team in &teams {
143                    println!("   - Team: {} ({})", team.name, team.path);
144                    println!("     Description: {}", team.description);
145                    
146                    // Get team notes
147                    match client.get_team_notes(&team.path).await {
148                        Ok(team_notes) => {
149                            println!("     Notes: {} notes", team_notes.len());
150                            for note in team_notes.iter().take(3) {
151                                println!("       - {}", note.title);
152                            }
153                        }
154                        Err(e) => eprintln!("     โŒ Error getting team notes: {}", e),
155                    }
156                }
157            }
158        }
159        Err(e) => eprintln!("โŒ Error getting teams: {}", e),
160    }
161
162    println!("\n๐ŸŽ‰ Advanced example completed!");
163    println!("   Created note ID: {}", created_note.note.id);
164    println!("   View at: {}", created_note.note.publish_link);
165
166    Ok(())
167}
Source

pub async fn delete_note(&self, note_id: &str) -> Result<()>

Source

pub async fn get_teams(&self) -> Result<Vec<Team>>

Examples found in repository?
examples/advanced_usage.rs (line 136)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Example with custom configuration
7    let options = ApiClientOptions {
8        wrap_response_errors: true,
9        timeout: Some(Duration::from_secs(30)),
10        retry_config: Some(RetryConfig {
11            max_retries: 3,
12            base_delay: Duration::from_millis(200),
13        }),
14    };
15
16    let client = ApiClient::with_options(
17        "your_access_token_here",
18        None, // Use default API endpoint
19        Some(options),
20    )?;
21
22    println!("=== HackMD API Client Advanced Example ===\n");
23
24    // 1. Get user information
25    println!("๐Ÿ“‹ Getting user information...");
26    match client.get_me().await {
27        Ok(user) => {
28            println!("โœ… User: {} ({})", user.name, user.email.unwrap_or("no email".to_string()));
29            println!("   Path: {}", user.user_path);
30            println!("   Teams: {}", user.teams.len());
31            for team in &user.teams {
32                println!("     - {} ({})", team.name, team.path);
33            }
34        }
35        Err(e) => {
36            eprintln!("โŒ Error getting user info: {}", e);
37            return Ok(());
38        }
39    }
40
41    println!();
42
43    // 2. Create a new note with various permissions
44    println!("๐Ÿ“ Creating a new note...");
45    let note_options = CreateNoteOptions {
46        title: Some("Advanced Rust Example".to_string()),
47        content: Some("# Advanced HackMD Rust Client Example\n\n## Features\n\n- โœ… Async/await support\n- โœ… Retry mechanism with exponential backoff\n- โœ… Comprehensive error handling\n- โœ… Type-safe API\n\n## Code\n\n```rust\nlet client = ApiClient::new(\"token\")?;\nlet user = client.get_me().await?;\nprintln!(\"Hello, {}!\", user.name);\n```\n\nThis note was created using the Rust HackMD API client! ๐Ÿฆ€".to_string()),
48        read_permission: Some(NotePermissionRole::SignedIn),
49        write_permission: Some(NotePermissionRole::Owner),
50        comment_permission: Some(CommentPermissionType::Owners),
51        permalink: Some(format!("rust-example-{}", chrono::Utc::now().timestamp())),
52    };
53
54    let created_note = match client.create_note(&note_options).await {
55        Ok(note) => {
56            println!("โœ… Created note: {} (ID: {})", note.note.title, note.note.id);
57            println!("   Short ID: {}", note.note.short_id);
58            println!("   Publish Link: {}", note.note.publish_link);
59            note
60        }
61        Err(e) => {
62            eprintln!("โŒ Error creating note: {}", e);
63            return Ok(());
64        }
65    };
66
67    println!();
68
69    // 3. Update the note content
70    println!("โœ๏ธ  Updating note content...");
71    let updated_content = format!(
72        "{}\n\n## Update\n\nThis content was updated at {} using the Rust API client.\n\n### Statistics\n\n- Original content length: {} characters\n- Update timestamp: {}\n- API client: hackmd-api-client-rs v0.1.0",
73        created_note.content,
74        chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
75        created_note.content.len(),
76        chrono::Utc::now().timestamp()
77    );
78
79    match client.update_note_content(&created_note.note.id, &updated_content).await {
80        Ok(_) => println!("โœ… Note content updated successfully"),
81        Err(e) => eprintln!("โŒ Error updating note: {}", e),
82    }
83
84    println!();
85
86    // 4. Update note permissions
87    println!("๐Ÿ”’ Updating note permissions...");
88    let permission_update = UpdateNoteOptions {
89        content: None,
90        read_permission: Some(NotePermissionRole::Guest), // Make it publicly readable
91        write_permission: Some(NotePermissionRole::SignedIn),
92        permalink: None,
93    };
94
95    match client.update_note(&created_note.note.id, &permission_update).await {
96        Ok(_) => println!("โœ… Note permissions updated successfully"),
97        Err(e) => eprintln!("โŒ Error updating permissions: {}", e),
98    }
99
100    println!();
101
102    // 5. Get updated note
103    println!("๐Ÿ” Fetching updated note...");
104    match client.get_note(&created_note.note.id).await {
105        Ok(note) => {
106            println!("โœ… Fetched note: {}", note.note.title);
107            println!("   Content length: {} characters", note.content.len());
108            println!("   Read permission: {:?}", note.note.read_permission);
109            println!("   Write permission: {:?}", note.note.write_permission);
110            println!("   Last changed: {}", note.note.last_changed_at);
111        }
112        Err(e) => eprintln!("โŒ Error fetching note: {}", e),
113    }
114
115    println!();
116
117    // 6. List recent notes
118    println!("๐Ÿ“š Getting note list...");
119    match client.get_note_list().await {
120        Ok(notes) => {
121            println!("โœ… Found {} notes", notes.len());
122            println!("   Recent notes:");
123            for note in notes.iter().take(5) {
124                println!("     - {} ({})", note.title, note.short_id);
125                println!("       Tags: {}", note.tags.join(", "));
126                println!("       Last changed: {}", note.last_changed_at);
127            }
128        }
129        Err(e) => eprintln!("โŒ Error getting notes: {}", e),
130    }
131
132    println!();
133
134    // 7. Get teams and team notes (if any)
135    println!("๐Ÿ‘ฅ Getting teams...");
136    match client.get_teams().await {
137        Ok(teams) => {
138            if teams.is_empty() {
139                println!("โ„น๏ธ  No teams found");
140            } else {
141                println!("โœ… Found {} teams", teams.len());
142                for team in &teams {
143                    println!("   - Team: {} ({})", team.name, team.path);
144                    println!("     Description: {}", team.description);
145                    
146                    // Get team notes
147                    match client.get_team_notes(&team.path).await {
148                        Ok(team_notes) => {
149                            println!("     Notes: {} notes", team_notes.len());
150                            for note in team_notes.iter().take(3) {
151                                println!("       - {}", note.title);
152                            }
153                        }
154                        Err(e) => eprintln!("     โŒ Error getting team notes: {}", e),
155                    }
156                }
157            }
158        }
159        Err(e) => eprintln!("โŒ Error getting teams: {}", e),
160    }
161
162    println!("\n๐ŸŽ‰ Advanced example completed!");
163    println!("   Created note ID: {}", created_note.note.id);
164    println!("   View at: {}", created_note.note.publish_link);
165
166    Ok(())
167}
Source

pub async fn get_team_notes(&self, team_path: &str) -> Result<Vec<Note>>

Examples found in repository?
examples/advanced_usage.rs (line 147)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Example with custom configuration
7    let options = ApiClientOptions {
8        wrap_response_errors: true,
9        timeout: Some(Duration::from_secs(30)),
10        retry_config: Some(RetryConfig {
11            max_retries: 3,
12            base_delay: Duration::from_millis(200),
13        }),
14    };
15
16    let client = ApiClient::with_options(
17        "your_access_token_here",
18        None, // Use default API endpoint
19        Some(options),
20    )?;
21
22    println!("=== HackMD API Client Advanced Example ===\n");
23
24    // 1. Get user information
25    println!("๐Ÿ“‹ Getting user information...");
26    match client.get_me().await {
27        Ok(user) => {
28            println!("โœ… User: {} ({})", user.name, user.email.unwrap_or("no email".to_string()));
29            println!("   Path: {}", user.user_path);
30            println!("   Teams: {}", user.teams.len());
31            for team in &user.teams {
32                println!("     - {} ({})", team.name, team.path);
33            }
34        }
35        Err(e) => {
36            eprintln!("โŒ Error getting user info: {}", e);
37            return Ok(());
38        }
39    }
40
41    println!();
42
43    // 2. Create a new note with various permissions
44    println!("๐Ÿ“ Creating a new note...");
45    let note_options = CreateNoteOptions {
46        title: Some("Advanced Rust Example".to_string()),
47        content: Some("# Advanced HackMD Rust Client Example\n\n## Features\n\n- โœ… Async/await support\n- โœ… Retry mechanism with exponential backoff\n- โœ… Comprehensive error handling\n- โœ… Type-safe API\n\n## Code\n\n```rust\nlet client = ApiClient::new(\"token\")?;\nlet user = client.get_me().await?;\nprintln!(\"Hello, {}!\", user.name);\n```\n\nThis note was created using the Rust HackMD API client! ๐Ÿฆ€".to_string()),
48        read_permission: Some(NotePermissionRole::SignedIn),
49        write_permission: Some(NotePermissionRole::Owner),
50        comment_permission: Some(CommentPermissionType::Owners),
51        permalink: Some(format!("rust-example-{}", chrono::Utc::now().timestamp())),
52    };
53
54    let created_note = match client.create_note(&note_options).await {
55        Ok(note) => {
56            println!("โœ… Created note: {} (ID: {})", note.note.title, note.note.id);
57            println!("   Short ID: {}", note.note.short_id);
58            println!("   Publish Link: {}", note.note.publish_link);
59            note
60        }
61        Err(e) => {
62            eprintln!("โŒ Error creating note: {}", e);
63            return Ok(());
64        }
65    };
66
67    println!();
68
69    // 3. Update the note content
70    println!("โœ๏ธ  Updating note content...");
71    let updated_content = format!(
72        "{}\n\n## Update\n\nThis content was updated at {} using the Rust API client.\n\n### Statistics\n\n- Original content length: {} characters\n- Update timestamp: {}\n- API client: hackmd-api-client-rs v0.1.0",
73        created_note.content,
74        chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
75        created_note.content.len(),
76        chrono::Utc::now().timestamp()
77    );
78
79    match client.update_note_content(&created_note.note.id, &updated_content).await {
80        Ok(_) => println!("โœ… Note content updated successfully"),
81        Err(e) => eprintln!("โŒ Error updating note: {}", e),
82    }
83
84    println!();
85
86    // 4. Update note permissions
87    println!("๐Ÿ”’ Updating note permissions...");
88    let permission_update = UpdateNoteOptions {
89        content: None,
90        read_permission: Some(NotePermissionRole::Guest), // Make it publicly readable
91        write_permission: Some(NotePermissionRole::SignedIn),
92        permalink: None,
93    };
94
95    match client.update_note(&created_note.note.id, &permission_update).await {
96        Ok(_) => println!("โœ… Note permissions updated successfully"),
97        Err(e) => eprintln!("โŒ Error updating permissions: {}", e),
98    }
99
100    println!();
101
102    // 5. Get updated note
103    println!("๐Ÿ” Fetching updated note...");
104    match client.get_note(&created_note.note.id).await {
105        Ok(note) => {
106            println!("โœ… Fetched note: {}", note.note.title);
107            println!("   Content length: {} characters", note.content.len());
108            println!("   Read permission: {:?}", note.note.read_permission);
109            println!("   Write permission: {:?}", note.note.write_permission);
110            println!("   Last changed: {}", note.note.last_changed_at);
111        }
112        Err(e) => eprintln!("โŒ Error fetching note: {}", e),
113    }
114
115    println!();
116
117    // 6. List recent notes
118    println!("๐Ÿ“š Getting note list...");
119    match client.get_note_list().await {
120        Ok(notes) => {
121            println!("โœ… Found {} notes", notes.len());
122            println!("   Recent notes:");
123            for note in notes.iter().take(5) {
124                println!("     - {} ({})", note.title, note.short_id);
125                println!("       Tags: {}", note.tags.join(", "));
126                println!("       Last changed: {}", note.last_changed_at);
127            }
128        }
129        Err(e) => eprintln!("โŒ Error getting notes: {}", e),
130    }
131
132    println!();
133
134    // 7. Get teams and team notes (if any)
135    println!("๐Ÿ‘ฅ Getting teams...");
136    match client.get_teams().await {
137        Ok(teams) => {
138            if teams.is_empty() {
139                println!("โ„น๏ธ  No teams found");
140            } else {
141                println!("โœ… Found {} teams", teams.len());
142                for team in &teams {
143                    println!("   - Team: {} ({})", team.name, team.path);
144                    println!("     Description: {}", team.description);
145                    
146                    // Get team notes
147                    match client.get_team_notes(&team.path).await {
148                        Ok(team_notes) => {
149                            println!("     Notes: {} notes", team_notes.len());
150                            for note in team_notes.iter().take(3) {
151                                println!("       - {}", note.title);
152                            }
153                        }
154                        Err(e) => eprintln!("     โŒ Error getting team notes: {}", e),
155                    }
156                }
157            }
158        }
159        Err(e) => eprintln!("โŒ Error getting teams: {}", e),
160    }
161
162    println!("\n๐ŸŽ‰ Advanced example completed!");
163    println!("   Created note ID: {}", created_note.note.id);
164    println!("   View at: {}", created_note.note.publish_link);
165
166    Ok(())
167}
Source

pub async fn create_team_note( &self, team_path: &str, payload: &CreateNoteOptions, ) -> Result<SingleNote>

Source

pub async fn update_team_note_content( &self, team_path: &str, note_id: &str, content: &str, ) -> Result<()>

Source

pub async fn update_team_note( &self, team_path: &str, note_id: &str, payload: &UpdateNoteOptions, ) -> Result<()>

Source

pub async fn delete_team_note( &self, team_path: &str, note_id: &str, ) -> Result<()>

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T> Instrument for T

Sourceยง

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Sourceยง

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<T> WithSubscriber for T

Sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

impl<T> ErasedDestructor for T
where T: 'static,