captcha-sdk 0.0.1

Unified server-side CAPTCHA verification for Rust
Documentation
use std::fmt;

use crate::credential::Credential;

/// Default `MTCaptcha` verification endpoint.
pub const DEFAULT_ENDPOINT: &str = "https://service.mtcaptcha.com/mtcv1/api/checktoken";

/// Configuration scaffold for the `MTCaptcha` adapter.
#[derive(PartialEq, Eq)]
pub struct MtCaptchaConfig {
    private_key: Credential,
    endpoint: String,
}

impl MtCaptchaConfig {
    /// Creates a configuration using the provider's default endpoint.
    pub fn new(private_key: impl Into<String>) -> Self {
        Self {
            private_key: Credential::new(private_key),
            endpoint: DEFAULT_ENDPOINT.to_owned(),
        }
    }

    /// Overrides the verification endpoint, primarily for testing.
    #[must_use]
    pub fn with_endpoint(mut self, endpoint: impl Into<String>) -> Self {
        self.endpoint = endpoint.into();
        self
    }

    /// Returns the verification endpoint.
    #[must_use]
    pub fn endpoint(&self) -> &str {
        &self.endpoint
    }
}

impl fmt::Debug for MtCaptchaConfig {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("MtCaptchaConfig")
            .field("private_key", &self.private_key)
            .field("endpoint", &self.endpoint)
            .finish()
    }
}