antigate 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in antigate.gemspec
4
+ gemspec
@@ -0,0 +1,35 @@
1
+ # Wrapper for [Antigate][1] API
2
+ Gem recognizes CAPTCHA by means Antigate.
3
+
4
+ [Registration Antigate account][2]
5
+
6
+ ## Install
7
+ gem install antigate
8
+
9
+ ## Usage
10
+ ### Recognize captcha
11
+ captcha = Antigate.wrapper(KEY)
12
+ captcha.phrase = 0 or 1 (0 default, 1 marks that at captcha 2-4 words)
13
+ captcha.regsense = 0 or 1 (0 default, 1 marks that text captcha is case sensitive)
14
+ 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)
15
+ captcha.calc = 0 or 1 (0 default, 1 marks that digit on captcha should be folded)
16
+ captcha.min_len = 0..20 (0 default, minimum length text captcha)
17
+ captcha.max_len = 0..20 (0 - unlimited, maximum length text captcha)
18
+ recognized = captcha.recognize(URL, EXT)
19
+ puts recognized[0] # ID recognized CAPTCHA
20
+ puts recognized[1] # Text CAPTCHA
21
+
22
+ #### Example
23
+ captcha = Antigate.wrapper('660aaf58948bae3fa81362ef71b9ebcc')
24
+ captcha.phrase = 1
25
+ recognized = captcha.recognize('http://www.google.com/recaptcha/api/image?c=03AHJ_Vuu-Kun_wMo4M8JiWA87K6awfoiUxJCUF9KkQq3tCfyxjYELhHcsIJrcJ_qgqIQQsBw5vWAkpHBqP4VEHv1nwtoAnD5uZvwzHknOFyID4OrX0_6q8QXQ5TwkRn7qBxdt3QdX6D8NvPcFHFHzmEhu1yCJJQfTwQ', 'jpg')
26
+ puts recognized[1]
27
+
28
+ ### Get balance
29
+ puts Antigate.balance(KEY)
30
+
31
+ #### Example
32
+ puts Antigate.balance('660aaf58948bae3fa81362ef71b9ebcc')
33
+
34
+ [1]: http://antigate.com/
35
+ [2]: http://antigate.com/index.php?action=regscreen
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "antigate/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "antigate"
7
+ s.version = Antigate::VERSION
8
+ s.authors = ["Ivan Aryutkin"]
9
+ s.email = ["iivanare@gmail.com"]
10
+ s.homepage = "https://github.com/ivanare/antigate"
11
+ s.summary = %q{Antigate wrapper}
12
+ s.description = %q{Wrapper for Antigate API}
13
+
14
+ s.rubyforge_project = "antigate"
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
@@ -0,0 +1,92 @@
1
+ require "antigate/version"
2
+
3
+ module Antigate
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
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
+ end
30
+
31
+ def recognize(url, ext)
32
+ added = nil
33
+ loop do
34
+ added = add(url, ext)
35
+ if added.include? 'ERROR_NO_SLOT_AVAILABLE'
36
+ sleep(1)
37
+ next
38
+ else
39
+ break
40
+ end
41
+ end
42
+ if added.include? 'OK'
43
+ id = added.split('|')[1]
44
+ sleep(10)
45
+ status = nil
46
+ loop do
47
+ status = status(id)
48
+ if status.include? 'CAPCHA_NOT_READY'
49
+ sleep(1)
50
+ next
51
+ else
52
+ break
53
+ end
54
+ end
55
+ return [id, status.split('|')[1]]
56
+ else
57
+ return added
58
+ end
59
+ end
60
+
61
+ def add(url, ext)
62
+ captcha = Net::HTTP.get(URI(url)) rescue nil
63
+ if captcha
64
+ params = {
65
+ 'method' => 'base64',
66
+ 'key' => @key,
67
+ 'body' => Base64.encode64(captcha),
68
+ 'ext' => ext,
69
+ 'phrase' => @phrase,
70
+ 'regsense' => @regsense,
71
+ 'numeric' => @numeric,
72
+ 'calc' => @calc,
73
+ 'min_len' => @min_len,
74
+ 'max_len' => @max_len
75
+ }
76
+ return Net::HTTP.post_form(URI('http://antigate.com/in.php'), params).body rescue nil
77
+ end
78
+ end
79
+
80
+ def status(id)
81
+ return Net::HTTP.get(URI("http://antigate.com/res.php?key=#{@key}&action=get&id=#{id}")) rescue nil
82
+ end
83
+
84
+ def bad(id)
85
+ return Net::HTTP.get(URI("http://antigate.com/res.php?key=#{@key}&action=reportbad&id=#{id}")) rescue nil
86
+ end
87
+
88
+ def balance
89
+ return Net::HTTP.get(URI("http://antigate.com/res.php?key=#{@key}&action=getbalance")) rescue nil
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ module Antigate
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: antigate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ivan Aryutkin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Wrapper for Antigate API
15
+ email:
16
+ - iivanare@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README.markdown
24
+ - Rakefile
25
+ - antigate.gemspec
26
+ - lib/antigate.rb
27
+ - lib/antigate/version.rb
28
+ homepage: https://github.com/ivanare/antigate
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: antigate
48
+ rubygems_version: 1.8.10
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Antigate wrapper
52
+ test_files: []