diff --git a/src/lib.rs b/src/lib.rs index cd3f159..0992df5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,11 +4,19 @@ // SPDX-License-Identifier: MIT //! # mcaptcha-api-rs: Library to interact with with mCaptcha API -//! +//! //! This library provides a convenient interface to validate [mCaptcha authorization //! tokens](https://mcaptcha.org/docs/webmasters/terminology#authorization-token) presented by //! Visitors against your mCaptcha instances. It uses [reqwest](https://crates.io/crates/reqwest), //! 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 serde::{Deserialize, Serialize}; use url::Url; @@ -26,38 +34,22 @@ impl MCaptcha { /// /// Parameters: /// - [`sitekey`](https://mcaptcha.org/docs/webmasters/terminology#sitekey): unique identifier of - /// captcha configuration. Available on mCaptcha dashboard. + /// captcha configuration. Available on mCaptcha dashboard. /// - `account_secret`: used for authentication. Available on the settings page of mCaptcha dashboard /// - `instance_url`: the URL of your mCaptcha instance /// - /// - /// ```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 { + pub fn new>(sitekey: T, account_secret: T, instance_url: Url) -> Self { let mut verify_path = instance_url.clone(); verify_path.set_path("/api/v1/pow/siteverify"); Self { - sitekey, - account_secret, + sitekey: sitekey.into(), + account_secret: account_secret.into(), verify_path, client: Client::new(), } } /// 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 { let payload = CaptchaVerfiyPayload::from_ctx(self, token); let res: CaptchaVerifyResp = self