Module: Decaptcher
- Extended by:
- Decaptcher
- Included in:
- Decaptcher
- Defined in:
- lib/decaptcher.rb,
lib/decaptcher/version.rb
Defined Under Namespace
Classes: Response, SolveError
Constant Summary
collapse
- VERSION =
"1.0.1"
- @@api_uri =
URI.parse( "http://www.fasttypers.org/imagepost.ashx" )
- @@api_key =
nil
Instance Method Summary
collapse
Instance Method Details
#api_key=(key) ⇒ Object
15
16
17
|
# File 'lib/decaptcher.rb', line 15
def api_key=( key )
@@api_key = key
end
|
#api_uri=(uri) ⇒ Object
23
24
25
|
# File 'lib/decaptcher.rb', line 23
def api_uri=( uri )
@@api_uri = uri
end
|
#api_url=(url) ⇒ Object
19
20
21
|
# File 'lib/decaptcher.rb', line 19
def api_url=( url )
@@api_uri = URI.parse( url )
end
|
#balance ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/decaptcher.rb', line 54
def balance
request = Net::HTTP::Post.new( @@api_uri.path )
request.set_form_data(
"Action" => "balance",
"Key" => @@api_key
)
response = self.send_request( request )
return response.to_i
end
|
#refund(task_id) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/decaptcher.rb', line 42
def refund( task_id )
request = Net::HTTP::Post.new( @@api_uri.path )
request.set_form_data(
"Action" => "refund",
"gen_task_id" => task_id,
"Key" => @@api_key
)
self.send_request( request )
return true
end
|
#send_request(request) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/decaptcher.rb', line 65
def send_request( request )
http = Net::HTTP.new( @@api_uri.host, @@api_uri.port )
response = http.request( request )
if response.body.slice( 0, 5 ) == 'Error'
errmsg = response.body.slice( 6, response.body.length - 6 )
raise SolveError.new( errmsg )
end
return response.body
end
|
#solve(blob) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/decaptcher.rb', line 27
def solve( blob )
task_id = SecureRandom.uuid
request = Net::HTTP::Post.new( @@api_uri.path )
request.set_form_data(
"Action" => "upload",
"gen_task_id" => task_id,
"Key" => @@api_key,
"file" => Base64.encode64( blob )
)
response = self.send_request( request )
return Response.new( task_id, response )
end
|