captcha-sdk 0.0.1

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

use crate::credential::Credential;

/// Default Friendly Captcha v2 verification endpoint.
pub const DEFAULT_ENDPOINT: &str = "https://global.frcapi.com/api/v2/captcha/siteverify";

/// Configuration scaffold for the Friendly Captcha adapter.
#[derive(PartialEq, Eq)]
pub struct FriendlyCaptchaConfig {
    api_key: Credential,
    endpoint: String,
}

impl FriendlyCaptchaConfig {
    /// Creates a configuration using the provider's default endpoint.
    pub fn new(api_key: impl Into<String>) -> Self {
        Self {
            api_key: Credential::new(api_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 FriendlyCaptchaConfig {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("FriendlyCaptchaConfig")
            .field("api_key", &self.api_key)
            .field("endpoint", &self.endpoint)
            .finish()
    }
}