diff --git a/lib/antigate.rb b/lib/antigate.rb index 52220c2..ef7caf5 100644 --- a/lib/antigate.rb +++ b/lib/antigate.rb @@ -60,30 +60,35 @@ def recognize(url, ext) return added end end - - 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 + + def add(url, ext) + begin + 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 + rescue Exception => e + captcha = url + end + + 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 def status(id) return Net::HTTP.get(URI("http://#{@domain}/res.php?key=#{@key}&action=get&id=#{id}")) rescue nil