captcha_solver 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb552923bd6768418ba4fad4480c7cb95971949d6f5c6b3f0dc62ef8c4adbd2f
4
- data.tar.gz: f1fc27b083b6399ecd367d6da461afc60733cebd3df0354193f99ed920fba4ce
3
+ metadata.gz: 04f4869b6dabc49cc2e82c1a91e50c1cadffce98dd777709951a692293887879
4
+ data.tar.gz: 07471d70d929a512e66347278c65347dd48f7908722646a17fa17af35452134f
5
5
  SHA512:
6
- metadata.gz: 988782a644cba122259eed79f3af63cba859204cd42313bde0c7d4ae43a357426dd018148d1fb74c6264d0a2cea6f96906889232ed9357a2dc12785d06f936aa
7
- data.tar.gz: 7de72ce2784bd5aa34069e102efc9f53da879f3a59400870192cfd8d5c27db5c4bb012d2c0202532964d9f7d0d6ccad58e9c1b668571d163dc7b70994c18663b
6
+ metadata.gz: f85e580b4cd6f207e8d5a32f7eb3f5f5560e242723c46c935618bfb98e507c4fa6df63e418513e81abfa1e264aeaefc3b06ad49793d744ab0abf358fa05c3fda
7
+ data.tar.gz: ab993f1ff6f048c4d5d50e003d0bff35e99f506723b6c68d4c7da9ebac0b9b69880c8c20c5ef19d3d1bfa8472bfa8cb00e792fb085d4027297732941f4fef693
@@ -36,7 +36,7 @@ module CaptchaSolver
36
36
  raise NotSolvedError.new(complete_response&.body)
37
37
  end
38
38
 
39
- # Returns solved captcha
39
+ # Returns solved captcha.
40
40
  def solved_captcha
41
41
  return nil unless solved?
42
42
  captcha_value
@@ -44,79 +44,91 @@ module CaptchaSolver
44
44
 
45
45
  private
46
46
 
47
- # Headers that have to be passed in each request. Use it in the child class
47
+ # Headers that have to be passed in each request.
48
48
  def default_request_headers
49
49
  { 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' }
50
50
  end
51
51
 
52
- # Params that have to be passed in each request. Use it in the child class
52
+ # Parameters that have to be passed in each request.
53
53
  def default_request_params
54
54
  { key: rucaptcha_api_key, json: 1 }
55
55
  end
56
56
 
57
- # Makes a in.php request. Response must be returned as JSON
58
- def make_start_request
59
- raise NotImplementedError.new('#make_start_request method must be implemented')
57
+ # Parameters which are used in in.php request.
58
+ def start_request_params
59
+ raise NotImplementedError.new('#start_request_params method must be implemented')
60
60
  end
61
61
 
62
- # Calls #make_start_request and saves the result in @start_response
62
+ # Makes a in.php request and saves the result in @start_response.
63
63
  def start
64
- @start_response = make_start_request
64
+ @start_response = RestClient::Request.execute(
65
+ method: :post,
66
+ url: 'http://rucaptcha.com/in.php',
67
+ proxy: "http://#{proxy_address}",
68
+ headers: default_request_headers,
69
+ payload: default_request_params.merge(start_request_params)
70
+ )
65
71
  end
66
72
 
67
- # Parses response from in.php request and returns rucaptcha id
73
+ # Parses response from in.php request and returns rucaptcha id.
68
74
  def rucaptcha_id
69
75
  return nil if start_response.nil?
70
76
  JSON.parse(start_response.body)['request']
71
77
  end
72
78
 
73
- # Checks if a in.php request is successful
79
+ # Checks if a in.php request is successful.
74
80
  def started?
75
81
  return false if start_response.nil?
76
82
  return false if errors_regexp.match?(start_response.body)
77
83
  !rucaptcha_id.nil?
78
84
  end
79
85
 
80
- # Makes a res.php request. Response must be returned as JSON
81
- def make_complete_request
82
- raise NotImplementedError.new('#make_complete_request method must be implemented')
86
+ # Parameters which are used in res.php request.
87
+ def complete_request_params
88
+ { id: rucaptcha_id, action: 'get' }
83
89
  end
84
90
 
85
- # Calls #make_complete_request and saves the result in @complete_response
91
+ # Makes a res.php request and saves the result in @complete_response.
86
92
  def complete
87
93
  return nil unless started?
88
- @complete_response = make_complete_request
94
+ @complete_response = RestClient::Request.execute(
95
+ method: :post,
96
+ url: 'http://rucaptcha.com/res.php',
97
+ proxy: "http://#{proxy_address}",
98
+ headers: default_request_headers,
99
+ payload: default_request_params.merge(complete_request_params)
100
+ )
89
101
  end
90
102
 
91
- # Checks if captcha solving is failed
103
+ # Checks if captcha solving is failed.
92
104
  def failed?
93
105
  return false if complete_response.nil?
94
106
  errors_regexp.match? complete_response.body
95
107
  end
96
108
 
97
- # Checks if captcha is solved
109
+ # Checks if captcha is solved.
98
110
  def solved?
99
111
  return false if complete_response.nil?
100
112
  return false if failed?
101
113
  !not_ready_regexp.match?(complete_response.body) && !captcha_value.nil?
102
114
  end
103
115
 
104
- # Parses response from res.php request and returns captcha value
116
+ # Parses response from res.php request and returns captcha value.
105
117
  def captcha_value
106
118
  JSON.parse(complete_response.body)['request']
107
119
  end
108
120
 
109
- # The error that is returned by res.php request if captcha is not solved yet
121
+ # The error that is returned by res.php request if captcha is not solved yet.
110
122
  def not_ready_regexp
111
123
  /CAPCHA_NOT_READY/i
112
124
  end
113
125
 
114
- # Any error that might be returned by in.php or res.php request
126
+ # Any error that might be returned by in.php or res.php request.
115
127
  def errors_regexp
116
128
  /(ERROR|BANNED|MAX_USER_TURN|REPORT_NOT_RECORDED)/i
117
129
  end
118
130
 
119
- # Makes a delay between requests
131
+ # Makes a delay between requests.
120
132
  def wait_for(seconds)
121
133
  puts "Waiting for #{seconds} seconds"
122
134
  seconds.times do |i|
@@ -2,7 +2,6 @@ require 'base64'
2
2
 
3
3
  module CaptchaSolver
4
4
  class RecaptchaV1 < Base
5
-
6
5
  attr_reader :image_path, :help_params
7
6
 
8
7
  def initialize(args)
@@ -43,40 +42,21 @@ module CaptchaSolver
43
42
  }[help_params[:language].to_sym] || 0
44
43
  end
45
44
 
46
- def make_start_request
47
- RestClient::Request.execute(
48
- method: :post,
49
- url: 'http://rucaptcha.com/in.php',
50
- proxy: "http://#{proxy_address}",
51
- headers: default_request_headers,
52
- payload: default_request_params.merge(
53
- body: base64_image,
54
- method: :base64,
55
- phrase: phrase,
56
- regsense: register_sensitive,
57
- numeric: numeric,
58
- calc: calculation,
59
- language: language,
60
- )
61
- )
62
- end
63
-
64
- def make_complete_request
65
- RestClient::Request.execute(
66
- method: :post,
67
- url: 'http://rucaptcha.com/res.php',
68
- proxy: "http://#{proxy_address}",
69
- headers: default_request_headers,
70
- payload: default_request_params.merge(
71
- id: rucaptcha_id,
72
- action: 'get'
73
- )
74
- )
75
- end
76
-
77
45
  def base64_image
78
46
  @base64_image ||=
79
47
  File.open(image_path, 'rb') { |file| Base64.encode64(file.read) }
80
48
  end
49
+
50
+ def start_request_params
51
+ {
52
+ body: base64_image,
53
+ method: 'base64',
54
+ phrase: phrase,
55
+ regsense: register_sensitive,
56
+ numeric: numeric,
57
+ calc: calculation,
58
+ language: language,
59
+ }
60
+ end
81
61
  end
82
62
  end
@@ -10,31 +10,12 @@ module CaptchaSolver
10
10
 
11
11
  private
12
12
 
13
- def make_start_request
14
- RestClient::Request.execute(
15
- method: :post,
16
- url: 'http://rucaptcha.com/in.php',
17
- proxy: "http://#{proxy_address}",
18
- headers: default_request_headers,
19
- payload: default_request_params.merge(
20
- method: 'userrecaptcha',
21
- googlekey: google_key,
22
- pageurl: page_url
23
- )
24
- )
25
- end
26
-
27
- def make_complete_request
28
- RestClient::Request.execute(
29
- method: :post,
30
- url: 'http://rucaptcha.com/res.php',
31
- proxy: "http://#{proxy_address}",
32
- headers: default_request_headers,
33
- payload: default_request_params.merge(
34
- id: rucaptcha_id,
35
- action: 'get'
36
- )
37
- )
13
+ def start_request_params
14
+ {
15
+ method: 'userrecaptcha',
16
+ googlekey: google_key,
17
+ pageurl: page_url
18
+ }
38
19
  end
39
20
  end
40
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: captcha_solver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Randi Korhonen