captchatrader 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Changelog.md +3 -0
- data/README.md +65 -0
- data/lib/captchatrader.rb +11 -0
- data/lib/captchatrader/api.rb +79 -0
- data/lib/captchatrader/error.rb +23 -0
- data/lib/captchatrader/submission.rb +12 -0
- data/version.txt +1 -0
- metadata +73 -0
data/Changelog.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
captchatrader
|
2
|
+
=============
|
3
|
+
|
4
|
+
Ruby bindings for the captchatrader.com API. Submit captcha images and retrieve the text as a string.
|
5
|
+
|
6
|
+
|
7
|
+
Features
|
8
|
+
--------
|
9
|
+
|
10
|
+
* Submit capture images and retrieve the text
|
11
|
+
* Notify server if text is correct to prevent charging credits on incorrectly detected captchas
|
12
|
+
* Retrieve amount of credits left
|
13
|
+
|
14
|
+
Usage
|
15
|
+
--------
|
16
|
+
|
17
|
+
Captchatrader::API.username = "your-username"
|
18
|
+
Captchatrader::API.password = "your-password-or-passkey"
|
19
|
+
Captchatrader::API.api_key = "your-applications-api-key"
|
20
|
+
|
21
|
+
# Submit a capture image to retrieve the text
|
22
|
+
captcha = Captchatrader::API.submit("http://example.com/link-to-image.jpg", :url)
|
23
|
+
puts captcha.value # => "capture text"
|
24
|
+
|
25
|
+
# Tell the server that this captcha has been detected incorrectly (prevent charging credits)
|
26
|
+
Captchatrader::API.respond(captcha.ticket, false) # true
|
27
|
+
|
28
|
+
# Credits left for this username
|
29
|
+
Captchatrader::API.credits # => 90
|
30
|
+
|
31
|
+
Install
|
32
|
+
-------
|
33
|
+
|
34
|
+
gem install capturetrader
|
35
|
+
|
36
|
+
Requirements
|
37
|
+
------------
|
38
|
+
|
39
|
+
* None (only Mocha for running tests)
|
40
|
+
|
41
|
+
License
|
42
|
+
-------
|
43
|
+
|
44
|
+
The MIT License
|
45
|
+
|
46
|
+
Copyright (c) 2011 Dennis Theisen
|
47
|
+
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
49
|
+
a copy of this software and associated documentation files (the
|
50
|
+
'Software'), to deal in the Software without restriction, including
|
51
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
52
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
53
|
+
permit persons to whom the Software is furnished to do so, subject to
|
54
|
+
the following conditions:
|
55
|
+
|
56
|
+
The above copyright notice and this permission notice shall be
|
57
|
+
included in all copies or substantial portions of the Software.
|
58
|
+
|
59
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
60
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
61
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
62
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
63
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
64
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
65
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Captchatrader
|
2
|
+
module API
|
3
|
+
extend self
|
4
|
+
|
5
|
+
BASE_URL = "http://api.captchatrader.com"
|
6
|
+
SUBMIT_TYPES = [:url, :file]
|
7
|
+
|
8
|
+
attr_accessor :username, :password, :api_key
|
9
|
+
|
10
|
+
def submit(image, type, match = nil)
|
11
|
+
raise ArgumentError, "type must be one of #{SUBMIT_TYPES.join(', ')}" unless SUBMIT_TYPES.include?(type.to_sym)
|
12
|
+
|
13
|
+
params = {
|
14
|
+
:value => image,
|
15
|
+
:type => type,
|
16
|
+
:api_key => API.api_key,
|
17
|
+
:username => API.username,
|
18
|
+
:password => API.password
|
19
|
+
}
|
20
|
+
params[:match] = match if match
|
21
|
+
|
22
|
+
response = post("#{BASE_URL}/submit", params)
|
23
|
+
parse_response(response, :submit, :image => image)
|
24
|
+
end
|
25
|
+
|
26
|
+
def respond(ticket, correct)
|
27
|
+
params = {
|
28
|
+
:ticket => ticket,
|
29
|
+
:is_correct => correct,
|
30
|
+
:username => API.username,
|
31
|
+
:password => API.password
|
32
|
+
}
|
33
|
+
response = post("#{BASE_URL}/respond", params)
|
34
|
+
parse_response(response, :respond)
|
35
|
+
end
|
36
|
+
|
37
|
+
def credits
|
38
|
+
response = get("#{BASE_URL}/get_credits/username:#{API.username}/password:#{API.password}/")
|
39
|
+
parse_response(response, :credits)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def get(url)
|
46
|
+
url = URI.parse(url)
|
47
|
+
response = Net::HTTP.start(url.host, url.port) do |http|
|
48
|
+
http.get(url.request_uri)
|
49
|
+
end
|
50
|
+
response.body
|
51
|
+
end
|
52
|
+
|
53
|
+
def post(url, params)
|
54
|
+
url = URI.parse(url)
|
55
|
+
post = Net::HTTP::Post.new(url.request_uri)
|
56
|
+
post.set_form_data(params)
|
57
|
+
response = Net::HTTP.start(url.host, url.port) do |http|
|
58
|
+
http.request(post)
|
59
|
+
end
|
60
|
+
response.body
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_response(response, type, options = {})
|
64
|
+
raise API::Error, "Unexpected response from captchatrader: #{response}" unless response =~ /\A\[.+\]\z/
|
65
|
+
|
66
|
+
code, details = response[1..-2].split(/ *, */)
|
67
|
+
raise API::Error, details.to_s[1..-2] if code.to_i == -1
|
68
|
+
|
69
|
+
case type
|
70
|
+
when :credits
|
71
|
+
details.to_i
|
72
|
+
when :submit
|
73
|
+
Submission.new(details.to_s[1..-2], code.to_i, options[:image])
|
74
|
+
when :respond
|
75
|
+
code.to_i == 0
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Captchatrader
|
2
|
+
module API
|
3
|
+
|
4
|
+
class Error < StandardError
|
5
|
+
# submit
|
6
|
+
API_KEY_DISABLED = "The API key has been disabled, likely because it is not responding to CAPTCHAs correctly or is submitting too quickly"
|
7
|
+
INSUFFICIENT_CREDITS = "The account provided does not have enough credits to complete the request"
|
8
|
+
INTERNAL_ERROR = "The server encountered an unexpected situation and the request was aborted"
|
9
|
+
INVALID_API_KEY = "The API key provided was not registered"
|
10
|
+
INVALID_PARAMETERS = "The request was not submitted correctly"
|
11
|
+
INVALID_TYPE = "The type argument was invalid"
|
12
|
+
INVALID_USER = "The username/password combination was incorrect"
|
13
|
+
USER_NOT_VALIDATED = "The user has not been validated or is banned"
|
14
|
+
NOT_AN_IMAGE = "The file or url uploaded was not detected to be a valid image"
|
15
|
+
SUBMISSION_ERROR = "An error occurred in the file upload"
|
16
|
+
|
17
|
+
# respond
|
18
|
+
INCORRECT_REPORTS = "Too many negative responses were submitted in a short time frame"
|
19
|
+
INVALID_TICKET = "The type argument was invalid"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/version.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: captchatrader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dennis Theisen
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-29 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Submit captcha images and retrieve the text as a string.
|
23
|
+
email: soleone@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- Changelog.md
|
32
|
+
- README.md
|
33
|
+
- version.txt
|
34
|
+
- lib/captchatrader/api.rb
|
35
|
+
- lib/captchatrader/error.rb
|
36
|
+
- lib/captchatrader/submission.rb
|
37
|
+
- lib/captchatrader.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/Soleone/captchatrader
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
hash: 3
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Ruby bindings for the captchatrader.com API.
|
72
|
+
test_files: []
|
73
|
+
|