semanticpen 0.1.0

Official Rust SDK for SemanticPen API - AI-powered content generation
Documentation
use semanticpen::{SemanticPenClient, ClientConfig};
use std::time::Duration;
use tokio;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("🚀 Testing Rust SDK with Simple Generation");
    println!("==========================================\n");
    
    // Create client with debug enabled
    let config = ClientConfig {
        debug: true,
        ..Default::default()
    };
    
    let client = SemanticPenClient::with_config("your-api-key-here".to_string(), config)?;
    
    // Test with only required parameter
    println!("📝 Generating article with minimal params...");
    let response = client.generate_article("Simple test article Rust SDK", None).await?;
    
    println!("✅ Generation successful!");
    if let Some(article_id) = response.get_article_id() {
        println!("   Article ID: {}", article_id);
        println!("   Project ID: {}", response.project_id);
        println!("   Message: {}", response.message);
        
        // Check status periodically
        println!("\n⏳ Checking status periodically...");
        let max_checks = 8;
        
        for i in 1..=max_checks {
            tokio::time::sleep(Duration::from_secs(5)).await;
            
            match client.get_article(&article_id).await {
                Ok(article) => {
                    println!("   Check {}: {} (progress: {}%)", i, article.status, article.progress);
                    
                    match article.status.as_str() {
                        "finished" => {
                            println!("   ✅ Article completed successfully!");
                            if let Some(html) = &article.article_html {
                                println!("   🎉 Has article_html: Yes");
                                println!("   📏 Content length: {}", html.len());
                            } else {
                                println!("   🎉 Has article_html: No");
                            }
                            break;
                        }
                        "failed" => {
                            println!("   ❌ Article failed");
                            if let Some(error) = &article.error_message {
                                println!("   Error details: {}", error);
                            }
                            break;
                        }
                        _ => {
                            if i >= max_checks {
                                println!("⏰ Reached maximum checks ({}), but article may still be processing", max_checks);
                            }
                        }
                    }
                }
                Err(e) => {
                    println!("❌ Error checking status: {}", e);
                    continue;
                }
            }
        }
    } else {
        println!("❌ No article ID returned in response");
    }
    
    Ok(())
}