captcha-sdk 0.0.1

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

use crate::credential::Credential;

/// Default Prosopo Procaptcha verification endpoint.
pub const DEFAULT_ENDPOINT: &str = "https://api.prosopo.io/siteverify";

/// Configuration scaffold for the Prosopo Procaptcha adapter.
#[derive(PartialEq, Eq)]
pub struct ProcaptchaConfig {
    secret: Credential,
    endpoint: String,
}

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