Skip to content

Commit

Permalink
Add FriendlyCaptcha support
Browse files Browse the repository at this point in the history
  • Loading branch information
escritorio-gustavo committed Jan 29, 2024
1 parent 8a14910 commit 75543c9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "captcha_oxide"
version = "5.1.1"
version = "5.2.0"
edition = "2021"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
5 changes: 5 additions & 0 deletions src/captcha_types/friendly_captcha/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod solution;
mod task;

pub use solution::*;
pub use task::*;
6 changes: 6 additions & 0 deletions src/captcha_types/friendly_captcha/solution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use std::borrow::Cow;

#[derive(serde::Deserialize, Debug)]
pub struct FriendlyCaptchaSolution<'a> {
pub token: Cow<'a, str>,
}
35 changes: 35 additions & 0 deletions src/captcha_types/friendly_captcha/task.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use captcha_oxide_derive::proxy_task;
use std::borrow::Cow;
use url::Url;

use crate::CaptchaTask;

/// Represents the data required by the 2captcha API to solve a
/// FriendlyCaptcha challenge
///
/// # Example
/// ```
/// use captcha_oxide::{CaptchaTask, captcha_types::friendly_captcha::FriendlyCaptcha};
///
/// # fn main() -> Result<(), captcha_oxide::Error> {
/// let captcha = FriendlyCaptcha::builder()
/// .website_url("http://someurl.com")
/// .website_key("SOME_KEY")
/// .build()?;
/// # Ok(())
/// # }
/// ```
#[proxy_task(with_proxy = "FriendlyCaptchaTask", proxyless = "FriendlyCaptchaTaskProxyless", crate = crate)]
#[derive(serde::Serialize, CaptchaTask)]
#[task(timeout = 20, solution = super::solution::FriendlyCaptchaSolution<'a>, crate = crate)]
#[serde(rename_all = "camelCase")]
pub struct FriendlyCaptcha<'a> {
/// The full URL of target web page where the captcha is loaded.
/// We do not open the page, so it is not a problem if it is available
/// only for authenticated users
#[serde(rename = "websiteURL")]
#[task(builder_type = &'a str, parse_with = { fallible({ path = url::Url::parse }) })]
pub(super) website_url: Url,

pub(super) website_key: Cow<'a, str>,
}
1 change: 1 addition & 0 deletions src/captcha_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod cut_captcha;
pub mod cyber_siara_captcha;
pub mod data_dome_captcha;
pub mod draw_around_captcha;
pub mod friendly_captcha;
pub mod geetest;
pub mod grid_captcha;
pub mod h_captcha;
Expand Down

0 comments on commit 75543c9

Please sign in to comment.