Class: Captchabot::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/captchabot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Wrapper

Returns a new instance of Wrapper.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/captchabot.rb', line 20

def initialize(key)
	@key = key

	@phrase = 0
	@regsense = 0
	@numeric = 0
	@calc = 0
	@min_len = 0
	@max_len = 0
	@domain = "captchabot.com"
end

Instance Attribute Details

#calcObject

Returns the value of attribute calc.



18
19
20
# File 'lib/captchabot.rb', line 18

def calc
  @calc
end

#domainObject

Returns the value of attribute domain.



18
19
20
# File 'lib/captchabot.rb', line 18

def domain
  @domain
end

#max_lenObject

Returns the value of attribute max_len.



18
19
20
# File 'lib/captchabot.rb', line 18

def max_len
  @max_len
end

#min_lenObject

Returns the value of attribute min_len.



18
19
20
# File 'lib/captchabot.rb', line 18

def min_len
  @min_len
end

#numericObject

Returns the value of attribute numeric.



18
19
20
# File 'lib/captchabot.rb', line 18

def numeric
  @numeric
end

#phraseObject

Returns the value of attribute phrase.



18
19
20
# File 'lib/captchabot.rb', line 18

def phrase
  @phrase
end

#regsenseObject

Returns the value of attribute regsense.



18
19
20
# File 'lib/captchabot.rb', line 18

def regsense
  @regsense
end

Instance Method Details

#add(url, ext) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/captchabot.rb', line 64

def add(url, ext)
  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = (uri.port == 443)
  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)
  captcha = response.body
	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://#{@domain}/in.php"), params).body rescue nil
	end
end

#bad(id) ⇒ Object



92
93
94
# File 'lib/captchabot.rb', line 92

def bad(id)
	return Net::HTTP.get(URI("http://#{@domain}/res.php?key=#{@key}&action=reportbad&id=#{id}")) rescue nil
end

#balanceObject



96
97
98
# File 'lib/captchabot.rb', line 96

def balance
	return Net::HTTP.get(URI("http://#{@domain}/res.php?key=#{@key}&action=getbalance")) rescue nil
end

#recognize(url, ext) ⇒ Object



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
62
# File 'lib/captchabot.rb', line 32

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



88
89
90
# File 'lib/captchabot.rb', line 88

def status(id)
	return Net::HTTP.get(URI("http://#{@domain}/res.php?key=#{@key}&action=get&id=#{id}")) rescue nil
end