private_captcha 0.0.3 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 633ba6ed9f1e744f7198bb02c280a219ee4cf88773b68507c6eec0a43e4b9ac7
4
- data.tar.gz: 2fa1a08ffc72014ca32080b52fcd71bf2427c25c11ff1f0901c549350d28e1b9
3
+ metadata.gz: 70c3d94ed5a3020b3f71df8c50558c2e1a09c5e245374844209d2734bc4d51a8
4
+ data.tar.gz: 6a3a267b62466abc243069c922af1440f77d6feaeac24c96238d1841aa9d4437
5
5
  SHA512:
6
- metadata.gz: a25c0fb6454a60031b33d35e4550c6f6d7afe3ec8789cda95257926c28b3858c7f2864b753670f024aa0aa1b624ce0bd81482d6311323e9190b50001893765ab
7
- data.tar.gz: 8bd7a36ace7a8e3d0ebfaf279e13661061e615ec6164413fcdc6fa2ad7e8681b4a632cf6e7ae258d1491d9f1faddbd50dcd664b1c5c6cc94da102d6f9bf2d15d
6
+ metadata.gz: 88e3e2caef19070d9aba49ceaf62b9a9eb0fb0c80bf56e6c9c90a86d513137248c9a8435b5fb751604c1bd1814f5d771ba9bf021a3278aa6ac964f13e0021716
7
+ data.tar.gz: 7bb7b45b726e696b3ea57d38c2ad6fbb1a9a7e37ac2ece858f50e43741512c39469f68732894ac0696b70c98c977459f18ebecb2cba12c4e8f294b628d76f4de
data/README.md CHANGED
@@ -38,7 +38,7 @@ end
38
38
  # Verify a captcha solution
39
39
  begin
40
40
  result = client.verify('user-solution-from-frontend')
41
- if result.success
41
+ if result.ok?
42
42
  puts 'Captcha verified successfully!'
43
43
  else
44
44
  puts "Verification failed: #{result.error_message}"
@@ -25,7 +25,7 @@ module PrivateCaptcha
25
25
  end
26
26
 
27
27
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
28
- def verify(solution, max_backoff_seconds: nil, attempts: nil)
28
+ def verify(solution, max_backoff_seconds: nil, attempts: nil, sitekey: nil)
29
29
  raise EmptySolutionError if solution.nil? || solution.empty?
30
30
 
31
31
  max_backoff = max_backoff_seconds || @config.max_backoff_seconds
@@ -52,7 +52,7 @@ module PrivateCaptcha
52
52
  end
53
53
 
54
54
  begin
55
- response = do_verify(solution)
55
+ response = do_verify(solution, sitekey: sitekey)
56
56
  error = nil
57
57
  break
58
58
  rescue RetriableError => e
@@ -81,7 +81,7 @@ module PrivateCaptcha
81
81
 
82
82
  output = verify(solution)
83
83
 
84
- unless output.success
84
+ unless output.ok?
85
85
  raise Error.new("captcha verification failed: #{output.error_message}",
86
86
  trace_id: output.trace_id)
87
87
  end
@@ -100,11 +100,12 @@ module PrivateCaptcha
100
100
  end
101
101
 
102
102
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
103
- def do_verify(solution)
103
+ def do_verify(solution, sitekey: nil)
104
104
  request = Net::HTTP::Post.new(@endpoint)
105
105
  request['X-Api-Key'] = @config.api_key
106
106
  request['User-Agent'] = "private-captcha-ruby/#{VERSION}"
107
107
  request['Content-Type'] = 'text/plain'
108
+ request['X-PC-Sitekey'] = sitekey if sitekey
108
109
  request.body = solution
109
110
 
110
111
  @logger.debug('Sending HTTP request') { "path=#{@endpoint.path} method=POST" }
@@ -44,6 +44,10 @@ module PrivateCaptcha
44
44
  @attempt = attempt
45
45
  end
46
46
 
47
+ def ok?
48
+ @success == true && @code == VERIFY_NO_ERROR
49
+ end
50
+
47
51
  def error_message
48
52
  ERROR_MESSAGES.fetch(@code, 'error')
49
53
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PrivateCaptcha
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: private_captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taras Kushnir
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-11-10 00:00:00.000000000 Z
11
+ date: 2025-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack