Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local captha file #6

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -19,17 +23,21 @@ 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)

#### Example
puts Antigate.balance('660aaf58948bae3fa81362ef71b9ebcc')

[1]: http://antigate.com/
[2]: http://antigate.com/index.php?action=regscreen
[2]: http://antigate.com/index.php?action=regscreen
24 changes: 13 additions & 11 deletions lib/antigate.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "antigate/version"

module Antigate
require 'net/http'
require 'uri'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion lib/antigate/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Antigate
VERSION = "0.0.2"
VERSION = "0.0.4"
end