Struct hcaptcha::HcaptchaRequest
source · pub struct HcaptchaRequest { /* private fields */ }
Expand description
Capture the required and optional data for a call to the hcaptcha API
Implementations§
source§impl HcaptchaRequest
impl HcaptchaRequest
sourcepub fn new(
secret: &str,
captcha: HcaptchaCaptcha
) -> Result<HcaptchaRequest, HcaptchaError>
pub fn new( secret: &str, captcha: HcaptchaCaptcha ) -> Result<HcaptchaRequest, HcaptchaError>
Create a new HcaptchaRequest
§Input
The Hcaptcha API has two mandatory parameters:
secret
: The client’s secret key for authentication
captcha
: HcaptchaCaptcha (including response token)
§Output
HcaptchaRequest is returned if the input strings are valid. HcaptchaError is returned if the validation fails.
§Example
use hcaptcha::HcaptchaRequest;
let secret = get_your_secret(); // your secret key
let captcha = get_captcha(); // captcha with response token
let request = HcaptchaRequest::new(&secret, captcha)?;
§Logging
If the tracing feature is enabled a debug level span is set for the method. The secret field will not be logged.
sourcepub fn new_from_response(
secret: &str,
response: &str
) -> Result<HcaptchaRequest, HcaptchaError>
pub fn new_from_response( secret: &str, response: &str ) -> Result<HcaptchaRequest, HcaptchaError>
Create a new HcaptchaRequest from only the response string
§Input
The Hcaptcha API has two mandatory parameters: secret: The client’s secret key for authentication response: The response code to validate
§Output
HcaptchaRequest is returned if the inputs are valid. HcaptchaError is returned if the validation fails.
§Example
use hcaptcha::HcaptchaRequest;
let secret = get_your_secret(); // your secret key
let response = get_response(); // Hcaptcha client response
let request = HcaptchaRequest::new_from_response(&secret, &response)?;
§Logging
If the tracing feature is enabled a debug level span is set for the method. The secret field will not be logged.
sourcepub fn set_remoteip(self, remoteip: &str) -> Result<Self, HcaptchaError>
pub fn set_remoteip(self, remoteip: &str) -> Result<Self, HcaptchaError>
Specify the optional ip address value
Update client IP address.
§Example
use hcaptcha::HcaptchaRequest;
let secret = get_your_secret(); // your secret key
let response = get_response(); // user's response token
let remoteip = get_remoteip_address(); // user's ip address
let request = HcaptchaRequest::new_from_response(&secret, &response)?
.set_remoteip(&remoteip)?;
#Logging
If the trace
feature is enabled a debug level span is set for the
method.
The secret field is not logged.
sourcepub fn set_sitekey(self, sitekey: &str) -> Result<Self, HcaptchaError>
pub fn set_sitekey(self, sitekey: &str) -> Result<Self, HcaptchaError>
Specify the optional sitekey value
Update the sitekey.
§Example
Create a new request and set the sitekey field in the request.
use hcaptcha::HcaptchaRequest;
let secret = get_your_secret(); // your secret key
let captcha = get_captcha(); // captcha
let sitekey = get_your_sitekey(); // your site key
let request = HcaptchaRequest::new(&secret, captcha)?
.set_sitekey(&sitekey);
#Logging
If the trace
feature is enabled a debug level span is created for the
method.
The secret field is not logged.