captched_to_death 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -29,7 +29,7 @@ Pass a block if you want to set the verbose option, that enables RestClient resp
29
29
  c.verbose = true
30
30
  end
31
31
 
32
- === Balance checking
32
+ ==== Balance checking
33
33
 
34
34
  With your client initialized using you account credentials, you can check your current balance like so:
35
35
 
@@ -38,7 +38,7 @@ With your client initialized using you account credentials, you can check your c
38
38
 
39
39
  Note that the "balance" in the response means your cents left.
40
40
 
41
- === CAPTCHA decoding
41
+ ==== CAPTCHA decoding
42
42
 
43
43
  With your client initialized using you account credentials, you can decode a CAPTCHA challenge if you still have credits left on your account. To do do so, just pass the CAPTCHA image URL:
44
44
 
@@ -47,21 +47,21 @@ With your client initialized using you account credentials, you can decode a CAP
47
47
 
48
48
  Note that only GIF, JPEG and PNG are supported as valid CAPTCHA challenges. Also, the response time depends on the current DeathByCaptcha server load.
49
49
 
50
- === CAPTCHA status checking
50
+ ==== CAPTCHA status checking
51
51
 
52
52
  Once the challenge has already been accepted, it's status can be checked at any time using it's CAPTCHA ID.
53
53
 
54
54
  client.captcha(36723349)
55
55
  => {"status"=>0, "captcha"=>36723349, "is_correct"=>true, "text"=>"jd472tfo"}
56
56
 
57
- === CAPTCHA reporting
57
+ ==== CAPTCHA reporting
58
58
 
59
59
  If you think the result of the challenge decoding is not correct you can report it to get a refund. But mind that you have to report it within the hour of submitting it and that abusing this feature might get you banned.
60
60
 
61
61
  client.report(36723349)
62
62
  => {"status"=>0, "captcha"=>36723349, "is_correct"=>false, "text"=>"jd472tfo"}
63
63
 
64
- === DeathByCaptcha server status checking
64
+ === CaptchedToDeath::Server
65
65
 
66
66
  You can check the current status of the DeathByCaptcha server to find out the average decoding time at any particular moment. This time will directly affect the response time of any decoding you submit afterwards.
67
67
 
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Cristian R. Arroyo"]
9
9
  s.email = ["cristian.arroyo@vivaserver.com"]
10
10
  s.homepage = "https://github.com/vivaserver/captched_to_death"
11
- s.summary = %q{A simple HTTP client to DeathByCaptcha API}
12
- s.description = %q{A simple HTTP client to DeathByCaptcha API using just RestClient}
11
+ s.summary = %q{A simple HTTP client to the DeathByCaptcha API}
12
+ s.description = %q{A simple HTTP client to the DeathByCaptcha API using just RestClient}
13
13
 
14
14
  s.add_runtime_dependency 'rest-client', "~> 1.6"
15
15
  s.add_development_dependency 'minitest'
@@ -33,9 +33,18 @@ module CaptchedToDeath
33
33
  #
34
34
  def balance
35
35
  fail RejectedError if empty_credentials?
36
- response = RestClient.post "#{API_URI}/user", {:username => @username, :password => @password}, :accept => @accept
37
- fail ServiceError unless response.code == 200
36
+ response = RestClient.post "#{API_URI}/user", {
37
+ :username => @username,
38
+ :password => @password
39
+ }, :accept => @accept
38
40
  JSON.parse(response)
41
+ rescue RestClient::Exception => e
42
+ case e.http_code
43
+ when 403
44
+ fail RejectedError
45
+ else
46
+ fail ServiceError
47
+ end
39
48
  end
40
49
 
41
50
  # Polls for uploaded CAPTCHA status.
@@ -50,6 +59,8 @@ module CaptchedToDeath
50
59
  case e.http_code
51
60
  when 404
52
61
  fail NotFound
62
+ when 500
63
+ fail ServiceError
53
64
  #503 (Service Temporarily Unavailable) when our service is overloaded (usually around 3:00–6:00 PM EST)
54
65
  when 503
55
66
  # not sure 503 is ever sent, but retry if it is
@@ -84,8 +95,7 @@ module CaptchedToDeath
84
95
  # (...so it'll be returned as a 200)
85
96
  #403 (Forbidden) credentials were rejected, or you don't have enough credits
86
97
  when 403
87
- # TODO: discrimate wrong credentials
88
- fail NoCreditError
98
+ fail NoCreditError if balance
89
99
  #400 (Bad Request) if your request was not following the specification or not a valid image
90
100
  when 400
91
101
  fail RejectedError
@@ -104,13 +114,18 @@ module CaptchedToDeath
104
114
  #
105
115
  def report(captcha_id)
106
116
  fail RejectedError if empty_credentials?
107
-
108
117
  response = RestClient.post "#{API_URI}/captcha/#{captcha_id}/report", {
109
118
  :username => @username,
110
119
  :password => @password,
111
120
  }, :accept => @accept
112
-
113
121
  JSON.parse(response)
122
+ rescue RestClient::Exception => e
123
+ case e.http_code
124
+ when 403
125
+ fail RejectedError
126
+ else
127
+ fail ServiceError
128
+ end
114
129
  end
115
130
 
116
131
  private
@@ -1,3 +1,3 @@
1
1
  module CaptchedToDeath
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: captched_to_death
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-11-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &72562580 !ruby/object:Gem::Requirement
16
+ requirement: &83665140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.6'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *72562580
24
+ version_requirements: *83665140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &72562370 !ruby/object:Gem::Requirement
27
+ requirement: &83664920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *72562370
35
+ version_requirements: *83664920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &72562140 !ruby/object:Gem::Requirement
38
+ requirement: &83664660 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,8 +43,8 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *72562140
47
- description: A simple HTTP client to DeathByCaptcha API using just RestClient
46
+ version_requirements: *83664660
47
+ description: A simple HTTP client to the DeathByCaptcha API using just RestClient
48
48
  email:
49
49
  - cristian.arroyo@vivaserver.com
50
50
  executables: []
@@ -89,5 +89,5 @@ rubyforge_project:
89
89
  rubygems_version: 1.8.10
90
90
  signing_key:
91
91
  specification_version: 3
92
- summary: A simple HTTP client to DeathByCaptcha API
92
+ summary: A simple HTTP client to the DeathByCaptcha API
93
93
  test_files: []