pub struct HcaptchaCaptcha { /* private fields */ }
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 value 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 a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more