private_captcha 0.0.6 → 0.0.8

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: 8cfbe57b68cd76d99caf830425f5c0b266807cd9f0b1290e7f973f10b3d6ff58
4
- data.tar.gz: 9dc9b9cb80b0ed3efeaa15992233688836a07d0a2e26f8640f1801f023db0958
3
+ metadata.gz: 197d99d169be8deaededceb9f733525d5d2d6287844cdf40a052fcb4a062a520
4
+ data.tar.gz: 8212225b2743d98bc0d621c5fdbe7dcb0ad3df2ed1ba2cd3da1741ce644045cc
5
5
  SHA512:
6
- metadata.gz: 9cfab92357a7f4a13d2b6f9aa63a2f523f29de75bcd0c2d79b252e49f65ca02cda3881ecadb7a2d5785eb9f85fa7e48df1561c4dad217718e532834ced62d8fc
7
- data.tar.gz: 3cac0cac74a8e081a3a67e405481306d2ddfe01a8d9790de575fb45ee1ab40fa3bb08d4bcb86f2110bccc5b248c054434323cc371f0d814016352452113047f4
6
+ metadata.gz: d694537643e19067f691ad44ad07a22c278243130221dd43e085a236c7daf6434149707942fe6caea276fd8ded36dd242554969ad2485a243a60a48151452a88
7
+ data.tar.gz: 32c341e9ae6c0f57cdbb5e009a1183effa018f8987e58ba8ae4407f7594e8ec8e30809d4e735440d979dd33e44efcacba78639921b49f640d14ce52efc11c1e3
@@ -24,7 +24,7 @@ module PrivateCaptcha
24
24
  @logger = @config.logger || Logger.new(IO::NULL)
25
25
  end
26
26
 
27
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
27
+ # rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
28
28
  def verify(solution, max_backoff_seconds: nil, attempts: nil, sitekey: nil)
29
29
  raise EmptySolutionError if solution.nil? || solution.empty?
30
30
 
@@ -73,13 +73,12 @@ module PrivateCaptcha
73
73
 
74
74
  response
75
75
  end
76
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
77
76
 
78
- def verify_request(request, form_field: nil)
77
+ def verify_request(request, form_field: nil, sitekey: nil)
79
78
  field = form_field || @config.form_field
80
79
  solution = extract_form_value(request, field)
81
80
 
82
- output = verify(solution)
81
+ output = verify(solution, sitekey: sitekey)
83
82
 
84
83
  unless output.ok?
85
84
  raise Error.new("captcha verification failed: #{output.error_message}",
@@ -99,7 +98,7 @@ module PrivateCaptcha
99
98
  domain.delete_suffix('/')
100
99
  end
101
100
 
102
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
101
+ # rubocop:disable-next Metrics/AbcSize, Metrics/MethodLength
103
102
  def do_verify(solution, sitekey: nil)
104
103
  request = Net::HTTP::Post.new(@endpoint)
105
104
  request['X-Api-Key'] = @config.api_key
@@ -149,7 +148,6 @@ module PrivateCaptcha
149
148
  raise RetriableError, e
150
149
  end
151
150
  end
152
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
153
151
 
154
152
  def parse_retry_after(header)
155
153
  return nil if header.nil? || header.empty?
@@ -5,7 +5,7 @@ require 'rack'
5
5
  module PrivateCaptcha
6
6
  # Middleware provides Rack middleware for automatic captcha verification
7
7
  class Middleware
8
- # rubocop:disable Metrics/AbcSize
8
+ # rubocop:disable-next Metrics/AbcSize
9
9
  def initialize(app, api_key:, **options)
10
10
  @app = app
11
11
  @client = Client.new do |config|
@@ -18,9 +18,8 @@ module PrivateCaptcha
18
18
  config.logger = options[:logger] if options[:logger]
19
19
  end
20
20
  end
21
- # rubocop:enable Metrics/AbcSize
22
21
 
23
- # rubocop:disable Metrics/MethodLength
22
+ # rubocop:disable-next Metrics/MethodLength
24
23
  def call(env)
25
24
  request = Rack::Request.new(env)
26
25
 
@@ -36,6 +35,5 @@ module PrivateCaptcha
36
35
 
37
36
  @app.call(env)
38
37
  end
39
- # rubocop:enable Metrics/MethodLength
40
38
  end
41
39
  end
@@ -16,7 +16,8 @@ module PrivateCaptcha
16
16
  TEST_PROPERTY_ERROR = 10
17
17
  INTEGRITY_ERROR = 11
18
18
  ORG_SCOPE_ERROR = 12
19
- VERIFY_CODES_COUNT = 13
19
+ SOLUTION_TIMING_ERROR = 13
20
+ VERIFY_CODES_COUNT = 14
20
21
 
21
22
  ERROR_MESSAGES = {
22
23
  VERIFY_NO_ERROR => '',
@@ -31,17 +32,20 @@ module PrivateCaptcha
31
32
  MAINTENANCE_MODE_ERROR => 'maintenance-mode',
32
33
  TEST_PROPERTY_ERROR => 'property-test',
33
34
  INTEGRITY_ERROR => 'integrity-error',
34
- ORG_SCOPE_ERROR => 'org-scope-error'
35
+ ORG_SCOPE_ERROR => 'org-scope-error',
36
+ SOLUTION_TIMING_ERROR => 'solution-timing'
35
37
  }.freeze
36
38
 
37
39
  attr_accessor :success, :code, :origin, :timestamp
38
40
  attr_reader :trace_id, :attempt
39
41
 
40
- def initialize(success: false, code: VERIFY_NO_ERROR, origin: nil, timestamp: nil, trace_id: nil, attempt: 0)
42
+ def initialize(success: false, code: VERIFY_NO_ERROR, origin: nil, timestamp: nil, edge_token: nil,
43
+ trace_id: nil, attempt: 0)
41
44
  @success = success
42
45
  @code = code
43
46
  @origin = origin
44
47
  @timestamp = timestamp
48
+ @edge_token = edge_token
45
49
  @trace_id = trace_id
46
50
  @attempt = attempt
47
51
  end
@@ -60,6 +64,7 @@ module PrivateCaptcha
60
64
  code: json_data['code'] || VERIFY_NO_ERROR,
61
65
  origin: json_data['origin'],
62
66
  timestamp: json_data['timestamp'],
67
+ edge_token: json_data['edge_token'],
63
68
  trace_id: trace_id,
64
69
  attempt: attempt
65
70
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PrivateCaptcha
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.8'
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.6
4
+ version: 0.0.8
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-12-23 00:00:00.000000000 Z
11
+ date: 2026-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack