forked from ivanare/antigate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 454a46d
Showing
7 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.gem | ||
.bundle | ||
Gemfile.lock | ||
pkg/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in antigate.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Wrapper for [Antigate][1] API | ||
Gem recognizes CAPTCHA by means Antigate. | ||
|
||
[Registration Antigate account][2] | ||
|
||
## Install | ||
gem install antigate | ||
|
||
## Usage | ||
### Recognize captcha | ||
captcha = Antigate.wrapper(KEY) | ||
captcha.phrase = 0 or 1 (0 default, 1 marks that at captcha 2-4 words) | ||
captcha.regsense = 0 or 1 (0 default, 1 marks that text captcha is case sensitive) | ||
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) | ||
captcha.calc = 0 or 1 (0 default, 1 marks that digit on captcha should be folded) | ||
captcha.min_len = 0..20 (0 default, minimum length text captcha) | ||
captcha.max_len = 0..20 (0 - unlimited, maximum length text captcha) | ||
recognized = captcha.recognize(URL, EXT) | ||
puts recognized[0] # ID recognized CAPTCHA | ||
puts recognized[1] # Text CAPTCHA | ||
|
||
#### Example | ||
captcha = Antigate.wrapper('660aaf58948bae3fa81362ef71b9ebcc') | ||
captcha.phrase = 1 | ||
recognized = captcha.recognize('http://www.google.com/recaptcha/api/image?c=03AHJ_Vuu-Kun_wMo4M8JiWA87K6awfoiUxJCUF9KkQq3tCfyxjYELhHcsIJrcJ_qgqIQQsBw5vWAkpHBqP4VEHv1nwtoAnD5uZvwzHknOFyID4OrX0_6q8QXQ5TwkRn7qBxdt3QdX6D8NvPcFHFHzmEhu1yCJJQfTwQ', 'jpg') | ||
puts recognized[1] | ||
|
||
### Get balance | ||
puts Antigate.balance(KEY) | ||
|
||
#### Example | ||
puts Antigate.balance('660aaf58948bae3fa81362ef71b9ebcc') | ||
|
||
[1]: http://antigate.com/ | ||
[2]: http://antigate.com/index.php?action=regscreen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "antigate/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "antigate" | ||
s.version = Antigate::VERSION | ||
s.authors = ["Ivan Aryutkin"] | ||
s.email = ["[email protected]"] | ||
s.homepage = "https://github.com/ivanare/antigate" | ||
s.summary = %q{Antigate wrapper} | ||
s.description = %q{Wrapper for Antigate API} | ||
|
||
s.rubyforge_project = "antigate" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
|
||
# specify any dependencies here; for example: | ||
# s.add_development_dependency "rspec" | ||
# s.add_runtime_dependency "rest-client" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
require "antigate/version" | ||
|
||
module Antigate | ||
require 'net/http' | ||
require 'uri' | ||
require 'base64' | ||
|
||
def self.wrapper(key) | ||
return Wrapper.new(key) | ||
end | ||
|
||
def self.balance(key) | ||
wrapper = Wrapper.new(key) | ||
return wrapper.balance | ||
end | ||
|
||
class Wrapper | ||
attr_accessor :phrase, :regsense, :numeric, :calc, :min_len, :max_len | ||
|
||
def initialize(key) | ||
@key = key | ||
|
||
@phrase = 0 | ||
@regsense = 0 | ||
@numeric = 0 | ||
@calc = 0 | ||
@min_len = 0 | ||
@max_len = 0 | ||
end | ||
|
||
def recognize(url, ext) | ||
added = nil | ||
loop do | ||
added = add(url, ext) | ||
if added.include? 'ERROR_NO_SLOT_AVAILABLE' | ||
sleep(1) | ||
next | ||
else | ||
break | ||
end | ||
end | ||
if added.include? 'OK' | ||
id = added.split('|')[1] | ||
sleep(10) | ||
status = nil | ||
loop do | ||
status = status(id) | ||
if status.include? 'CAPCHA_NOT_READY' | ||
sleep(1) | ||
next | ||
else | ||
break | ||
end | ||
end | ||
return [id, status.split('|')[1]] | ||
else | ||
return added | ||
end | ||
end | ||
|
||
def add(url, ext) | ||
captcha = Net::HTTP.get(URI(url)) rescue nil | ||
if captcha | ||
params = { | ||
'method' => 'base64', | ||
'key' => @key, | ||
'body' => Base64.encode64(captcha), | ||
'ext' => ext, | ||
'phrase' => @phrase, | ||
'regsense' => @regsense, | ||
'numeric' => @numeric, | ||
'calc' => @calc, | ||
'min_len' => @min_len, | ||
'max_len' => @max_len | ||
} | ||
return Net::HTTP.post_form(URI('http://antigate.com/in.php'), params).body rescue nil | ||
end | ||
end | ||
|
||
def status(id) | ||
return Net::HTTP.get(URI("http://antigate.com/res.php?key=#{@key}&action=get&id=#{id}")) rescue nil | ||
end | ||
|
||
def bad(id) | ||
return Net::HTTP.get(URI("http://antigate.com/res.php?key=#{@key}&action=reportbad&id=#{id}")) rescue nil | ||
end | ||
|
||
def balance | ||
return Net::HTTP.get(URI("http://antigate.com/res.php?key=#{@key}&action=getbalance")) rescue nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Antigate | ||
VERSION = "0.0.1" | ||
end |