captchabot 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +30 -0
- data/Rakefile +1 -0
- data/captchabot.gemspec +24 -0
- data/lib/captchabot.rb +100 -0
- data/lib/captchabot/version.rb +3 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: bf6fa171fa579eb476d54957839256e2c537ae01
|
4
|
+
data.tar.gz: 052cdfc85ab85ff0b4ec84f88d345853c532b861
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57126ef1b7b8e3342dcab99e7d836a6ae2b3c8ad5c80f986140c60d504f09bef08b8a4d4d47f55564284a198b33ce113d3bd53df23b72fda0c9d631bf3b78839
|
7
|
+
data.tar.gz: 3d988eea6f2e12d8e16418fb42d941dc7c5a8ef4ec37172622d8d272c781ec6ebf4b9c6e17bf0b213cc535e216e6caba92dfb9299d573f780dcc1ac30d721201
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Wrapper for [captchabot][1] API
|
2
|
+
Cloned from [Antigate][2] GEM
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
### Recognize captcha
|
6
|
+
captcha = Captchabot.wrapper(KEY)
|
7
|
+
captcha.phrase = 0 or 1 (0 default, 1 marks that at captcha 2-4 words)
|
8
|
+
captcha.regsense = 0 or 1 (0 default, 1 marks that text captcha is case sensitive)
|
9
|
+
captcha.numeric = 0 or 1 or 2 (0 default, 1 marks that text captcha consists only of numbers, 2 marks that on captcha no digit)
|
10
|
+
captcha.calc = 0 or 1 (0 default, 1 marks that digit on captcha should be folded)
|
11
|
+
captcha.min_len = 0..20 (0 default, minimum length text captcha)
|
12
|
+
captcha.max_len = 0..20 (0 - unlimited, maximum length text captcha)
|
13
|
+
recognized = captcha.recognize(URL, EXT)
|
14
|
+
puts recognized[0] # ID recognized CAPTCHA
|
15
|
+
puts recognized[1] # Text CAPTCHA
|
16
|
+
|
17
|
+
#### Example
|
18
|
+
captcha = Captchabot.wrapper('660aaf58948bae3fa81362ef71b9ebcc')
|
19
|
+
captcha.phrase = 1
|
20
|
+
recognized = captcha.recognize('http://www.google.com/recaptcha/api/image?c=03AHJ_Vuu-Kun_wMo4M8JiWA87K6awfoiUxJCUF9KkQq3tCfyxjYELhHcsIJrcJ_qgqIQQsBw5vWAkpHBqP4VEHv1nwtoAnD5uZvwzHknOFyID4OrX0_6q8QXQ5TwkRn7qBxdt3QdX6D8NvPcFHFHzmEhu1yCJJQfTwQ', 'jpg')
|
21
|
+
puts recognized[1]
|
22
|
+
|
23
|
+
### Get balance
|
24
|
+
puts Captchabot.balance(KEY)
|
25
|
+
|
26
|
+
#### Example
|
27
|
+
puts Captchabot.balance('660aaf58948bae3fa81362ef71b9ebcc')
|
28
|
+
|
29
|
+
[1]: http://captchabot.com/
|
30
|
+
[2]: https://github.com/ivanare/antigate
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/captchabot.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "captchabot/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "captchabot"
|
7
|
+
s.version = Captchabot::VERSION
|
8
|
+
s.authors = ["Dmitry Ukolov"]
|
9
|
+
s.email = ["udmitry@mail.ru"]
|
10
|
+
s.homepage = "https://github.com/ukolovda/captchabot"
|
11
|
+
s.summary = %q{Captchabot wrapper}
|
12
|
+
s.description = %q{Wrapper for Captchabot.com}
|
13
|
+
|
14
|
+
s.rubyforge_project = "captchabot"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
data/lib/captchabot.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require "captchabot/version"
|
2
|
+
|
3
|
+
module Captchabot
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
require 'base64'
|
7
|
+
|
8
|
+
def self.wrapper(key)
|
9
|
+
return Wrapper.new(key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.balance(key)
|
13
|
+
wrapper = Wrapper.new(key)
|
14
|
+
return wrapper.balance
|
15
|
+
end
|
16
|
+
|
17
|
+
class Wrapper
|
18
|
+
attr_accessor :phrase, :regsense, :numeric, :calc, :min_len, :max_len, :domain
|
19
|
+
|
20
|
+
def initialize(key)
|
21
|
+
@key = key
|
22
|
+
|
23
|
+
@phrase = 0
|
24
|
+
@regsense = 0
|
25
|
+
@numeric = 0
|
26
|
+
@calc = 0
|
27
|
+
@min_len = 0
|
28
|
+
@max_len = 0
|
29
|
+
@domain = "captchabot.com"
|
30
|
+
end
|
31
|
+
|
32
|
+
def recognize(url, ext)
|
33
|
+
added = nil
|
34
|
+
loop do
|
35
|
+
added = add(url, ext)
|
36
|
+
next if added.nil?
|
37
|
+
if added.include? 'ERROR_NO_SLOT_AVAILABLE'
|
38
|
+
sleep(1)
|
39
|
+
next
|
40
|
+
else
|
41
|
+
break
|
42
|
+
end
|
43
|
+
end
|
44
|
+
if added.include? 'OK'
|
45
|
+
id = added.split('|')[1]
|
46
|
+
sleep(10)
|
47
|
+
status = nil
|
48
|
+
loop do
|
49
|
+
status = status(id)
|
50
|
+
next if status.nil?
|
51
|
+
if status.include? 'CAPCHA_NOT_READY'
|
52
|
+
sleep(1)
|
53
|
+
next
|
54
|
+
else
|
55
|
+
break
|
56
|
+
end
|
57
|
+
end
|
58
|
+
return [id, status.split('|')[1]]
|
59
|
+
else
|
60
|
+
return added
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def add(url, ext)
|
65
|
+
uri = URI.parse(url)
|
66
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
67
|
+
http.use_ssl = (uri.port == 443)
|
68
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
69
|
+
response = http.request(request)
|
70
|
+
captcha = response.body
|
71
|
+
if captcha
|
72
|
+
params = {
|
73
|
+
'method' => 'base64',
|
74
|
+
'key' => @key,
|
75
|
+
'body' => Base64.encode64(captcha),
|
76
|
+
'ext' => ext,
|
77
|
+
'phrase' => @phrase,
|
78
|
+
'regsense' => @regsense,
|
79
|
+
'numeric' => @numeric,
|
80
|
+
'calc' => @calc,
|
81
|
+
'min_len' => @min_len,
|
82
|
+
'max_len' => @max_len
|
83
|
+
}
|
84
|
+
return Net::HTTP.post_form(URI("http://#{@domain}/in.php"), params).body rescue nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def status(id)
|
89
|
+
return Net::HTTP.get(URI("http://#{@domain}/res.php?key=#{@key}&action=get&id=#{id}")) rescue nil
|
90
|
+
end
|
91
|
+
|
92
|
+
def bad(id)
|
93
|
+
return Net::HTTP.get(URI("http://#{@domain}/res.php?key=#{@key}&action=reportbad&id=#{id}")) rescue nil
|
94
|
+
end
|
95
|
+
|
96
|
+
def balance
|
97
|
+
return Net::HTTP.get(URI("http://#{@domain}/res.php?key=#{@key}&action=getbalance")) rescue nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: captchabot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitry Ukolov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Wrapper for Captchabot.com
|
14
|
+
email:
|
15
|
+
- udmitry@mail.ru
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- Gemfile
|
22
|
+
- README.markdown
|
23
|
+
- Rakefile
|
24
|
+
- captchabot.gemspec
|
25
|
+
- lib/captchabot.rb
|
26
|
+
- lib/captchabot/version.rb
|
27
|
+
homepage: https://github.com/ukolovda/captchabot
|
28
|
+
licenses: []
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project: captchabot
|
46
|
+
rubygems_version: 2.1.11
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Captchabot wrapper
|
50
|
+
test_files: []
|