Class: Antigate::Wrapper
- Inherits:
-
Object
- Object
- Antigate::Wrapper
- Defined in:
- lib/antigate.rb
Instance Attribute Summary collapse
-
#calc ⇒ Object
Returns the value of attribute calc.
-
#max_len ⇒ Object
Returns the value of attribute max_len.
-
#min_len ⇒ Object
Returns the value of attribute min_len.
-
#numeric ⇒ Object
Returns the value of attribute numeric.
-
#phrase ⇒ Object
Returns the value of attribute phrase.
-
#regsense ⇒ Object
Returns the value of attribute regsense.
Instance Method Summary collapse
- #add(url, ext) ⇒ Object
- #bad(id) ⇒ Object
- #balance ⇒ Object
-
#initialize(key) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #recognize(url, ext) ⇒ Object
- #status(id) ⇒ Object
Constructor Details
#initialize(key) ⇒ Wrapper
Returns a new instance of Wrapper.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/antigate.rb', line 20 def initialize(key) @key = key @phrase = 0 @regsense = 0 @numeric = 0 @calc = 0 @min_len = 0 @max_len = 0 end |
Instance Attribute Details
#calc ⇒ Object
Returns the value of attribute calc.
18 19 20 |
# File 'lib/antigate.rb', line 18 def calc @calc end |
#max_len ⇒ Object
Returns the value of attribute max_len.
18 19 20 |
# File 'lib/antigate.rb', line 18 def max_len @max_len end |
#min_len ⇒ Object
Returns the value of attribute min_len.
18 19 20 |
# File 'lib/antigate.rb', line 18 def min_len @min_len end |
#numeric ⇒ Object
Returns the value of attribute numeric.
18 19 20 |
# File 'lib/antigate.rb', line 18 def numeric @numeric end |
#phrase ⇒ Object
Returns the value of attribute phrase.
18 19 20 |
# File 'lib/antigate.rb', line 18 def phrase @phrase end |
#regsense ⇒ Object
Returns the value of attribute regsense.
18 19 20 |
# File 'lib/antigate.rb', line 18 def regsense @regsense end |
Instance Method Details
#add(url, ext) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/antigate.rb', line 63 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 |
#bad(id) ⇒ Object
86 87 88 |
# File 'lib/antigate.rb', line 86 def bad(id) return Net::HTTP.get(URI("http://antigate.com/res.php?key=#{@key}&action=reportbad&id=#{id}")) rescue nil end |
#balance ⇒ Object
90 91 92 |
# File 'lib/antigate.rb', line 90 def balance return Net::HTTP.get(URI("http://antigate.com/res.php?key=#{@key}&action=getbalance")) rescue nil end |
#recognize(url, ext) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/antigate.rb', line 31 def recognize(url, ext) added = nil loop do added = add(url, ext) next if added.nil? 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) next if status.nil? if status.include? 'CAPCHA_NOT_READY' sleep(1) next else break end end return [id, status.split('|')[1]] else return added end end |
#status(id) ⇒ Object
82 83 84 |
# File 'lib/antigate.rb', line 82 def status(id) return Net::HTTP.get(URI("http://antigate.com/res.php?key=#{@key}&action=get&id=#{id}")) rescue nil end |