Skip to content

Commit

Permalink
Added gem source and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanare committed Dec 12, 2011
0 parents commit 454a46d
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
4 changes: 4 additions & 0 deletions Gemfile
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
35 changes: 35 additions & 0 deletions README.markdown
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
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "bundler/gem_tasks"
24 changes: 24 additions & 0 deletions antigate.gemspec
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
92 changes: 92 additions & 0 deletions lib/antigate.rb
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
3 changes: 3 additions & 0 deletions lib/antigate/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Antigate
VERSION = "0.0.1"
end

0 comments on commit 454a46d

Please sign in to comment.