wechat-api-rs 0.1.0

A Rust SDK for WeChat Official Account and Mini Program APIs
Documentation
//! # WeChat API Rust SDK
//!
//! A comprehensive Rust SDK for WeChat Official Account and Mini Program APIs.
//!
//! ## Quick Start
//!
//! ```rust
//! # use wechat_api_rs::WeChat;
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let client = WeChat::builder()
//!     .app_id("your_app_id")
//!     .app_secret("your_app_secret")
//!     .build()?;
//!
//! // Use the client
//! # Ok(())
//! # }
//! ```

// Core modules
pub mod client;
pub mod error;
pub mod auth;
pub mod crypto;
pub mod types;

// Feature-gated modules
#[cfg(feature = "official")]
pub mod official;

#[cfg(feature = "miniapp")]
pub mod miniapp;

// Re-exports
pub use client::{Client, ClientBuilder};
pub use error::{WeChatError, Result};
pub use auth::AccessToken;
pub use types::*;

/// WeChat API base URLs
pub mod api {
    pub const WECHAT_API_BASE: &str = "https://api.weixin.qq.com";
    pub const WECHAT_FILE_API_BASE: &str = "https://file.api.weixin.qq.com";
}

/// Main WeChat SDK client
pub struct WeChat {
    core_client: Client,
}

impl WeChat {
    /// Create a new WeChat client builder
    pub fn builder() -> WeChatBuilder {
        WeChatBuilder::new()
    }

    /// Get the core client
    pub fn core(&self) -> &Client {
        &self.core_client
    }

    /// Get the official account client
    #[cfg(feature = "official")]
    pub fn official(&self) -> official::OfficialClient {
        official::OfficialClient::new(self.core_client.clone())
    }

    /// Get the mini program client
    #[cfg(feature = "miniapp")]
    pub fn miniapp(&self) -> miniapp::MiniAppClient {
        miniapp::MiniAppClient::new(self.core_client.clone())
    }
}

/// Builder for WeChat client
pub struct WeChatBuilder {
    client_builder: ClientBuilder,
}

impl WeChatBuilder {
    pub fn new() -> Self {
        Self {
            client_builder: ClientBuilder::new(),
        }
    }

    pub fn app_id<S: Into<String>>(mut self, app_id: S) -> Self {
        self.client_builder = self.client_builder.app_id(app_id);
        self
    }

    pub fn app_secret<S: Into<String>>(mut self, app_secret: S) -> Self {
        self.client_builder = self.client_builder.app_secret(app_secret);
        self
    }

    pub fn timeout(mut self, timeout: std::time::Duration) -> Self {
        self.client_builder = self.client_builder.timeout(timeout);
        self
    }

    pub fn build(self) -> Result<WeChat> {
        let core_client = self.client_builder.build()?;
        Ok(WeChat { core_client })
    }
}

impl Default for WeChatBuilder {
    fn default() -> Self {
        Self::new()
    }
}