Skip to content

Commit 73e5952

Browse files
committed
first commit
0 parents  commit 73e5952

14 files changed

+727
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.gem
2+
*.token

GemFile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'https://rubygems.org'
2+

GemFile.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
5+
PLATFORMS
6+
x64-mingw-ucrt
7+
8+
DEPENDENCIES
9+
10+
BUNDLED WITH
11+
2.4.14

README.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# MetaBypass ( AI Captcha Solver )
2+
## Ruby class to work with [MetaBypass](https://metabypass.tech) services
3+
4+
Free demo (no credit card required) -> https://app.metabypass.tech/application
5+
6+
<br/>
7+
8+
### Features
9+
10+
Solve image captcha , reCaptcha v2 & v3 <br/>
11+
Auto handler for reCaptcha v2 <br/>
12+
Simple syntax <br/>
13+
Error logger <br/>
14+
15+
<br/>
16+
<br/>
17+
18+
## Install via gem
19+
20+
Go to your project root directory and run this command in terminal:
21+
22+
<br/>
23+
24+
```
25+
gem install metabypass
26+
```
27+
28+
<br/>
29+
<br/>
30+
31+
32+
## Usage
33+
34+
<br/>
35+
36+
**Image Captcha** <br />
37+
```ruby
38+
require 'metabypass'
39+
40+
41+
# ---------------------------- CREDENTIALS -----------------------------
42+
#get your credentials from https://app.metabypass.tech/application
43+
44+
client_id = 'YOUR_CLIENT_ID'
45+
client_secret = 'YOUR_CLIENT_SECRET'
46+
email = 'YOUR_EMAIL'
47+
password = 'YOUR_PASSWORD'
48+
49+
50+
# Metabypass instance
51+
metabypass = Metabypass.new(client_id,client_secret,email,password)
52+
53+
# ----------------------------IMAGE CAPTCHA SAMPLE -----------------------------
54+
#you can pass base64 encoded image file or path of image file
55+
img="samples/icaptcha1.jpg"
56+
#you can pass some optional params too. more details: https://app.metabypass.tech/docs.html?#api_3
57+
numeric=0; #default
58+
min_len=0; #default
59+
max_len=0; #default
60+
image_captcha= metabypass.image_captcha(img,numeric,min_len,max_len)
61+
puts metabypass.end_result
62+
```
63+
<br/><br/>
64+
65+
**reCaptcha v2** <br />
66+
```ruby
67+
require 'metabypass'
68+
69+
70+
# ---------------------------- CREDENTIALS -----------------------------
71+
#get your credentials from https://app.metabypass.tech/application
72+
73+
client_id = 'YOUR_CLIENT_ID'
74+
client_secret = 'YOUR_CLIENT_SECRET'
75+
email = 'YOUR_EMAIL'
76+
password = 'YOUR_PASSWORD'
77+
78+
# Metabypass instance
79+
metabypass = Metabypass.new(client_id,client_secret,email,password)
80+
81+
# --------------------------- reCAPTCHA V2 SAMPLE -----------------------------
82+
url="SITE_URL"
83+
sitekey="SITE_KEY"
84+
recaptcha_v2= metabypass.recaptcha_v2_handler(url,sitekey)
85+
puts metabypass.end_result
86+
```
87+
<br/><br/>
88+
89+
90+
**reCaptcha v3** <br />
91+
```ruby
92+
require 'metabypass'
93+
94+
95+
# ---------------------------- CREDENTIALS -----------------------------
96+
#get your credentials from https://app.metabypass.tech/application
97+
98+
client_id = 'YOUR_CLIENT_ID'
99+
client_secret = 'YOUR_CLIENT_SECRET'
100+
email = 'YOUR_EMAIL'
101+
password = 'YOUR_PASSWORD'
102+
103+
104+
# Metabypass instance
105+
metabypass = Metabypass.new(client_id,client_secret,email,password)
106+
107+
# --------------------------- reCAPTCHA V3 SAMPLE -----------------------------
108+
url="SITE_URL"
109+
sitekey="SITE_KEY"
110+
recaptcha_v3= metabypass.recaptcha_v3(url,sitekey)
111+
puts metabypass.end_result
112+
113+
```
114+
<br/><br/>
115+
116+
117+
**reCaptcha invisible** <br />
118+
```ruby
119+
require 'metabypass'
120+
121+
122+
# ---------------------------- CREDENTIALS -----------------------------
123+
#get your credentials from https://app.metabypass.tech/application
124+
125+
client_id = 'YOUR_CLIENT_ID'
126+
client_secret = 'YOUR_CLIENT_SECRET'
127+
email = 'YOUR_EMAIL'
128+
password = 'YOUR_PASSWORD'
129+
130+
131+
# Metabypass instance
132+
metabypass = Metabypass.new(client_id,client_secret,email,password)
133+
134+
# --------------------------- reCAPTCHA INVISIBLE SAMPLE -----------------------------
135+
url="SITE_URL"
136+
sitekey="SITE_KEY"
137+
recaptcha_invisible= metabypass.recaptcha_invisible(url,sitekey)
138+
puts metabypass.end_result
139+
140+
```
141+
<br/><br/>

lib/auth/auth.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
require_relative __dir__+"/../helpers"
2+
require 'net/http'
3+
require 'json'
4+
5+
6+
class Auth
7+
8+
# attr_reader :email, :password, :client_id, :client_secret,
9+
10+
def initialize(client_id,client_secret,email,password)
11+
@client_id = client_id
12+
@client_secret = client_secret
13+
@password = password
14+
@email = email
15+
@access_token_file_path = File.join(__dir__, 'metabypass.token')
16+
@access_token = retrieve_access_token || generate_access_token
17+
end
18+
19+
20+
def generate_access_token
21+
22+
request_url = 'https://app.metabypass.tech/CaptchaSolver/oauth/token'
23+
24+
params = {
25+
'grant_type' => 'password',
26+
'client_id' => @client_id,
27+
'client_secret' => @client_secret,
28+
'username' => @email,
29+
'password' => @password
30+
}
31+
32+
headers = {
33+
'Content-Type' => 'application/json',
34+
'Accept' => 'application/json'
35+
}
36+
37+
#webservice response
38+
response = send_request(request_url, params, 'POST', headers)
39+
40+
if response.empty?
41+
message = 'error! server response is empty'
42+
43+
#logger
44+
logger.error(message)
45+
return false
46+
end
47+
48+
49+
headers = JSON.parse(response['headers'])
50+
body = JSON.parse(response['body'])
51+
52+
if headers['http_code'] == 200
53+
@access_token = body['access_token']
54+
55+
File.write(@access_token_file_path, body['access_token'])
56+
return body['access_token']
57+
else
58+
message = 'error! unauth'
59+
#logger
60+
logger.error(message)
61+
return false
62+
end
63+
64+
end
65+
66+
private
67+
68+
def retrieve_access_token
69+
File.read(@access_token_file_path) if File.exist?(@access_token_file_path)
70+
end
71+
72+
end

lib/helpers.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
require 'net/http'
2+
require 'uri'
3+
4+
5+
def send_request(url, params, method, headers)
6+
7+
#prepare
8+
uri = URI(url)
9+
http = Net::HTTP.new(uri.host, uri.port)
10+
http.use_ssl = true if uri.scheme == 'https'
11+
12+
#method types
13+
case method
14+
when 'GET'
15+
uri.query = URI.encode_www_form(params)
16+
request = Net::HTTP::Get.new(uri)
17+
when 'POST'
18+
request = Net::HTTP::Post.new(uri)
19+
request.body = params.to_json
20+
when 'PUT'
21+
request = Net::HTTP::Put.new(uri)
22+
request.body = params.to_json
23+
when 'DELETE'
24+
uri.query = URI.encode_www_form(params)
25+
request = Net::HTTP::Delete.new(uri)
26+
else
27+
return {}
28+
end
29+
30+
headers.each { |key, value| request[key] = value }
31+
32+
response = http.request(request)
33+
34+
headers= response.to_hash
35+
headers['http_code']=response.code.to_i
36+
37+
{
38+
'headers' =>headers.to_json,
39+
'body' => response.body
40+
}
41+
42+
end
43+
44+
def is_base64_format?(str)
45+
46+
# Remove whitespace characters from the string
47+
cleaned_str = str.gsub(/\s+/, '')
48+
49+
# Check if the cleaned string is in the valid base64 format
50+
# by matching it against the base64 regular expression pattern
51+
base64_pattern = /^[a-zA-Z0-9+\/]+={0,2}$/
52+
base64_pattern.match?(cleaned_str)
53+
end

0 commit comments

Comments
 (0)