lmrc_cloudflare/lib.rs
1//! # Cloudflare Client
2//!
3//! A comprehensive, well-documented Rust client for the Cloudflare API,
4//! designed specifically for CI/CD and automation workflows.
5//!
6//! ## Features
7//!
8//! - **DNS Management**: Create, read, update, and delete DNS records with full control
9//! - **Zone Management**: List and query zones (domains)
10//! - **Cache Purging**: Clear cache by various methods (all, URLs, tags, hosts, prefixes)
11//! - **Builder Pattern**: Ergonomic API with builder pattern for all operations
12//! - **Custom Error Types**: Detailed error handling for programmatic responses
13//! - **Diff Output**: See what changes will be made before applying them
14//! - **Idempotent Operations**: Safe to run multiple times (perfect for CI/CD)
15//! - **Well Documented**: Comprehensive docs and examples
16//!
17//! ## Quick Start
18//!
19//! ```no_run
20//! use lmrc_cloudflare::{CloudflareClient, dns::RecordType};
21//!
22//! # async fn example() -> Result<(), lmrc_cloudflare::Error> {
23//! // Create a client
24//! let client = CloudflareClient::builder()
25//! .api_token("your-api-token")
26//! .build()?;
27//!
28//! // List zones
29//! let zones = client.zones().list().send().await?;
30//! println!("Found {} zones", zones.len());
31//!
32//! // Get zone ID
33//! let zone_id = client.zones().get_zone_id("example.com").await?;
34//!
35//! // Create a DNS record
36//! let record = client.dns()
37//! .create_record(&zone_id)
38//! .name("api.example.com")
39//! .record_type(RecordType::A)
40//! .content("192.0.2.1")
41//! .proxied(true)
42//! .send()
43//! .await?;
44//!
45//! println!("Created record: {}", record.id);
46//!
47//! // List DNS records
48//! let records = client.dns()
49//! .list_records(&zone_id)
50//! .record_type(RecordType::A)
51//! .send()
52//! .await?;
53//!
54//! // Update a record
55//! client.dns()
56//! .update_record(&zone_id, &record.id)
57//! .content("192.0.2.2")
58//! .send()
59//! .await?;
60//!
61//! // Purge cache
62//! client.cache()
63//! .purge_urls(&zone_id)
64//! .urls(vec!["https://example.com/page1"])
65//! .send()
66//! .await?;
67//! # Ok(())
68//! # }
69//! ```
70//!
71//! ## CI/CD Integration
72//!
73//! The sync operations are designed for CI/CD workflows:
74//!
75//! ```no_run
76//! use lmrc_cloudflare::{CloudflareClient, dns::{RecordType, DnsRecordBuilder}};
77//!
78//! # async fn example() -> Result<(), lmrc_cloudflare::Error> {
79//! let client = CloudflareClient::new("your-api-token")?;
80//! let zone_id = client.zones().get_zone_id("example.com").await?;
81//!
82//! // Define desired state
83//! let desired_records = vec![
84//! DnsRecordBuilder::new()
85//! .name("api.example.com")
86//! .record_type(RecordType::A)
87//! .content("192.0.2.1")
88//! .proxied(true),
89//! DnsRecordBuilder::new()
90//! .name("www.example.com")
91//! .record_type(RecordType::CNAME)
92//! .content("example.com")
93//! .proxied(true),
94//! ];
95//!
96//! // Dry run to see what would change
97//! let changes = client.dns()
98//! .sync_records(&zone_id)
99//! .records(desired_records.clone())
100//! .dry_run(true)
101//! .send()
102//! .await?;
103//!
104//! for change in &changes {
105//! println!("{:?}: {}", change.action, change.description);
106//! }
107//!
108//! // Apply changes
109//! let changes = client.dns()
110//! .sync_records(&zone_id)
111//! .records(desired_records)
112//! .dry_run(false)
113//! .send()
114//! .await?;
115//! # Ok(())
116//! # }
117//! ```
118//!
119//! ## Error Handling
120//!
121//! The library uses custom error types for better error handling:
122//!
123//! ```no_run
124//! use lmrc_cloudflare::{CloudflareClient, Error};
125//!
126//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
127//! let client = CloudflareClient::new("your-api-token")?;
128//!
129//! match client.zones().get_zone_id("nonexistent.com").await {
130//! Ok(zone_id) => println!("Zone ID: {}", zone_id),
131//! Err(Error::NotFound(msg)) => println!("Zone not found: {}", msg),
132//! Err(Error::Unauthorized(msg)) => println!("Auth error: {}", msg),
133//! Err(Error::RateLimited { retry_after }) => {
134//! println!("Rate limited, retry after: {:?}", retry_after);
135//! }
136//! Err(e) => println!("Other error: {}", e),
137//! }
138//! # Ok(())
139//! # }
140//! ```
141
142pub mod cache;
143pub mod client;
144pub mod dns;
145pub mod error;
146pub mod types;
147pub mod zones;
148
149// Re-export main types at crate root
150pub use client::{CloudflareClient, CloudflareClientBuilder, RetryConfig};
151pub use error::{Error, Result};
152pub use types::{Change, ChangeAction};
153
154// Common type re-exports
155pub use dns::{DnsRecord, DnsRecordBuilder, RecordType};
156pub use zones::Zone;