fix: doctests
This commit is contained in:
parent
c9ac771bbd
commit
b2cdc81e30
1 changed files with 13 additions and 21 deletions
30
src/lib.rs
30
src/lib.rs
|
@ -9,6 +9,14 @@
|
||||||
//! tokens](https://mcaptcha.org/docs/webmasters/terminology#authorization-token) presented by
|
//! tokens](https://mcaptcha.org/docs/webmasters/terminology#authorization-token) presented by
|
||||||
//! Visitors against your mCaptcha instances. It uses [reqwest](https://crates.io/crates/reqwest),
|
//! Visitors against your mCaptcha instances. It uses [reqwest](https://crates.io/crates/reqwest),
|
||||||
//! and `native-tls` under the hood to communicate with the API.
|
//! and `native-tls` under the hood to communicate with the API.
|
||||||
|
//! ```rust,ignore
|
||||||
|
//! use url::Url;
|
||||||
|
//! use mcaptcha_api_rs::MCaptcha;
|
||||||
|
//!
|
||||||
|
//! let mcaptcha = MCaptcha::new("sitekeyfromdashboard", "secretfromdashboadr", Url::parse("https://mcaptcha.example.com").unwrap());
|
||||||
|
//! assert!(mcaptcha.verify("authorizationtokenfromvisitor").await.unwrap());
|
||||||
|
//! ```
|
||||||
|
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -30,34 +38,18 @@ impl MCaptcha {
|
||||||
/// - `account_secret`: used for authentication. Available on the settings page of mCaptcha dashboard
|
/// - `account_secret`: used for authentication. Available on the settings page of mCaptcha dashboard
|
||||||
/// - `instance_url`: the URL of your mCaptcha instance
|
/// - `instance_url`: the URL of your mCaptcha instance
|
||||||
///
|
///
|
||||||
///
|
pub fn new<T: Into<String>>(sitekey: T, account_secret: T, instance_url: Url) -> Self {
|
||||||
/// ```rust
|
|
||||||
/// use url::Url;
|
|
||||||
/// use mcaptcha_api_rs::MCaptcha;
|
|
||||||
///
|
|
||||||
/// let mcaptcha = MCaptcha::new("sitekeyfromdashboard", "secretfromdashboadr", Url::parse("https://mcaptcha.example.com").unwrap());
|
|
||||||
/// ```
|
|
||||||
pub fn new(sitekey: String, account_secret: String, instance_url: Url) -> Self {
|
|
||||||
let mut verify_path = instance_url.clone();
|
let mut verify_path = instance_url.clone();
|
||||||
verify_path.set_path("/api/v1/pow/siteverify");
|
verify_path.set_path("/api/v1/pow/siteverify");
|
||||||
Self {
|
Self {
|
||||||
sitekey,
|
sitekey: sitekey.into(),
|
||||||
account_secret,
|
account_secret: account_secret.into(),
|
||||||
verify_path,
|
verify_path,
|
||||||
client: Client::new(),
|
client: Client::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify authorization token presented by visitor against mCaptcha server
|
/// Verify authorization token presented by visitor against mCaptcha server
|
||||||
///
|
|
||||||
///
|
|
||||||
/// ```rust,no_run
|
|
||||||
/// use url::Url;
|
|
||||||
/// use mcaptcha_api_rs::MCaptcha;
|
|
||||||
///
|
|
||||||
/// let mcaptcha = MCaptcha::new("sitekeyfromdashboard", "secretfromdashboadr", Url::parse("https://mcaptcha.example.com").unwrap());
|
|
||||||
/// assert!(mcaptcha.verify("authorizationtokenfromvisitor").await.unwrap());
|
|
||||||
/// ```
|
|
||||||
pub async fn verify(&self, token: &str) -> Result<bool, reqwest::Error> {
|
pub async fn verify(&self, token: &str) -> Result<bool, reqwest::Error> {
|
||||||
let payload = CaptchaVerfiyPayload::from_ctx(self, token);
|
let payload = CaptchaVerfiyPayload::from_ctx(self, token);
|
||||||
let res: CaptchaVerifyResp = self
|
let res: CaptchaVerifyResp = self
|
||||||
|
|
Loading…
Reference in a new issue