diff --git a/README.markdown b/README.markdown index 5ccb1e9..5ae77a9 100644 --- a/README.markdown +++ b/README.markdown @@ -4,8 +4,12 @@ Gem recognizes CAPTCHA by means Antigate. [Registration Antigate account][2] ## Install - gem install antigate - +### Gemfile Install + gem 'antigate', :github => 'SeNaP/antigate' +### Local Install + git clone https://github.com/SeNaP/antigate.git + cd antigate && gem build antigate + sudo gem install antigate.gem ## Usage ### Recognize captcha captcha = Antigate.wrapper(KEY) @@ -19,12 +23,16 @@ Gem recognizes CAPTCHA by means Antigate. puts recognized[0] # ID recognized CAPTCHA puts recognized[1] # Text CAPTCHA -#### Example +#### From remote file captcha = Antigate.wrapper('660aaf58948bae3fa81362ef71b9ebcc') captcha.phrase = 1 recognized = captcha.recognize('http://www.google.com/recaptcha/api/image?c=03AHJ_Vuu-Kun_wMo4M8JiWA87K6awfoiUxJCUF9KkQq3tCfyxjYELhHcsIJrcJ_qgqIQQsBw5vWAkpHBqP4VEHv1nwtoAnD5uZvwzHknOFyID4OrX0_6q8QXQ5TwkRn7qBxdt3QdX6D8NvPcFHFHzmEhu1yCJJQfTwQ', 'jpg') puts recognized[1] - +#### From local file + captcha = Antigate.wrapper('660aaf58948bae3fa81362ef71b9ebcc') + captcha.phrase = 1 + recognized = captcha.recognize('captcha', 'jpg') + puts recognized[1] ### Get balance puts Antigate.balance(KEY) @@ -32,4 +40,4 @@ Gem recognizes CAPTCHA by means Antigate. puts Antigate.balance('660aaf58948bae3fa81362ef71b9ebcc') [1]: http://antigate.com/ -[2]: http://antigate.com/index.php?action=regscreen \ No newline at end of file +[2]: http://antigate.com/index.php?action=regscreen diff --git a/lib/antigate.rb b/lib/antigate.rb index 52220c2..352913d 100644 --- a/lib/antigate.rb +++ b/lib/antigate.rb @@ -1,5 +1,3 @@ -require "antigate/version" - module Antigate require 'net/http' require 'uri' @@ -29,10 +27,10 @@ def initialize(key) @domain = "antigate.com" end - def recognize(url, ext) + def recognize(captcha_file, ext) added = nil loop do - added = add(url, ext) + added = add(captcha_file, ext) next if added.nil? if added.include? 'ERROR_NO_SLOT_AVAILABLE' sleep(1) @@ -61,13 +59,17 @@ def recognize(url, ext) 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 + def add(captcha_file, ext) + if captcha_file.include?("http") + uri = URI.parse(captcha_file) + 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 + else + captcha = File.read("#{captcha_file}.#{ext}") + end if captcha params = { 'method' => 'base64', diff --git a/lib/antigate/version.rb b/lib/antigate/version.rb index 23bd9f9..1fce7aa 100644 --- a/lib/antigate/version.rb +++ b/lib/antigate/version.rb @@ -1,3 +1,3 @@ module Antigate - VERSION = "0.0.2" + VERSION = "0.0.4" end