Struct hcaptcha::HcaptchaCaptcha [−][src]
pub struct HcaptchaCaptcha { /* fields omitted */ }Expand description
Capture the Hcaptcha data coming from the client.
Implementations
Create a new HcaptchaCaptcha from a response string slice.
Input
response - The response token from the client
Output
The HcaptchaCaptcha is returned if the input is valid. A HcaptchaError is returned if the validation fails.
Example
Create HcaptchaCaptcha from response key.
use hcaptcha::HcaptchaCaptcha;
// Get the body JSON string from the event.
let body_str = e.body.unwrap_or_else(|| "".to_owned());
// Get the form data from the body string.
let form: Form = serde_json::from_str(&body_str)?;
let captcha = HcaptchaCaptcha::new(&form.response)?;
Logging
If the tracing feature is enabled a debug level span is set for the method.
Update the remoteip field in HcaptchaCaptcha.
Input
remoteip - The response token from the client
Output
If the remoteip string is empty the field is set to None. If the remoteip string is a valid v4 or v6 ip address the field is set to Some(remoteip). If the remoteip string is invalid a HcaptchaError is returned.
Example
use hcaptcha::HcaptchaCaptcha;
let remoteip = get_remoteip_address();
let captcha = HcaptchaCaptcha::new(&form.response)?
.set_remoteip(&remoteip)?;
assert_some!(captcha.remoteip());
if let Some(sk) = captcha.remoteip() {
assert_eq!(remoteip, sk.to_string());
};Logging
If the tracing feature is enabled a debug level span is set for the method.
Update the remoteip field in HcaptchaCaptcha.
Input
sitekey - The response token from the client
Output
If the sitekey string is empty the field is set to None. If the sitekey string is a valid uuid the field is set to Some(sitekey). If the sitekey string is invalid a HcaptchaError is returned.
Example
use hcaptcha::HcaptchaCaptcha;
// Get the body JSON string from the event.
let body_str = e.body.unwrap_or_else(|| "".to_owned());
// Get the form data from the body string.
let form: Form = serde_json::from_str(&body_str)?;
let sitekey = get_sitekey();
let captcha = HcaptchaCaptcha::new(&form.response)?
.set_sitekey(&sitekey)?;
assert_some!(captcha.sitekey());
if let Some(sk) = captcha.sitekey() {
assert_eq!(sitekey, sk.to_string());
};
Logging
If the tracing feature is enabled a debug level span is set for the method.
Return the valud of the response field.
Output
A string containing the value of the response field.
Example
use hcaptcha::HcaptchaCaptcha;
let (response, captcha) = get_captcha();
assert_eq!(response, captcha.response().to_string());
Logging
If the tracing feature is enabled a debug level span is set for the method.
Get the value of the remoteip field.
Output
An Option enum containing the value of the remoteip in the Some variant or a None variant if the value is not set.
Example
use hcaptcha::HcaptchaCaptcha;
let (remoteip, captcha) = get_captcha();
let value = captcha.remoteip();
assert_some!(&value);
if let Some(v) = value {
assert_eq!(remoteip, v.to_string());
}
Logging
If the tracing feature is enabled a debug level span is set for the method.
Get the value of the sitekey field.
Output
An Option enum containing the value of the sitekey in the Some variant or a None variant if the value is not set.
Example
use hcaptcha::HcaptchaCaptcha;
let (sitekey, captcha) = get_captcha();
let value = captcha.sitekey();
assert_some!(&value);
if let Some(v) = value {
assert_eq!(sitekey, v.to_string());
};
Logging
If the tracing feature is enabled a debug level span is set for the method.
Trait Implementations
Returns the “default value” for a type. Read more
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>, Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for HcaptchaCaptchaimpl Send for HcaptchaCaptchaimpl Sync for HcaptchaCaptchaimpl Unpin for HcaptchaCaptchaimpl UnwindSafe for HcaptchaCaptchaBlanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more